1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 const EventEmitter = require("devtools/shared/event-emitter");
9 function WebSocketDebuggerTransport(socket) {
10 EventEmitter.decorate(this);
17 WebSocketDebuggerTransport.prototype = {
23 this.socket.addEventListener("message", this);
24 this.socket.addEventListener("close", this);
30 this.emit("send", object);
32 this.socket.send(JSON.stringify(object));
37 throw new Error("Bulk send is not supported by WebSocket transport");
44 this.socket.removeEventListener("message", this);
45 this.socket.removeEventListener("close", this);
50 this.hooks.onClosed();
58 this.onMessage(event);
67 if (typeof data !== "string") {
68 throw new Error("Binary messages are not supported by WebSocket transport");
71 const object = JSON.parse(data);
72 this.emit("packet", object);
74 this.hooks.onPacket(object);
79 module.exports = WebSocketDebuggerTransport;