@eclipse-glsp/theia-integration
Version:
Glue code to integrate GLSP clients into Eclipse Theia
49 lines • 2.24 kB
JavaScript
;
/********************************************************************************
* Copyright (c) 2023 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getWebSocketAddress = getWebSocketAddress;
exports.isValidWebSocketAddress = isValidWebSocketAddress;
/**
* Utility function that tries to construct a WebSocket address from the given partial {@link WebSocketConnectionInfo}.
* To construct a valid address the info most provide at least a port and and a path.
* @param info Partial connection information
* @returns The corresponding address, or `undefined` if the info does not contain the required properties.
*/
function getWebSocketAddress(info) {
var _a, _b;
if ('path' in info && info.path !== undefined && 'port' in info && info.port !== undefined) {
const protocol = (_a = info.protocol) !== null && _a !== void 0 ? _a : 'ws';
const host = (_b = info.host) !== null && _b !== void 0 ? _b : '127.0.0.1';
return `${protocol}://${host}:${info.port}/${info.path}`;
}
return undefined;
}
/**
* Validates wether the given string is valid WebSocket address.
* @param address The address to validate
* @returns `true` if the address is valid, `false` otherwise
*/
function isValidWebSocketAddress(address) {
try {
const { protocol } = new URL(address);
return protocol === 'ws:' || protocol === 'wss:';
}
catch (error) {
return false;
}
}
//# sourceMappingURL=websocket-util.js.map