import Observable from "../utils/Observable.js"; import { ConnectionOpenedEvent, DataEvent } from "./Events.js"; class WebSocketClient extends Observable { constructor() { super(); } connect(url) { this.ws = new WebSocket(url); this.ws.onopen = onOpen.bind(this); this.ws.onmessage = onMessage.bind(this); } } function onOpen() { let connectionEvent = new ConnectionOpenedEvent(); this.notifyAll(connectionEvent); } function onMessage(event) { let dataEvent = new DataEvent(event.data); this.notifyAll(dataEvent); } export default WebSocketClient;