admin管理员组文章数量:1357276
I had a similar problem but can't figure out what is happening here. I have a .Net page that contains all the TokBox methods for subscribing. I launch a new window (video monitor for multiple streams), initialize the clients, store their clientSessions in an array, and display the subscribed streams in a grid pattern on the page (in this example, only using one client). I create and initialize each client session every time I open the page with:
lstSessions[i] = opener.initializeClientSession(apiKey, sessionId, token, $('Player'+i), 'subscribe');
In the Opener page:
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);
}
});
});
}
I close the Video Monitor and unsubscribe from the streams using:
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);
}
}
This works properly the first time I open the Video Monitor page. However, when I try it a second time, I get the error, "OT.Session: Cannot connect, the session is already undefined". From the console log I get:
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
On the second attempt:
initializeClientSession: 2_MX40NTk1MjgxMn5-MTUwODA2NzU5NzcxNH55WVIzNXNtREpLREl0bHlUTGxhcWJBOFV-fg
OT.Session: Cannot connect, the session is already undefined
I've checked clientSession in unsubscribeClientVideo and it says it's connected. The actual client is publishing like normal without any errors or warnings. So, how can the "SESSION" be undefined? I haven't touched the "session" that I know of. Obviously, there is something here I really don't understand. Any help greatly appreciated.
I had a similar problem but can't figure out what is happening here. I have a .Net page that contains all the TokBox methods for subscribing. I launch a new window (video monitor for multiple streams), initialize the clients, store their clientSessions in an array, and display the subscribed streams in a grid pattern on the page (in this example, only using one client). I create and initialize each client session every time I open the page with:
lstSessions[i] = opener.initializeClientSession(apiKey, sessionId, token, $('Player'+i), 'subscribe');
In the Opener page:
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);
}
});
});
}
I close the Video Monitor and unsubscribe from the streams using:
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);
}
}
This works properly the first time I open the Video Monitor page. However, when I try it a second time, I get the error, "OT.Session: Cannot connect, the session is already undefined". From the console log I get:
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
On the second attempt:
initializeClientSession: 2_MX40NTk1MjgxMn5-MTUwODA2NzU5NzcxNH55WVIzNXNtREpLREl0bHlUTGxhcWJBOFV-fg
OT.Session: Cannot connect, the session is already undefined
I've checked clientSession in unsubscribeClientVideo and it says it's connected. The actual client is publishing like normal without any errors or warnings. So, how can the "SESSION" be undefined? I haven't touched the "session" that I know of. Obviously, there is something here I really don't understand. Any help greatly appreciated.
Share Improve this question edited Aug 23, 2019 at 4:23 UtkarshPramodGupta 8,1727 gold badges36 silver badges57 bronze badges asked Oct 15, 2017 at 12:39 VelocedgeVelocedge 1,4651 gold badge16 silver badges46 bronze badges1 Answer
Reset to default 9I guess the warning "OT.Session: Cannot connect, the session is already undefined" is a bit misleading. In your unsubscribeClientVideo function, all you are doing is unsubscribing to one of the subscriber's video feed but you are still connected to the session actually. So in short, you are trying to connect to a session you are already connected to by running clientSession.connect() function twice.
本文标签: javascriptTokBox Error OTSession Cannot connectthe session is already undefinedStack Overflow
版权声明:本文标题:javascript - TokBox Error: OT.Session: Cannot connect, the session is already undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744075534a2586676.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论