Class: Media

Media()

new Media()

WebRTC Media class
Properties:
Name Type Description
application Application The parent application object
parentConversation Conversation the conversation object this media instance belongs to
Properties
Name Type Description
remoteMembers Array.<Member> The remote members
streamIndex number the latest index of the streams, updated in each new peer offer
rtcObjects Array.<object> data related to the rtc connection
Properties
Name Type Attributes Description
rtc_id string the rtc_id
pc PeerConnection the current PeerConnection object
stream Stream the stream of the specific rtc_id
type string <optional>
audio|video|screenshare the type of the stream
streamIndex number the index number of the stream (e.g. use to mute)
Source:
Fires:

Methods

_cleanMediaProperties()

Cleans up the user's media before leaving the conversation
Source:

disable() → {Promise}

Disable media participation in the conversation for this application if RtcStats MOS is enabled, a final report will be available in ConversationClient#rtcstats:report
Source:
Returns:
Type
Promise
Example
function disable() {
  conversation.media.disable()
     .then((response) => {
      }).catch((error) => {
          console.log(error);
      });
}

enable(params) → {Promise.<MediaStream>}

Enable media participation in the conversation for this application (requires WebRTC)
Parameters:
Name Type Description
params object rtc params
Properties
Name Type Attributes Default Description
label string Label is an application defined tag, eg. ‘fullscreen’
audio object <optional>
true audio enablement mode. possible values "both", "send_only", "receive_only", "none", true or false
autoPlayAudio object <optional>
false attach the audio stream automatically to start playing after enable media (default false) *
Source:
Returns:
Type
Promise.<MediaStream>
Example

Enable media in this conversation

function enable() {
  conversation.media.enable()
     .then((stream) => {
                const media = document.createElement("audio");
                const source = document.createElement("source");
                const media_div = document.createElement("div");
                media.appendChild(source);
                media_div.appendChild(media);
                document.insertBefore(media_div);
                // Older browsers may not have srcObject
                if ("srcObject" in media) {
                    media.srcObject = stream;
                } else {
                    // Avoid using this in new browsers, as it is going away.
                    media.src = window.URL.createObjectURL(stream);
                }
                media.onloadedmetadata = (e) => {
                    media.play();
                };

		 }).catch((error) => {
          console.log(error);
      });
}

fetchRecording(url) → {Promise.<Event>}

Download the recoding file
Parameters:
Name Type Description
url string the recording url coming in the recording event
Source:
Returns:
Type
Promise.<Event>

mute(muteopt, audioopt, videoopt, streamIndexopt)

Mute our member
Parameters:
Name Type Attributes Default Description
mute boolean <optional>
false true for mute, false for unmute
audio boolean <optional>
true true for audio stream - relevant only in video conversation
video boolean <optional>
false true for video stream - relevant only in video conversation
streamIndex number <optional>
stream id to set - if it's not set all streams will be muted
Source:
Examples

Mute audio stream in non video conversation

media.mute(true)

Mute audio and video streams in video conversation

media.mute(true, true, true, 0)

Mute only video in video conversation

media.mute(true, false, true, 0)

playStream() → {Promise.<Event>}

Play an audio stream in a conversation
Source:
Returns:
Type
Promise.<Event>

record(params) → {Promise.<Recording>}

Record the audio stream in a conversation
Parameters:
Name Type Description
params object
Properties
Name Type Description
format string = (mp3, wav, ogg)
streamed boolean -
validity_time number -
beep_start boolean -
beep_stop boolean ~
detect_speech boolean -
Source:
Returns:
Type
Promise.<Recording>
Example
conversation.audio.record()

sayText(params) → {Promise.<Event>}

Play a voice text in a conversation
Parameters:
Name Type Description
params object
Properties
Name Type Description
text string the text to say in the conversation
voice_name string -
level number [0] -
queue boolean -
loop boolean -
Source:
Returns:
Type
Promise.<Event>
Example
conversation.media.say({text:'hi'})

sendDTMF(digit) → {Promise.<Event>}

Send DTMF in a conversation
Parameters:
Name Type Description
digit string the DTMF digit(s) to send
Source:
Returns:
Type
Promise.<Event>
Example
conversation.media.sendDTMF('digit')

startRinging() → {Promise.<Event>}

Send start ringing event
Source:
Returns:
Type
Promise.<Event>
Example
Send ringing event
function startRinging() {
  conversation.media.startRinging()
     .then((response) => {
      }).catch((error) => {
          console.log(error);
      });
}

conversation.on('audio:ringing:start', (data) => {
console.log("ringing");
});

stopRinging() → {Promise.<Event>}

Send stop ringing event
Source:
Returns:
Type
Promise.<Event>
Example
Send ringing event
function stopRinging() {
  conversation.media.stopRinging()
     .then(function(response) {
      }).catch(function(error) {
          console.log(error);
      });
}

conversation.on('audio:ringing:stop', function(data)){
console.log("ringing stopped");
}

updateAudioConstraints(constraints, type) → {Promise.<MediaStream>}

Replaces the stream's audio tracks currently being used as the sender's sources with a new one
Parameters:
Name Type Attributes Description
constraints object audio constraints
type string rtc object type
constraints.audio object <optional>
set audio constraints - { deviceId: { exact: microphoneId } }
Source:
Returns:
- Returns the new stream.
Type
Promise.<MediaStream>
Example
<caption>Update the stream currently being used with a new one</caption>

updateSource(constraints, type) → {Promise.<MediaStream>}

Replaces the stream's tracks currently being used as the sender's sources with a new one
Parameters:
Name Type Attributes Default Description
constraints object video and audio constraints
type string video rtc object type
constraints.audio object <optional>
set audio constraints - { deviceId: { exact: microphoneId } }
constraints.video object <optional>
set video constraints - { deviceId: { exact: cameraId } }
Source:
Returns:
- Returns the new stream.
Type
Promise.<MediaStream>
Example
<caption>Update the stream currently being used with a new one</caption>