【问题标题】:Tokbox/Opentok: How to not display published videoTokbox/Opentok:如何不显示已发布的视频
【发布时间】:2017-03-10 08:46:05
【问题描述】:

我正在尝试实现 2 个用户之间的视频会议。下面的代码显示发布的视频和订阅的视频。我想发布但不向用户显示发布的视频,只显示订阅的视频。如何做到这一点?提前致谢!

            var session = OT.initSession(apiKey, sessionId)
                .connect(token, function(error) {

                    var publisher = OT.initPublisher('divPublish');
                    session.publish(publisher);
                    console.log("Publishing to session1");
                });


                    var session2 = OT.initSession(apiKey, sessionId2);
                    session2.connect(token2, function(error) {
                        if (error) {
                            console.log("Error connecting: ", error.name, error.message);
                        } else {
                            console.log("Connected to the session2.");
                        }
                    });

                    session2.on("streamCreated", function(event) {
                        //var options = { width: 400, height: 300, insertMode: 'append' }
                        session2.subscribe(event.stream, 'divSubscribe');
                        console.log("Subscribing to session2");
                    });

【问题讨论】:

  • 我不确定您的用例是什么,但如果您希望发布者和订阅者互相看到,那么您应该只初始化并连接到一个会话,而不是两个。

标签: opentok tokbox video-conferencing


【解决方案1】:

您可以通过提供分离的 DOM 元素作为第一个参数来初始化未出现在页面上的发布者:

const container = document.createElement('div');
const publisher = OT.initPublisher(container);

是否要将 container 附加到页面由您决定。

参见OT.initPublishertargetElement 参数:https://tokbox.com/developer/sdks/js/reference/OT.html#initPublisher

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多