Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TokBox Error: OT.Session: Cannot connect, the session is already undefined

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.

like image 792
Velocedge Avatar asked Mar 07 '23 19:03

Velocedge


1 Answers

I 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.

like image 82
UtkarshPramodGupta Avatar answered Apr 14 '23 16:04

UtkarshPramodGupta