Merge pull request #61 from kPherox/fix-integrated-tl-reconnect-streaming

Fix integrated tl reconnect streaming
This commit is contained in:
Cutls 2019-04-22 23:18:12 +09:00 committed by GitHub
commit d439169c63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 14 deletions

View File

@ -94,12 +94,14 @@ function mixre(acct_id, tlid, TLtype, mute,delc,voice,mode) {
websocketLocal[wslid] = new WebSocket(startLocal); websocketLocal[wslid] = new WebSocket(startLocal);
websocketHome[wshid].onopen = function(mess) { websocketHome[wshid].onopen = function(mess) {
localStorage.setItem("wssH_" + tlid, wshid); localStorage.setItem("wssH_" + tlid, wshid);
console.log("Connect Streaming API(Integrated:Home)"); console.log(tlid + ":Connect Streaming API(Integrated:Home)");
console.log(mess);
$("#notice_icon_" + tlid).removeClass("red-text"); $("#notice_icon_" + tlid).removeClass("red-text");
} }
websocketLocal[wslid].onopen = function(mess) { websocketLocal[wslid].onopen = function(mess) {
localStorage.setItem("wssL_" + tlid, wslid); localStorage.setItem("wssL_" + tlid, wslid);
console.log("Connect Streaming API(Integrated:Local)"); console.log(tlid + ":Connect Streaming API(Integrated:Local)");
console.log(mess);
$("#notice_icon_" + tlid).removeClass("red-text"); $("#notice_icon_" + tlid).removeClass("red-text");
} }
websocketLocal[wslid].onmessage = function(mess) { websocketLocal[wslid].onmessage = function(mess) {
@ -195,39 +197,57 @@ function mixre(acct_id, tlid, TLtype, mute,delc,voice,mode) {
} }
} }
websocketLocal[wslid].onerror = function(error) { websocketLocal[wslid].onerror = function(error) {
console.error('WebSocket Error ' + error); console.error('WebSocketLocal Error')
console.error(error);
if(mode=="error"){ if(mode=="error"){
$("#notice_icon_" + tlid).addClass("red-text"); $("#notice_icon_" + tlid).addClass("red-text");
todo('WebSocket Error ' + error); todo('WebSocket Error ' + error);
}else{ }else{
reconnector(tlid,TLtype,acct_id,"","error"); var errorct=localStorage.getItem("wserror_" + tlid)*1+1;
localStorage.setItem("wserror_" + tlid,errorct);
if(errorct<3){
reconnector(tlid,TLtype,acct_id,"","error");
}
} }
}; };
websocketLocal[wslid].onclose = function() { websocketLocal[wslid].onclose = function() {
console.error('WebSocketLocal Closing by error:' + tlid); console.log('WebSocketLocal Closing:' + tlid);
if(mode=="error"){ if(mode=="error"){
$("#notice_icon_" + tlid).addClass("red-text"); $("#notice_icon_" + tlid).addClass("red-text");
todo('WebSocket Closed'); todo('WebSocket Closed');
}else{ }else{
reconnector(tlid,TLtype,acct_id,"","error"); var errorct=localStorage.getItem("wserror_" + tlid)*1+1;
localStorage.setItem("wserror_" + tlid,errorct);
if(errorct<3){
reconnector(tlid,TLtype,acct_id,"","error");
}
} }
}; };
websocketHome[wshid].onerror = function(error) { websocketHome[wshid].onerror = function(error) {
console.error('WebSocket Error ' + error); console.error('WebSocketHome Error')
console.error(error);
if(mode=="error"){ if(mode=="error"){
$("#notice_icon_" + tlid).addClass("red-text"); $("#notice_icon_" + tlid).addClass("red-text");
todo('WebSocket Error ' + error); todo('WebSocket Error ' + error);
}else{ }else{
reconnector(tlid,TLtype,acct_id,"","error"); var errorct=localStorage.getItem("wserror_" + tlid)*1+1;
localStorage.setItem("wserror_" + tlid,errorct);
if(errorct<3){
reconnector(tlid,TLtype,acct_id,"","error");
}
} }
}; };
websocketHome[wshid].onclose = function() { websocketHome[wshid].onclose = function() {
console.error('WebSocketHome Closing by error:' + tlid); console.log('WebSocketHome Closing:' + tlid);
if(mode=="error"){ if(mode=="error"){
$("#notice_icon_" + tlid).addClass("red-text"); $("#notice_icon_" + tlid).addClass("red-text");
todo('WebSocket Closed'); todo('WebSocket Closed');
}else{ }else{
reconnector(tlid,TLtype,acct_id,"","error"); var errorct=localStorage.getItem("wserror_" + tlid)*1+1;
localStorage.setItem("wserror_" + tlid,errorct);
if(errorct<3){
reconnector(tlid,TLtype,acct_id,"","error");
}
} }
}; };

View File

@ -337,8 +337,8 @@ function reload(type, cc, acct_id, tlid, data, mute, delc, voice, mode) {
return false; return false;
}; };
websocket[wsid].onclose = function() { websocket[wsid].onclose = function() {
console.error("Closing"); console.log("Closing");
console.error(tlid); console.log(tlid);
if(mode=="error"){ if(mode=="error"){
$("#notice_icon_" + tlid).addClass("red-text"); $("#notice_icon_" + tlid).addClass("red-text");
todo('WebSocket Closed'); todo('WebSocket Closed');
@ -788,7 +788,7 @@ function strAliveInt(){
} }
function reconnector(tlid,type,acct_id,data,mode){ function reconnector(tlid,type,acct_id,data,mode){
console.log("Reconnector:"+mode) console.log("Reconnector:"+mode)
if(type=="mix" || type=="plus"){ if(type=="mix" || type=="integrated" || type=="plus"){
if(localStorage.getItem("voice_" + tlid)){ if(localStorage.getItem("voice_" + tlid)){
var voice=true; var voice=true;
}else{ }else{
@ -801,7 +801,7 @@ function reconnector(tlid,type,acct_id,data,mode){
} }
var wssh=localStorage.getItem("wssH_" + tlid); var wssh=localStorage.getItem("wssH_" + tlid);
websocketHome[wssh].close(); websocketHome[wssh].close();
var wssh=localStorage.getItem("wssL_" + tlid); var wssl=localStorage.getItem("wssL_" + tlid);
websocketLocal[wssl].close(); websocketLocal[wssl].close();
mixre(acct_id, tlid, type, mute,"",voice,mode); mixre(acct_id, tlid, type, mute,"",voice,mode);
}else if(type=="notf"){ }else if(type=="notf"){