-
Notifications
You must be signed in to change notification settings - Fork 342
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
Conversation
…ersion in package.json as well
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.
@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.
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.
@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.
examples/mediadevices/src/index.js
Outdated
if(someRoom) { | ||
[localAudioTrackPublication] = Array.from(someRoom.localParticipant.audioTracks.values()); | ||
} | ||
if (localAudioTrackPublication) { |
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.
This still doesn't work if you want to change and apply devices before joining a Room.
examples/mediadevices/src/index.js
Outdated
var video = document.querySelector('video#videoinputpreview'); | ||
applyVideoInputDeviceSelection(deviceSelections.videoinput.value, video, someRoom); | ||
const video = document.querySelector('video#videoinputpreview'); | ||
applyVideoInputDeviceSelection(deviceSelections.videoinput.value, localVideoTrackPublication.track) |
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.
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).
@manjeshbhargav this is how it looks like now! Works great on FF. |
examples/mediadevices/src/helpers.js
Outdated
@@ -30,61 +30,25 @@ function applyAudioOutputDeviceSelection(deviceId, audio) { | |||
/** | |||
* Apply the selected audio input 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.
* Apply the selected audio input device. | |
* Apply the selected input device. |
examples/mediadevices/src/helpers.js
Outdated
@@ -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 |
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.
* @param {LocalTrack} Track - LocalAudioTrack or LocalVideoTrack | |
* @param {LocalTrack} localTrack - LocalAudioTrack or LocalVideoTrack |
examples/mediadevices/src/helpers.js
Outdated
* @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 |
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.
* @param {string} kind - kind of Track | |
* @param {'audio' | 'video'} kind |
examples/mediadevices/src/helpers.js
Outdated
* @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>} |
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.
* @returns {Promise<void>} | |
* @returns {Promise<LocalTrack>} The created or restarted LocalTrack |
examples/mediadevices/src/index.js
Outdated
console.log('localAudioTrack after apply', localAudioTrack); | ||
} | ||
await applyInputDeviceSelection(deviceSelections.audioinput.value, localAudioTrack, 'audio'); | ||
console.log('localAudioTrack exists',localAudioTrack); |
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.
console.log('localAudioTrack exists',localAudioTrack); |
examples/mediadevices/src/index.js
Outdated
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) |
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.
localVideoTrack.attach(video) | |
localVideoTrack.attach(video); |
examples/mediadevices/src/index.js
Outdated
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))); |
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.
localVideoTrack = await applyInputDeviceSelection(deviceSelections.videoinput.value, localVideoTrack, 'video').catch(err => (console.error(err))); | |
localVideoTrack = await applyInputDeviceSelection(deviceSelections.videoinput.value, localVideoTrack, 'video'); |
examples/mediadevices/src/index.js
Outdated
if (audio.srcObject) { | ||
var canvas = waveformContainer.querySelector('canvas'); | ||
waveform.setStream(audio.srcObject); | ||
try { |
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.
try { |
examples/mediadevices/src/index.js
Outdated
} catch (error) { | ||
console.log('audioInput apply failed:', error); | ||
} |
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.
} catch (error) { | |
console.log('audioInput apply failed:', error); | |
} |
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.
LGTM. Let's go through the example once in our 1:1 before merging. 👍
examples/mediadevices/src/index.js
Outdated
@@ -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. |
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.
// 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. |
examples/mediadevices/src/index.js
Outdated
@@ -156,15 +145,17 @@ async function applyVideoInputDeviceChange(event) { | |||
} | |||
try { |
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.
try { |
examples/mediadevices/src/index.js
Outdated
} catch (error) { | ||
console.log('videoInput apply failed:', error); | ||
} |
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.
} catch (error) { | |
console.log('videoInput apply failed:', error); | |
} |
JIRA Ticket
This PR is for updating the Media Devices example to use the latest SDK track.restart method.
Contributing to Twilio