/**
|
* 获取Websocket的连接
|
* @param action
|
* @param port
|
* @returns {string}
|
*/
|
function getWsUrl(action: string, port?: string): string {
|
let _port = port ? port : 8080;
|
let hostname = window.location.hostname;
|
let wsProtocol = "ws://";
|
if (window.location.protocol === "https:") {
|
wsProtocol = "wss://";
|
}
|
if (process.env.NODE_ENV === "development") {
|
hostname = "localhost";
|
} else {
|
_port = window.location.port;
|
}
|
// 处理端口为80
|
_port = _port === 80 ? "" : ":" + _port;
|
return wsProtocol + hostname + _port + "/bg/" + action;
|
}
|
|
export default getWsUrl;
|