如何手动发布/取消发布?
我看着这些链接
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');
}
链接地址: http://www.djcxy.com/p/11325.html