Require handleMessage to be set before opening scratch-link-socket

This commit is contained in:
Paul Kaplan 2019-05-31 08:35:27 -04:00
parent 5e626eb7e9
commit 94afd58b2f

View file

@ -33,12 +33,12 @@ class ScratchLinkWebSocket {
throw new Error(`Unknown ScratchLink socket Type: ${this._type}`); throw new Error(`Unknown ScratchLink socket Type: ${this._type}`);
} }
if (this._onOpen && this._onClose && this._onError) { if (this._onOpen && this._onClose && this._onError && this._handleMessage) {
this._ws.onopen = this._onOpen; this._ws.onopen = this._onOpen;
this._ws.onclose = this._onClose; this._ws.onclose = this._onClose;
this._ws.onerror = this._onError; this._ws.onerror = this._onError;
} else { } else {
throw new Error('Must set open, close and error handlers before calling open on the socket'); throw new Error('Must set open, close, message and error handlers before calling open on the socket');
} }
this._ws.onmessage = this._onMessage.bind(this); this._ws.onmessage = this._onMessage.bind(this);