@litert/televoke
Version:
A simple RPC service framework.
87 lines • 2.88 kB
JavaScript
;
/**
* Copyright 2025 Angus.Fenying <fenying@litert.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.createWsConnector = createWsConnector;
exports.createWssConnector = createWssConnector;
const LibWS = require("@litert/websocket");
const dWS = require("./WebSocket.decl");
const WebSocket_Transporter_1 = require("./WebSocket.Transporter");
class WsConnector {
constructor(_opts) {
var _a;
this._opts = _opts;
(_a = this._opts).headers ?? (_a.headers = {});
}
setHeaders(newHeaders, append = true) {
if (append) {
Object.assign(this._opts.headers, newHeaders);
}
else {
this._opts.headers = newHeaders;
}
}
async connect() {
const ws = await LibWS.wsConnect({
...this._opts,
headers: {
...this._opts?.headers,
...LibWS.createClientHandshakeHeaders({
'subProtocols': [dWS.WEBSOCKET_SUB_PROTOCOL]
})
}
});
ws.setMasking(false);
return new WebSocket_Transporter_1.WebSocketTransporter(dWS.WS_PROTOCOL_NAME, ws);
}
}
class WssConnector {
constructor(_opts) {
var _a;
this._opts = _opts;
(_a = this._opts).headers ?? (_a.headers = {});
}
setHeaders(newHeaders, append = true) {
if (append) {
Object.assign(this._opts.headers, newHeaders);
}
else {
this._opts.headers = newHeaders;
}
}
async connect() {
const ws = await LibWS.wssConnect({
...this._opts,
headers: {
...this._opts?.headers,
...LibWS.createClientHandshakeHeaders({
'subProtocols': [dWS.WEBSOCKET_SUB_PROTOCOL]
})
}
});
ws.setMasking(false);
return new WebSocket_Transporter_1.WebSocketTransporter(dWS.WSS_PROTOCOL_NAME, ws);
}
}
function createWsConnector(opts) {
opts.frameReceiveMode = LibWS.EFrameReceiveMode.LITE;
return new WsConnector(opts);
}
function createWssConnector(opts) {
opts.frameReceiveMode = LibWS.EFrameReceiveMode.LITE;
return new WssConnector(opts);
}
//# sourceMappingURL=WebSocket.Client.js.map