3

We are trying to connect WebSocket using below code, found no issues when the internet is working fine. But when internet is down or due to some other N/W related issues this message getting displayed in the browser console:

"WebSocket connection to 'wss://phone.company.com:5063/' failed: Error in connection establishment: net::ERR_INTERNET_DISCONNECTED".

Is there a way to catch this error and throw delegate callback to clients like onWebSocketConnectionFailed()?

var sConn = {
        socket: null,
        uri: 'wss://phone.complany.com:5063',

  try {

    this.ws = new WebSocket(this.url, 'sip');

    this.ws.onopen    = onOpen.bind(this);
    this.ws.onclose   = onClose.bind(this);
    this.ws.onmessage = onMessage.bind(this);
    this.ws.onerror   = onError.bind(this);

  } catch(e) {
    onError.call(this, e);
  }
}
Long Luong
  • 764
  • 2
  • 14
  • 28
Cherry
  • 699
  • 1
  • 7
  • 20

0 Answers0