-
Notifications
You must be signed in to change notification settings - Fork 342
media selection sample that works on mobile devices and connect to room #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start! Can you also share the UI snapshot? Also, can you mention somewhere that it is important in mobile browsers to always create new LocalVideoTracks while switching between cameras? This is because, as soon as you create a new LocalVideoTrack, video stops for the old LocalVideoTrack. So, it is recommended to stop and unpublish the old LocalVideoTrack before publishing the new LocalVideoTrack.
examples/mediadevices/src/helpers.js
Outdated
@@ -14,42 +15,54 @@ function getDevicesOfKind(deviceInfos, kind) { | |||
}); | |||
} | |||
|
|||
function switchLocalTracks(room, newLockTrack) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@makarandp0 I would make this simpler:
/**
* Replace the existing LocalAudioTrack or LocalVideoTrack with
* a new one in the Room.
* @param {Room} room - The Room you have joined
* @param {LocalAudioTrack|LocalVideoTrack} track - The LocalTrack you want to switch to
* @returns {void}
*/
function switchLocalTracks(room, track) {
const localParticipant = room.localParticipant;
const publication = Array(track.kind === 'audio'
? localParticipant.audioTracks.values()
: localParticipant.videoTracks.values())[0];
if (publication) {
publication.track.stop();
publication.unpublish();
}
localParticipant.publishTrack(localTrack);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manjeshbhargav - I think current version reads better, and by using track.kind avoid an extra if check. but good point about track.stop, I will update to stop the track before unpublishing.
examples/mediadevices/src/helpers.js
Outdated
* @param {string} deviceId | ||
* @param {HTMLAudioElement} audio | ||
*/ | ||
function applyAudioOutputDeviceSelection(deviceId, audio) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@makarandp0 I think you should retain this and only apply where setSinkId
is supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved this functionality out of the helper.js because a) this example is already getting big, and more importantly the part of handling output devices does not require/demonstrates any of our SDK apis.
@manjeshbhargav - what do you think about removing output device selection from this sample. This is outside the scope of our API, and does not work on safari.
It also does not render waveform on mobile chrome either, I did not investigate why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@makarandp0 I think we should still retain it here because we have been asked question before as to how to redirect media to specific audio output devices. That is the reason we added this example in the first place. However, I would add an additional check for setSinkId
support:
/**
* Apply the selected audio output device.
* @param {string} deviceId
* @param {HTMLAudioElement} audio
* @returns {Promise<void>}
*/
function applyAudioOutputDeviceSelection(deviceId, audio) {
return typeof audio.setSinkId === 'function'
? audio.setSinkId(deviceId)
: Promise.reject('This browser does not support setting an audio output device');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@makarandp0 Some small change requests, otherwise the example looks good!
<h4>Join room:</h4> | ||
<h6 id="roomName"></h6> | ||
<p>Please join the above Room from another device/browser using <a href="/quickstart" target="_blank">QuickStart App</a> | ||
to see media input device changes taking effect on the receiver side. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@makarandp0 on the receiver side?
examples/mediadevices/src/helpers.js
Outdated
* @returns {void} | ||
*/ | ||
function switchLocalTracks(room, track) { | ||
if (room) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@makarandp0 Nitpick: please make this check for room
being non-null outside this function. Ideally, we should only have the code we want to showcase here.
examples/mediadevices/src/helpers.js
Outdated
}).then(function(localTrack) { | ||
localTrack.attach(audio); | ||
switchLocalTracks(room, localTrack); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@makarandp0 Here, you can do the room
non-null check:
room && switchLocalTracks(room, localTrack);
examples/mediadevices/src/helpers.js
Outdated
* @param {string} deviceId | ||
* @param {HTMLAudioElement} audio | ||
*/ | ||
function applyAudioOutputDeviceSelection(deviceId, audio) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@makarandp0 I think we should still retain it here because we have been asked question before as to how to redirect media to specific audio output devices. That is the reason we added this example in the first place. However, I would add an additional check for setSinkId
support:
/**
* Apply the selected audio output device.
* @param {string} deviceId
* @param {HTMLAudioElement} audio
* @returns {Promise<void>}
*/
function applyAudioOutputDeviceSelection(deviceId, audio) {
return typeof audio.setSinkId === 'function'
? audio.setSinkId(deviceId)
: Promise.reject('This browser does not support setting an audio output device');
}
examples/mediadevices/src/helpers.js
Outdated
}).then(function(localTrack) { | ||
localTrack.attach(video); | ||
switchLocalTracks(room, localTrack); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@makarandp0 Here, you can do the room
non-null check:
room && switchLocalTracks(room, localTrack);
This PR updates media device sample.
With the updates now you can:
What does not work:
Before merge:
on Safari (iOS).

on Chrome (Desktop)
