Skip to content

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

Merged
merged 11 commits into from
Jun 10, 2019

Conversation

makarandp0
Copy link
Contributor

@makarandp0 makarandp0 commented Jun 5, 2019

This PR updates media device sample.

With the updates now you can:

  • load the sample and update tracks while connected to room.
  • sample works on mobile safari (on iOS).
  • sample works on mobile chrome (on android).

What does not work:

  • video tracks from chrome do not show up in mobile safari. They do not fire "subscribed" event. (Filed JSDK-2382)

Before merge:

  • remove hardcoded room name
  • fix and remove TODOs from code.
  • revert package.json changes which are for local testing only

on Safari (iOS).
IMG_0356

on Chrome (Desktop)
Screen Shot 2019-06-06 at 3 52 02 PM

@makarandp0 makarandp0 requested a review from manjeshbhargav June 5, 2019 19:18
@makarandp0 makarandp0 self-assigned this Jun 5, 2019
Copy link
Collaborator

@manjeshbhargav manjeshbhargav left a 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.

@@ -14,42 +15,54 @@ function getDevicesOfKind(deviceInfos, kind) {
});
}

function switchLocalTracks(room, newLockTrack) {
Copy link
Collaborator

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);
}

Copy link
Contributor Author

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.

* @param {string} deviceId
* @param {HTMLAudioElement} audio
*/
function applyAudioOutputDeviceSelection(deviceId, audio) {
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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');
}

@makarandp0 makarandp0 requested a review from manjeshbhargav June 6, 2019 23:08
Copy link
Collaborator

@manjeshbhargav manjeshbhargav left a 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.
Copy link
Collaborator

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?

* @returns {void}
*/
function switchLocalTracks(room, track) {
if (room) {
Copy link
Collaborator

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.

}).then(function(localTrack) {
localTrack.attach(audio);
switchLocalTracks(room, localTrack);
Copy link
Collaborator

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);

* @param {string} deviceId
* @param {HTMLAudioElement} audio
*/
function applyAudioOutputDeviceSelection(deviceId, audio) {
Copy link
Collaborator

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');
}

}).then(function(localTrack) {
localTrack.attach(video);
switchLocalTracks(room, localTrack);
Copy link
Collaborator

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);

@makarandp0 makarandp0 merged commit 0a62e24 into master Jun 10, 2019
@makarandp0 makarandp0 deleted the JSDK-2374_media_selection_on_mobile branch June 10, 2019 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants