nttcom / peerjs

[Deprecated] This branch is a customized version of PeerJS for NTT Communications's WebRTC platform SkyWay.
http://nttcom.github.io/skyway/en/
Other
225 stars 91 forks source link

Websocket sudddenly closes #56

Closed brickgale closed 7 years ago

brickgale commented 7 years ago

Currently I'm creating a modification on how to communicate via WebSockets only, using send function of web sockets, encountered Uncaught TypeError: e.error is not a function at WebSocket._socket._socket.onclose. On the original peerjs, there were no error as such since it won't fallback to xhr as what i've seen on skyway modified it on this._socket.onclose event/function.

https://skyway.io/dist/0.3/peer.js

// Fall back to XHR if WS closes
  this._socket.onclose = function(msg) {
      util.error("WS closed with code "+msg.code);
      if(!self.disconnected) {
        self._startXhrStream();
      }
  }
brickgale commented 7 years ago

Fixed it by overriding Socket.prototype._startWebSocket, removing blocks of code:

if (util.supportsKeepAlive) {
      self._setWSTimeout();
}

and modified onclose to:

this._socket.onclose = function(msg) {
      util.log("WS closed with code "+msg.code);
      self.disconnected = true;
      self.emit('disconnected');
}