8

私はこれらのリンクを見ました

http://www.tokbox.com/opentok/api/tools/js/documentation/overview/publish.html

http://www.tokbox.com/opentok/api/tools/js/tutorials/overview

ただし、これらは手動で公開/非公開の例ではありません。つまり、それぞれ「streamCreated」/「streamDestroyed」イベントハンドラーを使用せずに公開/非公開します。

これを実行したい理由は、ユーザーが自由に実行できるように、公開/非公開のボタンがあるためです。

これを行う方法はありますか?

4

1 に答える 1

4

はい、とても簡単です。公開前のソース コードをチェックして、その方法を確認してください。これを実現する startPublishing() と stopPublishing() の 2 つの関数があります。

主に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');
}
于 2012-10-22T09:38:59.567 に答える