0

I'm trying to achieve a video conference between 2 users. Below code displays published video and subscribed video. I want to publish but not display the published video to the user and only display subscribed video. How to achieve that? Thanks in advance!

            var session = OT.initSession(apiKey, sessionId)
                .connect(token, function(error) {

                    var publisher = OT.initPublisher('divPublish');
                    session.publish(publisher);
                    console.log("Publishing to session1");
                });


                    var session2 = OT.initSession(apiKey, sessionId2);
                    session2.connect(token2, function(error) {
                        if (error) {
                            console.log("Error connecting: ", error.name, error.message);
                        } else {
                            console.log("Connected to the session2.");
                        }
                    });

                    session2.on("streamCreated", function(event) {
                        //var options = { width: 400, height: 300, insertMode: 'append' }
                        session2.subscribe(event.stream, 'divSubscribe');
                        console.log("Subscribing to session2");
                    });
Karts
  • 85
  • 2
  • 12
  • I'm not sure what your use case is but if you want the publisher and subscriber to see each other then you should only initialise and connect to a single session, not two. – aiham Mar 10 '17 at 14:55

1 Answers1

3

You can initialise a publisher that doesn't appear on the page by providing a detached DOM element as the first argument:

const container = document.createElement('div');
const publisher = OT.initPublisher(container);

It's up to you if you want to attach that container to the page or not.

See targetElement argument of OT.initPublisher: https://tokbox.com/developer/sdks/js/reference/OT.html#initPublisher

aiham
  • 3,614
  • 28
  • 32