I am using OpenTok api for One-To-One Video Conference.Is there any way so that I can use it for live stream.So in my case Only one user will publish the stream on session and every other user will connect to that.
But its required to add publisher element for each stream,so how can without publishing a stream , connect to single user.
I would appreciate if solution has a example.
You just need to serve the "publishing user" and all the other users 2 different scripts (on 2 different pages).
The "publishing user" will have code that connects to the session and then publishes a stream. Example:
var session = OT.initSession(apiKey, sessionId);
var publisher = OT.initPublisher('publisher', function(error) {
if (error) return alert('please reload and allow permission for your camera and mic');
session.connect(token, function(error) {
if (error) return alert('session connection error: ' + error.message);
session.publish(publisher);
});
);
All the other users will have code that connects to the session and subscribes to a stream. Example:
var session = OT.initSession(apiKey, sessionId);
session.on('streamCreated', function(event) {
session.subscribe(event.stream, 'subscriber', function(error) {
if (error) return alert('stream subscriber error:' + error.message);
});
});
session.connect(token, function(error) {
if (error) return alert('session connection error: ' + error.message);
});
Also, be aware that sessions with many users should be of mediaMode="routed" in order to help scale with quality. Even with routed sessions, having too many subscribers with a wide range of connectivity (bandwidth, latency, decoding power) will impact the quality of the stream negatively. If you have sessions with larger than ~30 subscribers, you should get in touch with TokBox support to help you adjust settings to scale your sessions.