Skip to content

Commit 85ed986

Browse files
authored
Merge pull request #6157 from decentraland/update/livekit
update livekit-client@2.0.10
2 parents 9aa4fec + 312aa46 commit 85ed986

File tree

5 files changed

+61
-123
lines changed

5 files changed

+61
-123
lines changed

browser-interface/package-lock.json

Lines changed: 43 additions & 108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

browser-interface/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"fp-future": "^1.0.1",
8484
"gifuct-js": "^2.1.2",
8585
"hls.js": "^1.3.4",
86-
"livekit-client": "^1.8.0",
86+
"livekit-client": "^2.0.10",
8787
"mitt": "^3.0.0",
8888
"mz-observable": "^1.0.1",
8989
"redux": "^4.2.1",

browser-interface/packages/shared/comms/adapters/LivekitAdapter.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ export class LivekitAdapter implements MinimumCommunicationsAdapter {
3030
public readonly events = mitt<CommsAdapterEvents>()
3131

3232
private disposed = false
33-
private readonly room: Room
3433
private voiceHandler: VoiceHandler
3534

36-
constructor(private config: LivekitConfig) {
37-
this.room = new Room()
35+
static async init(config: LivekitConfig) {
36+
const room = new Room()
37+
const sid = await room.getSid()
38+
return new LivekitAdapter(config, room, sid)
39+
}
3840

41+
private constructor(private config: LivekitConfig, private readonly room: Room, private sid: string) {
3942
this.voiceHandler = createLiveKitVoiceHandler(this.room, this.config.globalAudioStream)
4043

4144
this.room
@@ -58,13 +61,13 @@ export class LivekitAdapter implements MinimumCommunicationsAdapter {
5861

5962
this.config.logger.log(this.room.name, 'disconnected from room', reason, {
6063
liveKitParticipantSid: this.room.localParticipant.sid,
61-
liveKitRoomSid: this.room.sid
64+
liveKitRoomSid: this.sid
6265
})
6366
trackEvent('disconnection_cause', {
6467
context: 'livekit-adapter',
6568
message: `Got RoomEvent.Disconnected. Reason: ${reason}`,
6669
liveKitParticipantSid: this.room.localParticipant.sid,
67-
liveKitRoomSid: this.room.sid
70+
liveKitRoomSid: this.sid
6871
})
6972
const kicked = reason === DisconnectReason.DUPLICATE_IDENTITY
7073
this.do_disconnect(kicked).catch((err) => {
@@ -108,14 +111,14 @@ export class LivekitAdapter implements MinimumCommunicationsAdapter {
108111
}
109112

110113
try {
111-
await this.room.localParticipant.publishData(data, reliable ? DataPacket_Kind.RELIABLE : DataPacket_Kind.LOSSY)
114+
await this.room.localParticipant.publishData(data, { reliable })
112115
} catch (err: any) {
113116
// NOTE: for tracking purposes only, this is not a "code" error, this is a failed connection or a problem with the livekit instance
114117
trackEvent('error', {
115118
context: 'livekit-adapter',
116119
message: `Error trying to send data. Reason: ${err.message}`,
117120
stack: err.stack,
118-
saga_stack: `room session id: ${this.room.sid}, participant id: ${this.room.localParticipant.sid}, state: ${state}`
121+
saga_stack: `room session id: ${this.sid}, participant id: ${this.room.localParticipant.sid}, state: ${state}`
119122
})
120123
await this.disconnect()
121124
}
@@ -144,12 +147,12 @@ export class LivekitAdapter implements MinimumCommunicationsAdapter {
144147

145148
getActiveVideoStreams(): Map<string, ActiveVideoStreams> {
146149
const result = new Map<string, ActiveVideoStreams>()
147-
const participants = this.room.participants
150+
const participants = this.room.remoteParticipants
148151

149152
for (const [sid, participant] of participants) {
150-
if (participant.videoTracks.size > 0) {
153+
if (participant.videoTrackPublications.size > 0) {
151154
const participantTracks = new Map<string, Track>()
152-
for (const [videoSid, track] of participant.videoTracks) {
155+
for (const [videoSid, track] of participant.videoTrackPublications) {
153156
if (track.videoTrack?.mediaStream) {
154157
participantTracks.set(videoSid, track.videoTrack)
155158
}

browser-interface/packages/shared/comms/adapters/voice/liveKitVoiceHandler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function createLiveKitVoiceHandler(room: Room, globalAudioStream: GlobalA
5454
participantsInfo.set(participant.identity, $)
5555

5656
participant.on(ParticipantEvent.IsSpeakingChanged, (talking: boolean) => {
57-
const audioPublication = participant.getTrack(Track.Source.Microphone)
57+
const audioPublication = participant.getTrackPublication(Track.Source.Microphone)
5858
if (audioPublication && audioPublication.track) {
5959
const audioTrack = audioPublication.track as RemoteAudioTrack
6060
onUserTalkingCallback(participant.identity, audioTrack.isMuted ? false : talking)
@@ -200,7 +200,7 @@ export function createLiveKitVoiceHandler(room: Room, globalAudioStream: GlobalA
200200
)
201201
}
202202

203-
for (const [_, participant] of room.participants) {
203+
for (const [_, participant] of room.remoteParticipants) {
204204
const address = participant.identity
205205
const peer = getPeer(address)
206206
const participantInfo = participantsInfo.get(address)
@@ -209,7 +209,7 @@ export function createLiveKitVoiceHandler(room: Room, globalAudioStream: GlobalA
209209
const profile = getCurrentUserProfile(state)
210210
if (profile) {
211211
const muted = !shouldPlayVoice(state, profile, address)
212-
const audioPublication = participant.getTrack(Track.Source.Microphone)
212+
const audioPublication = participant.getTrackPublication(Track.Source.Microphone)
213213
if (audioPublication && audioPublication.track) {
214214
const audioTrack = audioPublication.track as RemoteAudioTrack
215215
audioTrack.setMuted(muted)

browser-interface/packages/shared/comms/sagas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ async function connectAdapter(connStr: string, identity: ExplorerIdentity): Prom
289289
throw new Error('No access token')
290290
}
291291

292-
const livekitAdapter = new LivekitAdapter({
292+
const livekitAdapter = await LivekitAdapter.init({
293293
logger: commsLogger,
294294
url: theUrl.origin + theUrl.pathname,
295295
token,

0 commit comments

Comments
 (0)