UNPKG

@ray-core/plugin-devtools

Version:

Inject React Devtools to Ray

54 lines (53 loc) 1.79 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const global_1 = __importDefault(require("./global")); var ReadyState; (function (ReadyState) { ReadyState[ReadyState["CONNECTING"] = 0] = "CONNECTING"; ReadyState[ReadyState["OPEN"] = 1] = "OPEN"; ReadyState[ReadyState["CLOSING"] = 2] = "CLOSING"; ReadyState[ReadyState["CLOSED"] = 3] = "CLOSED"; })(ReadyState || (ReadyState = {})); class WebSocket { constructor(url) { this.CONNECTING = ReadyState.CONNECTING; this.OPEN = ReadyState.OPEN; this.CLOSING = ReadyState.CLOSING; this.CLOSED = ReadyState.CLOSED; this.readyState = ReadyState.CONNECTING; global_1.default.connectSocket({ url, }); global_1.default.onSocketOpen(() => { this.readyState = ReadyState.OPEN; if (typeof this.onopen === 'function') { this.onopen(); } }); global_1.default.onSocketError((res) => { if (typeof this.onerror === 'function') { this.onerror(res); } }); global_1.default.onSocketClose(() => { this.readyState = ReadyState.CLOSED; if (typeof this.onclose === 'function') { this.onclose(); } }); global_1.default.onSocketMessage((res) => { if (typeof this.onmessage === 'function') { this.onmessage(res); } }); } send(payload) { global_1.default.sendSocketMessage({ data: payload, }); } } exports.default = WebSocket;