我遇到了类似的问题,但无法弄清楚这里发生了什么。我有一个 .Net 页面,其中包含用于订阅的所有 TokBox 方法。我启动一个新窗口(多个流的视频监视器),初始化客户端,将它们的 clientSession 存储在一个数组中,并在页面上以网格模式显示订阅的流(在本例中,仅使用一个客户端)。每次打开页面时,我都会创建并初始化每个客户端 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:无法连接, 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”怎么可能是未定义的呢?我还没有触及我所知道的“ session ”。显然,这里有些东西我真的不明白。非常感谢任何帮助。
最佳答案
我猜警告“OT.Session:无法连接, session 已经未定义”有点误导。在您的 unsubscribeClientVideo 功能中,您所做的只是取消订阅订阅者的视频源之一,但实际上您仍然连接到 session 。所以简而言之,您正在尝试通过运行两次 clientSession.connect() 函数来连接到您已经连接到的 session 。
关于javascript - TokBox 错误 : OT. session : Cannot connect, session 已未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46755137/