Publishing a stream
Once you have a Publisher object and a session the next step is to pass it to the session object.
Pass the publisher object into the publish() method of a Session object to publish a stream to the session:
The second parameter is a completion handler function that is passed an error object if publishing fails. Otherwise the completion handler function is called with no error passed in.
This code assumes that session is a Session object, and that the client has connected to the session. For more information, see Joining a Session.
The Publish object dispatches a streamCreated event when it starts streaming to the session:
The Publisher object has an element property, which is set to the HTML DOM element containing it.
To publish a stream, add an OTPublisher component as a child of the OTSession object:
The publisher starts streaming when the client connects to the session. The OTPublisher object dispatches a streamCreated event when it starts streaming to the session. It dispatches an error event if there is an error publishing. Set an eventHandlers prop of the OTPublisher component, and set the streamCreated and error properties of that object to callback functions:
Pass the publisher object into the publish(PublisherKit publisher) method of a Session object to publish the stream to the session:
This code assumes that mSession is a Session object, and that the client has connected to the session. For more information, see Joining a Session.
The PublisherKit.PublisherListener.onStreamCreated(PublisherKit publisher, Stream stream) method is called when the publisher starts streaming to the session:
Pass the publisher object into the OTSession publish(_:error:) method of an OTSession object to publish the stream to the session:
This code assumes that session is a Session object, and that the client has connected to the session. For more information, see Joining a Session.
The OTPublisherDelegate publisher(_:streamCreated:) message is sent when the publisher starts streaming to the session.
Pass the publisher object into the [OTSession publish:error] method of an OTSession object to publish the stream to the session:
This code assumes that session is a Session object, and that the client has connected to the session. For more information, see Creating a Session.
The [OTPublisherDelegate publisher:streamCreated:] message is sent when the publisher starts streaming to the session.
Pass the publisher object into the Publish(publisher) method of a Session object to publish the stream to the session:
This code assumes that session is a Session object, that publisher is a Publisher object and that the client has connected to the session. For more information, see Joining a Session.
The Publisher sends the StreamCreated event when the publisher starts streaming to the session:
Publishing a stream
When the application connects to a session, the on_connected() callback function of the otc_session_callbacks struct is called (see Joining a Session). In response to this, you can call the otc_session_publish() function to publish a stream to the OpenTok session:
The otc_session_publish() function takes two arguments:
- The pointer to the
otc_sessionstructure. - The
otc_publisherstructure.
It returns OTC_SUCCESS when it successfully starts publishing a stream to the session. Or it returns an error, and the otc_error callback is called.