Class: MediaStream

MediaStream

MediaStream class is used for representing audio/video content which participants can send and receive. Unlike the standard MediaStream it can contain one audio and one video only. There are two types of media streams: local and remote. The distinction is nominal — still there is only one class to represent both of them.

Local media streams are created explicitly with a help of createMediaStream method of MindSDK class. They can contains audio/video from local suppliers only (such as Microphone, Camera and Screen). Local media streams are intended to be streamed on behalf of the local participant only.

Remote media streams contain audio/video of remote participants or the conference. The primary and the secondary media streams of any remote participant can be got with help of getMediaStream or getSecondaryMediaStream methods of Participant class, respectively. The media stream of the conference can be got with getMediaStream method of Conference class.

Any media stream can be played with <video/> or <audio/> HTML elements — just assign the stream to mediaStream property which Mind Web SDK adds to prototypes of HTMLVideoElement and HTMLAudioElement automatically). Keep in mind that <video/> tries to play (tries to consume) audio and video of the media stream, whereas <audio/> tries to play (tries to consumes) audio only of the media stream. This means that if you want to play only audio of a remote media stream, it is better to play it with <audio/> instead of playing it with invisible <video/> because the latter will force underlying WebRTC connection to receive and decode both audio and video.

let myVideo = document.getElementById("myVideo");
let mySecondaryStream = document.getElementById("mySecondaryVideo");
let participantVideo = document.getElementById("participantVideo");

let me = conference.getMe();

// We assume that microphone and camera have been already acquired or will be acquired later
let myStream = MindSDK.createMediaStream(microphone, camera);
me.setMediaStream(myStream);
myVideo.mediaStream = myStream;

// We assume that screen has been already acquired or will be acquired later
let mySecondaryStream = MindSDK.createMediaStream(null, screen);
me.setSecondaryMediaStream(mySecondaryStream);
mySecondaryVideo.mediaStream = mySecondaryStream;

let participant = conference.getParticipantById("<PARTICIPANT_ID>");
if (participant) {
    participantVideo.mediaStream = participant.getMediaStream();
}

...

let conferenceAudio = document.createElement("audio");
conferenceAudio.mediaStream = conference.getMediaStream();
document.body.append(conferenceAudio);