WebRTC player - reconnect on error

Issues when playing with WebRTC Player

WebRTC player - reconnect on error

Postby admin » Tue Sep 18, 2018 4:26 pm

When WebRTC player stops playing, due to network error, broadcast not available, server down, or any other reason,
you can start playing again automatically with simple changes to unrealwebrtcplayer.js

In the unrealwebrtcplayer.js script,
locate the function

function onConnStateChange(event) {
if (pc.connectionState === "failed") {
Terminate();
alert("Connection failed; playback stopped");
}
}

and change it to:

var that = this;
function onConnStateChange(event) {
if (pc.connectionState === "failed") {
Terminate();
setTimeout(function () { that.Play(); }, 2000);
}
}


Notice the change - instead of alerting the message "Connection failed; playback stopped", we are starting to play again in 2 seconds.

Make similar changes in
function DoSignaling() : after each call to Terminate(), on the next line, instead of alerting, put the same line: setTimeout(function () { that.Play(); }, 2000);

So part of the function looks like that:

ws.onmessage = function(evt) {
var response = evt.data;
var strArr = response.split("|-|-|");

connOK = true;

if (state == 0) {
state = 1;

if (strArr.length == 1) {
Terminate();
setTimeout(function () { that.Play(); }, 2000);
}


Of course, you can also set the error text (the one that we are not alerting any more) somewhere on your web page, to let user know what happened, and also say something like "Reconnecting in 2 seconds..."
admin
Site Admin
 
Posts: 1022
Joined: Fri Aug 21, 2009 10:13 am

Re: WebRTC player - reconnect on error

Postby kpgchd » Mon Nov 05, 2018 3:36 am

Hi

I am trying same but getting error : "that.Play is not a function"...even I tried with this.Play
kpgchd
 
Posts: 0
Joined: Mon Nov 05, 2018 2:39 am

Re: WebRTC player - reconnect on error

Postby admin » Mon Nov 05, 2018 9:44 am

"even I tried with this.Play" - this will not work.

You need to follow this thread exactly.

Didn't you forget the very first line?
var that = this;
admin
Site Admin
 
Posts: 1022
Joined: Fri Aug 21, 2009 10:13 am


Return to Playing with WebRTC Player

Who is online

Users browsing this forum: No registered users and 1 guest