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