arv*_*sim 7 api videochat video-conferencing tokbox
我查看了这些链接
http://www.tokbox.com/opentok/api/tools/js/documentation/overview/publish.html
http://www.tokbox.com/opentok/api/tools/js/tutorials/overview
但它们不是手动发布发布的示例,也就是说,不分别使用'streamCreated'/'streamDestroyed'事件处理程序发布/取消发布.
我想这样做的原因是我有一个发布/取消发布的按钮,以便用户可以随意进行.
有没有办法做到这一点?
是的,而且非常简单。查看预发布源代码以了解具体操作方法。有 2 个函数 startPublishing() 和 stopPublishing() 可以实现此目的。
它们主要用于session.publish(publisher);发布和session.unpublish(publisher);取消发布。
这是我用来处理的代码:
// Called by a button to start publishing to the session
function startPublishing() {
if (!publisher) {
var parentDiv = document.getElementById("myCamera");
var publisherDiv = document.createElement('div'); // Create a div for the publisher to replace
publisherDiv.setAttribute('id', 'opentok_publisher');
parentDiv.appendChild(publisherDiv);
var publisherProps = {
width : VIDEO_WIDTH,
height : VIDEO_HEIGHT
};
publisher = TB.initPublisher(apiKey, publisherDiv.id, publisherProps); // Pass the replacement div id and properties
session.publish(publisher);
show('unpublishLink');
hide('publishLink');
}
}
//Called by a button to stop publishing to the session
function stopPublishing() {
if (publisher) {
session.unpublish(publisher);
}
publisher = null;
show('publishLink');
hide('unpublishLink');
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2099 次 |
| 最近记录: |