Skip to content

JSDK-2911 Update MediaDevices example to use track.restart #145

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 9 commits into from
Jul 21, 2020

Conversation

PikaJoyce
Copy link
Contributor

JIRA Ticket

This PR is for updating the Media Devices example to use the latest SDK track.restart method.

Contributing to Twilio

All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.

  • I acknowledge that all my contributions will be made under the project's license.

@PikaJoyce PikaJoyce requested a review from manjeshbhargav July 10, 2020 03:44
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.

@PikaJoyce Your current changes breaks the app if you try and change devices before joining a Room. Please verify your changes locally before requesting a pull request review.

@PikaJoyce PikaJoyce requested a review from manjeshbhargav July 14, 2020 20:04
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.

@PikaJoyce Your most recent changes still don't work if you want to select devices before joining the Room. Please verify that your changes work before asking for a review.

if(someRoom) {
[localAudioTrackPublication] = Array.from(someRoom.localParticipant.audioTracks.values());
}
if (localAudioTrackPublication) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still doesn't work if you want to change and apply devices before joining a Room.

var video = document.querySelector('video#videoinputpreview');
applyVideoInputDeviceSelection(deviceSelections.videoinput.value, video, someRoom);
const video = document.querySelector('video#videoinputpreview');
applyVideoInputDeviceSelection(deviceSelections.videoinput.value, localVideoTrackPublication.track)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still doesn't work if you want to change and apply devices before joining a Room. Also, localVideoTrackPublication.track will raise an error if you haven't joined the Room (publication will be null).

@PikaJoyce
Copy link
Contributor Author

@manjeshbhargav this is how it looks like now! Works great on FF.
mediaDevices

@PikaJoyce PikaJoyce requested a review from manjeshbhargav July 16, 2020 00:10
@@ -30,61 +30,25 @@ function applyAudioOutputDeviceSelection(deviceId, audio) {
/**
* Apply the selected audio input device.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Apply the selected audio input device.
* Apply the selected input device.

@@ -30,61 +30,25 @@ function applyAudioOutputDeviceSelection(deviceId, audio) {
/**
* Apply the selected audio input device.
* @param {string} deviceId
* @param {HTMLAudioElement} audio
* @param {Room} [room] - The Room, if you have already joined one
* @param {LocalTrack} Track - LocalAudioTrack or LocalVideoTrack
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {LocalTrack} Track - LocalAudioTrack or LocalVideoTrack
* @param {LocalTrack} localTrack - LocalAudioTrack or LocalVideoTrack

* @param {HTMLAudioElement} audio
* @param {Room} [room] - The Room, if you have already joined one
* @param {LocalTrack} Track - LocalAudioTrack or LocalVideoTrack
* @param {string} kind - kind of Track
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param {string} kind - kind of Track
* @param {'audio' | 'video'} kind

* @param {HTMLAudioElement} audio
* @param {Room} [room] - The Room, if you have already joined one
* @param {LocalTrack} Track - LocalAudioTrack or LocalVideoTrack
* @param {string} kind - kind of Track
* @returns {Promise<void>}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @returns {Promise<void>}
* @returns {Promise<LocalTrack>} The created or restarted LocalTrack

console.log('localAudioTrack after apply', localAudioTrack);
}
await applyInputDeviceSelection(deviceSelections.audioinput.value, localAudioTrack, 'audio');
console.log('localAudioTrack exists',localAudioTrack);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log('localAudioTrack exists',localAudioTrack);

applyVideoInputDeviceSelection(deviceSelections.videoinput.value, video, someRoom);
const video = document.querySelector('video#videoinputpreview');
localVideoTrack = await applyInputDeviceSelection(deviceSelections.videoinput.value, localVideoTrack, 'video').catch(err => (console.error(err)));
localVideoTrack.attach(video)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
localVideoTrack.attach(video)
localVideoTrack.attach(video);

var video = document.querySelector('video#videoinputpreview');
applyVideoInputDeviceSelection(deviceSelections.videoinput.value, video, someRoom);
const video = document.querySelector('video#videoinputpreview');
localVideoTrack = await applyInputDeviceSelection(deviceSelections.videoinput.value, localVideoTrack, 'video').catch(err => (console.error(err)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
localVideoTrack = await applyInputDeviceSelection(deviceSelections.videoinput.value, localVideoTrack, 'video').catch(err => (console.error(err)));
localVideoTrack = await applyInputDeviceSelection(deviceSelections.videoinput.value, localVideoTrack, 'video');

if (audio.srcObject) {
var canvas = waveformContainer.querySelector('canvas');
waveform.setStream(audio.srcObject);
try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try {

Comment on lines 144 to 146
} catch (error) {
console.log('audioInput apply failed:', error);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (error) {
console.log('audioInput apply failed:', error);
}

@PikaJoyce PikaJoyce requested a review from manjeshbhargav July 20, 2020 18:42
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.

LGTM. Let's go through the example once in our 1:1 before merging. 👍

@@ -122,27 +120,18 @@ function participantDisconnected(participant) {
participantDiv.parentNode.removeChild(participantDiv);
}

// // reads selected audio input, and updates preview and room to use the device.
// Reads selected audio input, and updates preview and room to use the device.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Reads selected audio input, and updates preview and room to use the device.
// reads selected audio input, and updates preview and room to use the device.

@@ -156,15 +145,17 @@ async function applyVideoInputDeviceChange(event) {
}
try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try {

Comment on lines 154 to 156
} catch (error) {
console.log('videoInput apply failed:', error);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} catch (error) {
console.log('videoInput apply failed:', error);
}

@PikaJoyce PikaJoyce merged commit b2da4f0 into master Jul 21, 2020
@PikaJoyce PikaJoyce deleted the JSDK-2911-UpdateMediaDevicesExample branch July 21, 2020 00:39
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