@flashphoner/websdk 2.0.208 → 2.0.209

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8898,6 +8898,9 @@ var getSession = function getSession(id) {
8898
8898
  * @param {Object=} options.sipOptions Sip configuration
8899
8899
  * @param {Object=} options.mediaOptions Media connection configuration
8900
8900
  * @param {Integer=} options.timeout Connection timeout in milliseconds
8901
+ * @param {Integer=} options.pingInterval Server ping interval in milliseconds [0]
8902
+ * @param {Integer=} options.receiveProbes A maximum subsequental pings received missing count [0]
8903
+ * @param {Integer=} options.probesInterval Interval to check subsequental pings received [0]
8901
8904
  * @returns {Session} Created session
8902
8905
  * @throws {Error} Error if API is not initialized
8903
8906
  * @throws {TypeError} Error if options.urlServer is not specified
@@ -8924,6 +8927,8 @@ var createSession = function createSession(options) {
8924
8927
  var mediaOptions = options.mediaOptions;
8925
8928
  var keepAlive = options.keepAlive;
8926
8929
  var timeout = options.timeout;
8930
+ var wsPingSender = new WSPingSender(options.pingInterval || 0);
8931
+ var wsPingReceiver = new WSPingReceiver(options.receiveProbes || 0, options.probesInterval || 0);
8927
8932
  var connectionTimeout;
8928
8933
  var cConfig; //SIP config
8929
8934
 
@@ -9041,7 +9046,7 @@ var createSession = function createSession(options) {
9041
9046
  mediaProviders: Object.keys(MediaProvider),
9042
9047
  keepAlive: keepAlive,
9043
9048
  authToken: authToken,
9044
- clientVersion: "2.0.208",
9049
+ clientVersion: "2.0.209",
9045
9050
  clientOSVersion: window.navigator.appVersion,
9046
9051
  clientBrowserVersion: window.navigator.userAgent,
9047
9052
  msePacketizationVersion: 2,
@@ -9054,7 +9059,11 @@ var createSession = function createSession(options) {
9054
9059
 
9055
9060
 
9056
9061
  send("connection", cConfig);
9057
- logger.setConnection(wsConnection);
9062
+ logger.setConnection(wsConnection); // Send ping messages to server to check if connection is still alive #WCS-3410
9063
+
9064
+ wsPingSender.start(); // Check subsequintel pings received from server to check if connection is still alive #WCS-3410
9065
+
9066
+ wsPingReceiver.start();
9058
9067
  };
9059
9068
 
9060
9069
  wsConnection.onmessage = function (event) {
@@ -9070,6 +9079,7 @@ var createSession = function createSession(options) {
9070
9079
  switch (data.message) {
9071
9080
  case 'ping':
9072
9081
  send("pong", null);
9082
+ wsPingReceiver.success();
9073
9083
  break;
9074
9084
 
9075
9085
  case 'getUserData':
@@ -9229,7 +9239,11 @@ var createSession = function createSession(options) {
9229
9239
  sessionStatus = newStatus;
9230
9240
 
9231
9241
  if (sessionStatus == SESSION_STATUS.DISCONNECTED || sessionStatus == SESSION_STATUS.FAILED) {
9232
- //remove streams
9242
+ // Stop pinging server #WCS-3410
9243
+ wsPingSender.stop(); // Stop checking pings received #WCS-3410
9244
+
9245
+ wsPingReceiver.stop(); //remove streams
9246
+
9233
9247
  for (var prop in streamRefreshHandlers) {
9234
9248
  if (streamRefreshHandlers.hasOwnProperty(prop) && typeof streamRefreshHandlers[prop] === 'function') {
9235
9249
  streamRefreshHandlers[prop]({
@@ -9245,6 +9259,73 @@ var createSession = function createSession(options) {
9245
9259
  if (callbacks[sessionStatus]) {
9246
9260
  callbacks[sessionStatus](session, obj);
9247
9261
  }
9262
+ } // Websocket periodic ping sender
9263
+
9264
+
9265
+ function WSPingSender(interval) {
9266
+ this.interval = interval || 0;
9267
+ this.intervalId = null;
9268
+
9269
+ this.start = function () {
9270
+ if (this.interval > 0) {
9271
+ this.intervalId = setInterval(function () {
9272
+ send("ping", null);
9273
+ }, this.interval);
9274
+ }
9275
+ };
9276
+
9277
+ this.stop = function () {
9278
+ if (this.intervalId) {
9279
+ clearInterval(this.intervalId);
9280
+ }
9281
+ };
9282
+
9283
+ return this;
9284
+ } // Websocket ping receive prober
9285
+
9286
+
9287
+ function WSPingReceiver(receiveProbes, probesInterval) {
9288
+ this.maxPings = receiveProbes || 0;
9289
+ this.interval = probesInterval || 0;
9290
+ this.intervalId = null;
9291
+ this.pingsMissing = 0;
9292
+
9293
+ this.start = function () {
9294
+ if (this.maxPings > 0 && this.interval > 0) {
9295
+ var receiver = this;
9296
+ this.intervalId = setInterval(function () {
9297
+ receiver.checkPingsReceived();
9298
+ }, this.interval);
9299
+ }
9300
+ };
9301
+
9302
+ this.stop = function () {
9303
+ if (this.intervalId) {
9304
+ clearInterval(this.intervalId);
9305
+ }
9306
+
9307
+ this.pingsMissing = 0;
9308
+ };
9309
+
9310
+ this.checkPingsReceived = function () {
9311
+ this.pingsMissing++;
9312
+
9313
+ if (this.pingsMissing >= this.maxPings) {
9314
+ this.failure();
9315
+ }
9316
+ };
9317
+
9318
+ this.success = function () {
9319
+ this.pingsMissing = 0;
9320
+ };
9321
+
9322
+ this.failure = function () {
9323
+ logger.info(LOG_PREFIX, "Missing " + this.pingsMissing + " pings from server, connection seems to be down");
9324
+ onSessionStatusChange(SESSION_STATUS.FAILED);
9325
+ wsConnection.close();
9326
+ };
9327
+
9328
+ return this;
9248
9329
  }
9249
9330
  /**
9250
9331
  * @callback sdpHook