Search code examples
javascriptopentoktokbox

TokBox: is there way to recreate video window?


When creating session, we passing element's id to replace with video window. But if element were removed from DOM tree, can we re-bind session to another element?


Solution

  • There is no way to rebind a publisher or subscriber to a different element after it's already been initialised.

    Instead you should create a container that you provide to the publisher/subscriber and then you can append and move that container to anywhere in the DOM as you like.

    Eg:

    const pubContainer = document.createElement('div');
    const publisher = OT.initPublisher(pubContainer);
    session.publish(publisher);
    document.getElementById('A').appendChild(pubContainer);
    

    Then later:

    pubContainer.parentElement.removeChild(pubContainer);
    document.getElementById('B').appendChild(pubContainer);