我有類似的問題,但無法弄清楚發生了什麼。我有一個.Net頁面,其中包含用於訂閱的所有TokBox方法。我啓動一個新窗口(用於多個流的視頻監視器),初始化客戶端,將它們的clientSessions存儲在數組中,並在頁面上以網格模式顯示訂閱的流(在本例中僅使用一個客戶端)。我創建每次我與打開頁面時初始化每個客戶端會話:TokBox錯誤:OT.Session:無法連接,會話已被定義爲
lstSessions[i] = opener.initializeClientSession(apiKey, sessionId, token, $('Player'+i), 'subscribe');
在揭幕戰頁:
function initializeClientSession(apiKey, sessionId, token, container, myAction) {
var clientSession = OT.initSession(apiKey, sessionId);
console.log('initializeClientSession: ' + sessionId);
clientSession.connect(token, function (error) {
if (error) {
console.log("ERROR: initializeClientSession: " + myAction + " " + error);
}
else {
console.log("clientSession connected: " + myAction + " " + clientSession.id);
switch(myAction) {
case "publish":
publishClientVideo(clientSession, container);
break;
case "subscribe":
subscribeClientVideo(clientSession, container);
break;
case "delay":
if (inPVM) publishClientVideo(clientSession, container);
break;
}
}
});
return clientSession;
}
function subscribeClientVideo(clientSession, container) {
console.log("subscribeClientVideo: " + container.id + " " + clientSession.id);
clientSession.on('streamCreated', function (event) {
console.log("streamCreated: " + event.stream.id);
clientSubscriber = clientSession.subscribe(event.stream, container, {
insertMode: 'append',
width: '100%',
height: '100%'
}, function (error) {
if (error) {
console.log("ERROR clientSession.subscribe: " + error);
}
else {
console.log("Client subscribed: inPVM = " + inPVM);
}
});
});
}
我關閉視頻監視器和取消訂閱流:
function unsubscribeClientVideo(clientSession, container) {
console.log("unsubscribeClientVideo: " + clientSession.id + " " + contianer.id);
container.style.visibility = 'hidden';
try {
clientSession.unsubscribe(clientSubscriber);
}
catch (e) {
console.log("ERROR unsubscribeClientVideo: " + e);
}
}
第一次打開視頻監視器頁面時,此功能正常工作。但是,當我第二次嘗試時,出現錯誤「OT.Session:無法連接,會話已經未定義」。從控制檯日誌中我得到:
initializeClientSession: 2_MX40NTk1MjgxMn5-MTUwODA2NzU5NzcxNH55WVIzNXNtREpLREl0bHlUTGxhcWJBOFV-fg
clientSession connected: subscribe 2_MX40NTk1MjgxMn5-MTUwODA2NzU5NzcxNH55WVIzNXNtREpLREl0bHlUTGxhcWJBOFV-fg
subscribeClientVideo: videoPlayer0 2_MX40NTk1MjgxMn5-MTUwODA2NzU5NzcxNH55WVIzNXNtREpLREl0bHlUTGxhcWJBOFV-fg
streamCreated: e5ad9453-aa55-41ec-b150-d8dfd5b04875
Client subscribed: inPVM = true
在第二次嘗試:
initializeClientSession: 2_MX40NTk1MjgxMn5-MTUwODA2NzU5NzcxNH55WVIzNXNtREpLREl0bHlUTGxhcWJBOFV-fg
OT.Session: Cannot connect, the session is already undefined
我在unsubscribeClientVideo檢查的ClientSession,它說,它的連接。實際的客戶端正常發佈,沒有任何錯誤或警告。那麼,「SESSION」怎麼會是未定義的呢?我沒有觸及我所知道的「會話」。顯然,這裏有一些我真的不明白的地方。任何幫助不勝感激。
一行修復!無法告訴你我一直試圖弄清楚這一點。我只是添加了clientSession.disconnect();在取消發佈功能,一切都很好。那個消息太可怕了!......完全向錯誤的方向發送了我。感謝您的澄清! – Velocedge
非常歡迎! :) – Utkarsh