【问题标题】:TokBox Error: OT.Session: Cannot connect, the session is already undefinedTokBox 错误:OT.Session:无法连接,会话已经未定义
【发布时间】:2018-03-27 01:53:27
【问题描述】:

我遇到了类似的问题,但无法弄清楚这里发生了什么。我有一个 .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”怎么可能是未定义的呢?我还没有碰过我所知道的“会话”。显然,这里有些东西我真的不明白。非常感谢任何帮助。

【问题讨论】:

    标签: javascript node.js session stream tokbox


    【解决方案1】:

    我猜警告“OT.Session: 无法连接,会话已经未定义”有点误导。在您的 unsubscribeClientVideo 函数中,您所做的只是取消订阅订阅者的视频源之一,但实际上您仍然连接到会话。所以简而言之,你试图通过运行 clientSession.connect() 函数两次来连接到你已经连接的会话。

    【讨论】:

    • 一行修复!不能告诉你我已经尝试了多久。我只是添加了 clientSession.disconnect();在取消发布功能中,一切都很好。那条消息太糟糕了!.. 完全把我送错了方向。感谢您的澄清!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-22
    • 2013-10-09
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 2020-08-13
    相关资源
    最近更新 更多