import messages, { decode, CLIENT_PROTOCOL } from "./messages";

export default class NetworkClient {
  private socket: WebSocket;

  constructor(private readonly url) {
    this.socket = new WebSocket(url, [CLIENT_PROTOCOL]);
    this.socket.binaryType = "arraybuffer";
    this.socket.onopen = () => {
      console.log("Connected");
    };
    this.socket.onmessage = (ev) => {
      const data = decode(ev.data);
      console.log("Received ", data);
    };
  }
}
