Skip to main content

Publish to Conference

To participate actively in a conference, you can publish your audio, video, or screen using the SDK. Before publishing, ensure you have obtained the necessary media streams using the createMediaStream method. Detailed instructions for obtaining media streams are available on the Accessing medias page.

Steps to Publish:

  1. Obtain Media Streams: Use the createMediaStream method to capture audio, video, or screen content that you intend to publish. Refer to the detailed instructions on createMediaStream for guidance here.

  2. Publish to Conference: Once you have obtained the media streams, you can use the publish method to send your streams to the conference. The publish method requires the media stream obtained from createMediaStream as its argument.

How to use publish method

    const localstream = await twyng.createMediastream({
video: {
source: 'camera',
resolution: {
width: 640,
height: 360
}
}, audio: 'mic'
})
const publication = await twyng.publish(localstream)

Manage the publishing:

The publish method returns an instance with additional features for managing the publishing

  1. Mute/Unmute: Control the audio or video stream's mute state.
  2. Stop: Stop publishing the stream to the conference.
  3. ChangeDevice: Switch the media input device (e.g., switch cameras).
  4. addEventListener/removeEventListener: Register or unregister event listeners to handle events related to publishing.

Mute and Unmute

This method accepts one argument type. The value of type will be either `video' or 'audio'

    const publication = await twyng.publish(localstream)
publication.mute('video') // If any video stream is inside the stream, it will be muted.
publication.mute('audio') // If the audio stream is inside the stream, its audio will be muted.

Stop

Stop publishing the stream to the conference.

    await publication.stop() // This publishing will be ended and the stream is removed form the remote stream list.

ChangeDevice

Switch the media input device (e.g., switch cameras and microphones). The changeDevice method requires the media stream obtained from createMediaStream as its argument.

    const localstream = await twyng.createMediastream({
video: {
source: 'camera',
deviceId: "some id of particular device"
}
})
await publication.changeDevice(localstream)

addEventListener and removeEventListener:

The publishing instance also produces events. One important event is ended, which occurs when the publishing terminates unexpectedly due to background issues or other reasons.

    publication.addEventListener('ended', () => {
// Handle the publishing ending unexpectedly
});