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/. */
10 } = require("devtools/shared/protocol");
11 const { webSocketSpec } = require("devtools/shared/specs/websocket");
14 * A WebSocketFront is used as a front end for the WebSocketActor that is
15 * created on the server, hiding implementation details.
17 class WebSocketFront extends FrontClassWithSpec(webSocketSpec) {
18 constructor(client, targetFront, parentFront) {
19 super(client, targetFront, parentFront);
21 this._onWebSocketOpened = this._onWebSocketOpened.bind(this);
22 this._onWebSocketClosed = this._onWebSocketClosed.bind(this);
23 this._onFrameSent = this._onFrameSent.bind(this);
24 this._onFrameReceived = this._onFrameReceived.bind(this);
26 // Attribute name from which to retrieve the actorID
27 // out of the target actor's form
28 this.formAttributeName = "webSocketActor";
30 this.on("serverWebSocketOpened", this._onWebSocketOpened);
31 this.on("serverWebSocketClosed", this._onWebSocketClosed);
32 this.on("serverFrameSent", this._onFrameSent);
33 this.on("serverFrameReceived", this._onFrameReceived);
37 * Close the WebSocketFront.
41 this.off("serverWebSocketOpened");
42 this.off("serverWebSocketClosed");
43 this.off("serverFrameSent");
44 this.off("serverFrameReceived");
45 return super.destroy();
49 * The "webSocketOpened" message type handler. We redirect any message to
50 * the UI for displaying.
53 * @param number httpChannelId
54 * Channel ID of the websocket connection.
55 * @param string effectiveURI
57 * @param string protocols
58 * WebSocket procotols.
59 * @param string extensions
61 async _onWebSocketOpened(httpChannelId, effectiveURI, protocols, extensions) {
72 * The "webSocketClosed" message type handler. We redirect any message to
73 * the UI for displaying.
76 * @param number httpChannelId
77 * @param boolean wasClean
79 * @param string reason
81 async _onWebSocketClosed(httpChannelId, wasClean, code, reason) {
82 this.emit("webSocketClosed", httpChannelId, wasClean, code, reason);
86 * The "frameReceived" message type handler. We redirect any message to
87 * the UI for displaying.
90 * @param string httpChannelId
91 * Channel ID of the websocket connection.
93 * The data received from the server.
95 async _onFrameReceived(httpChannelId, data) {
96 this.emit("frameReceived", httpChannelId, data);
100 * The "frameSent" message type handler. We redirect any message to
101 * the UI for displaying.
104 * @param string httpChannelId
105 * Channel ID of the websocket connection.
107 * The data received from the server.
109 async _onFrameSent(httpChannelId, data) {
110 this.emit("frameSent", httpChannelId, data);
114 exports.WebSocketFront = WebSocketFront;
115 registerFront(WebSocketFront);