PHP WebShell
Текущая директория: /usr/lib/node_modules/bitgo/node_modules/rpc-websockets/dist/lib/client
Просмотр файла: websocket.browser.cjs
/**
* WebSocket implements a browser-side WebSocket specification.
* @module Client
*/
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const eventemitter3_1 = require("eventemitter3");
class WebSocketBrowserImpl extends eventemitter3_1.EventEmitter {
socket;
/** Instantiate a WebSocket class
* @constructor
* @param {String} address - url to a websocket server
* @param {(Object)} options - websocket options
* @param {(String|Array)} protocols - a list of protocols
* @return {WebSocketBrowserImpl} - returns a WebSocket instance
*/
constructor(address, options, protocols) {
super();
this.socket = new window.WebSocket(address, protocols);
this.socket.onopen = () => this.emit("open");
this.socket.onmessage = (event) => this.emit("message", event.data);
this.socket.onerror = (error) => this.emit("error", error);
this.socket.onclose = (event) => {
this.emit("close", event.code, event.reason);
};
}
/**
* Sends data through a websocket connection
* @method
* @param {(String|Object)} data - data to be sent via websocket
* @param {Object} optionsOrCallback - ws options
* @param {Function} callback - a callback called once the data is sent
* @return {Undefined}
*/
send(data, optionsOrCallback, callback) {
const cb = callback || optionsOrCallback;
try {
this.socket.send(data);
cb();
}
catch (error) {
cb(error);
}
}
/**
* Closes an underlying socket
* @method
* @param {Number} code - status code explaining why the connection is being closed
* @param {String} reason - a description why the connection is closing
* @return {Undefined}
* @throws {Error}
*/
close(code, reason) {
this.socket.close(code, reason);
}
addEventListener(type, listener, options) {
this.socket.addEventListener(type, listener, options);
}
}
/**
* factory method for common WebSocket instance
* @method
* @param {String} address - url to a websocket server
* @param {(Object)} options - websocket options
* @return {Undefined}
*/
function default_1(address, options) {
return new WebSocketBrowserImpl(address, options);
}
exports.default = default_1;
Выполнить команду
Для локальной разработки. Не используйте в интернете!