UNPKG

@genexus/web-standard-functions

Version:

GeneXus JavaScript standard functions library for web generators

58 lines 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GeneXusClientSocket = exports.SocketStatus = void 0; const socketService_1 = require("../../web/socketService"); const network_1 = require("../sd/network"); const client_information_1 = require("./client-information"); var SocketStatus; (function (SocketStatus) { SocketStatus[SocketStatus["Disconnected"] = 0] = "Disconnected"; SocketStatus[SocketStatus["Connected"] = 1] = "Connected"; })(SocketStatus || (exports.SocketStatus = SocketStatus = {})); class GeneXusClientSocket { /** * Connects to a Socket Server endpoint using the URL specified in the 'url' property * New messages will be published to '{url}.socket.messagereceived' event. * New opened connections will be published to '{url}.socket.connected' event. * Failed connections will be published to '{url}.socket.connectionfailed' event. * Closed connections will be published to '{url}.socket.connectionclosed' event. */ static async open(url) { this.url = resolveUrl(url); await this.socketService.open(this.url, url); this.status = SocketStatus.Connected; } /** * Closes the socket connection. */ static close() { this.status = SocketStatus.Disconnected; this.socketService.close(this.url); } /** * Sends the data to the currently connected Socket Server. * @param {any} data The data to send. */ static async send(data) { return this.socketService.send(this.url, data); } } exports.GeneXusClientSocket = GeneXusClientSocket; GeneXusClientSocket.url = ""; GeneXusClientSocket.status = SocketStatus.Disconnected; GeneXusClientSocket.socketService = socketService_1.default.getInstance(); const resolveUrl = (url) => { let wsUrl = url; if (!wsUrl) { wsUrl = network_1.GeneXusSDNetwork.applicationServerURL() .replace("http://", "ws://") .replace("https://", "wss://") + "gxwebsocket"; wsUrl = wsUrl.indexOf("?") < 0 ? wsUrl + "?" + client_information_1.GeneXusClientClientInformation.id() : wsUrl; } return wsUrl; }; //# sourceMappingURL=client-socket.js.map