Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// COMPOSITE FULL-ADDRESS
let address: string;
if (ip.indexOf("ws://") == -1)
if (ip.indexOf("://") != -1)
throw "only websocket is possible";
else
ip = "ws://" + ip;
if (path.length != 0 && path.charAt(0) != "/")
path = "/" + path;
address = ip + ":" + port + path;
// CONNECTION BRANCHES
if (std.is_node() == true)
{
this.node_client_ = new ws.client();
this.node_client_.on("connect", this._Handle_node_connect.bind(this));
this.node_client_.connect(address);
}
else
{
this.browser_socket_ = new WebSocket(address);
this.browser_socket_.onopen = this._Handle_browser_connect.bind(this);
this.browser_socket_.onerror = this._Handle_close.bind(this);
this.browser_socket_.onclose = this._Handle_close.bind(this);
this.browser_socket_.onmessage = this._Handle_browser_message.bind(this);
}
}
public close(): void
{
if (std.is_node() == true)
super.close();
else
this.browser_socket_.close();
}