summaryrefslogtreecommitdiff
path: root/share/web_surfaces/shared/channel.js
diff options
context:
space:
mode:
Diffstat (limited to 'share/web_surfaces/shared/channel.js')
-rw-r--r--share/web_surfaces/shared/channel.js20
1 files changed, 12 insertions, 8 deletions
diff --git a/share/web_surfaces/shared/channel.js b/share/web_surfaces/shared/channel.js
index 03b87979d2..8c6f8afdcd 100644
--- a/share/web_surfaces/shared/channel.js
+++ b/share/web_surfaces/shared/channel.js
@@ -41,28 +41,32 @@ export class MessageChannel {
constructor (host) {
// https://developer.mozilla.org/en-US/docs/Web/API/URL/host
- this.host = host;
+ this._host = host;
}
async open () {
return new Promise((resolve, reject) => {
- this.socket = new WebSocket(`ws://${this.host}`);
+ this._socket = new WebSocket(`ws://${this._host}`);
- this.socket.onclose = () => this.closeCallback();
+ this._socket.onclose = () => this.closeCallback();
- this.socket.onerror = (error) => this.errorCallback(error);
+ this._socket.onerror = (error) => this.errorCallback(error);
- this.socket.onmessage = (event) => {
+ this._socket.onmessage = (event) => {
this.messageCallback (Message.fromJsonText(event.data));
};
- this.socket.onopen = resolve;
+ this._socket.onopen = resolve;
});
}
+ async close () {
+ this._socket.close();
+ }
+
send (msg) {
- if (this.socket) {
- this.socket.send(msg.toJsonText());
+ if (this._socket) {
+ this._socket.send(msg.toJsonText());
} else {
throw Error('MessageChannel: cannot call send() before open()');
}