Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Commit

Permalink
Use user device parameters for meet tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
alimtunc committed Jun 28, 2023
1 parent c5aed63 commit 7245340
Showing 1 changed file with 56 additions and 9 deletions.
65 changes: 56 additions & 9 deletions core/modules/meet/client/meet-low-level.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,25 @@ const updateTrack = (type, tracks) => {
else if (type === 'video') user?.profile?.shareVideo ? track.unmute() : track.mute()
}

const onLocalTracks = (template, tracks) => {
const replaceLocalTrack = (template, newTrack) => {
const localTracks = template.localTracks.get()

if (localTracks) {
template.localTracks.set(
localTracks.map((track) => {
if (track.getType() === newTrack.getType()) {
// Replace old tracks by the new one
template.room.replaceTrack(track, newTrack)
return newTrack
}
return track
})
)
attachLocalTracks([newTrack])
}
}

const attachLocalTracks = (tracks) => {
tracks.forEach((track) => {
if (track.getType() === 'video') {
let videoNode = document.querySelector('#video-stream-me')
Expand All @@ -295,25 +313,30 @@ const onLocalTracks = (template, tracks) => {
// tracks[i].attach(audioNode)
}
})

template.localTracks.set(tracks)
}

const connect = async (template) => {
console.log('Connection started')

if (!template.connection.get()) {
const options = getOptions(template.roomName)
const user = Meteor.user({ fields: { 'profile.audioRecorder': 1, 'profile.videoRecorder': 1 } })

meetJs.init(options)
meetJs.setLogLevel(meetJs.logLevels.ERROR)

await meetJs.createLocalTracks({ devices: ['audio', 'video'] }).then((tracks) => {
updateTrack('video', tracks)
updateTrack('audio', tracks)

onLocalTracks(template, tracks)
})
await meetJs
.createLocalTracks({
devices: ['audio', 'video'],
cameraDeviceId: user?.profile?.videoRecorder,
micDeviceId: user?.profile?.audioRecorder,
})
.then((tracks) => {
updateTrack('video', tracks)
updateTrack('audio', tracks)
attachLocalTracks(tracks)
template.localTracks.set(tracks)
})

template.connection.set(new meetJs.JitsiConnection(null, null, options))

Expand Down Expand Up @@ -375,6 +398,30 @@ Template.meetLowLevel.onCreated(function () {
if (user) this.avatarURL.set(generateRandomAvatarURLForUser(user))
})

this.autorun(() => {
const user = Meteor.user({ fields: { 'profile.videoRecorder': 1 } })

if (!user) return
meetJs
.createLocalTracks({
devices: ['video'],
cameraDeviceId: user?.profile?.videoRecorder,
})
.then((tracks) => replaceLocalTrack(this, tracks[0]))
})

this.autorun(() => {
const user = Meteor.user({ fields: { 'profile.audioRecorder': 1 } })

if (!user) return
meetJs
.createLocalTracks({
devices: ['audio'],
micDeviceId: user?.profile?.audioRecorder,
})
.then((tracks) => replaceLocalTrack(this, tracks[0]))
})

window.addEventListener(eventTypes.onUsersComeCloser, (e) => {
const { users } = e.detail

Expand Down

0 comments on commit 7245340

Please sign in to comment.