我查看了这些链接
http://www.tokbox.com/opentok/api/tools/js/documentation/overview/publish.html http://www.tokbox.com/opentok/api/tools/js/documentation/overview/publish.html
http://www.tokbox.com/opentok/api/tools/js/tutorials/overview http://www.tokbox.com/opentok/api/tools/js/tutorials/overview
但它们没有手动发布/取消发布的示例,即不分别使用“streamCreated”/“streamDestroyed”事件处理程序的情况下发布/取消发布。
我想这样做的原因是我有一个发布/取消发布的按钮,以便用户可以随意执行。
有没有办法做到这一点?
是的,而且非常简单。查看预发布 http://www.tokbox.com/opentok/api/tools/js/tutorials/prepublish.html源代码看看如何。有 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');
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)