import React from 'react';
import logo from './logo.svg';
import './App.css';

export const socket = new WebSocket('ws://127.0.0.1:7000', "rust-websocket");
socket.addEventListener('open', (event) => {
  console.log(event);
  const test = {
    action: 'test',
    message: 'unchi'
  };
  socket.send(JSON.stringify(test));
});
socket.addEventListener('message', (event) => {
  console.log(event);
  const data = event.data;
  if (data.indexOf('PING') === 0) {
    socket.send('PONG');
    socket.send('PRIVMSG #osoma_crawler :オソマ');
  }
})
function App() {
  /*
  const socket = new WebSocket('wss://irc-ws.chat.twitch.tv:443');
  socket.addEventListener('open', (event) => {
    console.log(event);
    socket.send('PASS oauth:xweh94y0e330bo1i9rw0ty6fo02m9w');
    socket.send('NICK osoma_bot');
    socket.send('JOIN #osoma_crawler');
  });
  socket.addEventListener('message', (event) => {
    console.log(event);
    const data = event.data;
    if (data.indexOf('PING') === 0) {
      socket.send('PONG');
      socket.send('PRIVMSG #osoma_crawler :オソマ');
    }
  })
  */
  console.log("test")
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.tsx</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
      </header>
    </div>
  );
}

export default App;
