livekit-client
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -10,3 +10,3 @@ import { ParticipantInfo } from '../../proto/model'; | ||
constructor(id: string, name?: string); | ||
addSubscribedMediaTrack(mediaTrack: MediaStreamTrack, sid: Track.SID): RemoteTrackPublication; | ||
addSubscribedMediaTrack(mediaTrack: MediaStreamTrack, sid: Track.SID): RemoteTrackPublication | undefined; | ||
addSubscribedDataTrack(dataChannel: RTCDataChannel, sid: Track.SID, name: string): RemoteTrackPublication; | ||
@@ -13,0 +13,0 @@ get hasMetadata(): boolean; |
@@ -9,10 +9,7 @@ "use strict"; | ||
const model_1 = require("../../proto/model"); | ||
const errors_1 = require("../errors"); | ||
const events_1 = require("../events"); | ||
const RemoteAudioTrack_1 = require("../track/RemoteAudioTrack"); | ||
const RemoteAudioTrackPublication_1 = require("../track/RemoteAudioTrackPublication"); | ||
const RemoteDataTrack_1 = require("../track/RemoteDataTrack"); | ||
const RemoteDataTrackPublication_1 = require("../track/RemoteDataTrackPublication"); | ||
const RemoteVideoTrack_1 = require("../track/RemoteVideoTrack"); | ||
const RemoteVideoTrackPublication_1 = require("../track/RemoteVideoTrackPublication"); | ||
const Track_1 = require("../track/Track"); | ||
@@ -40,35 +37,32 @@ const types_1 = require("../track/types"); | ||
} | ||
if (!this.hasMetadata) { | ||
// try this again later | ||
setTimeout(() => { | ||
this.addSubscribedMediaTrack(mediaTrack, sid); | ||
}, 100); | ||
return; | ||
} | ||
// find the track publication or create one | ||
// it's possible for the media track to arrive before participant info | ||
let publication = this.getTrackPublication(sid); | ||
// it's also possible that the browser didn't honor our original track id | ||
// FireFox would use its own local uuid instead of server track id | ||
if (!publication) { | ||
const info = { | ||
sid: sid, | ||
name: mediaTrack.label, | ||
type: Track_1.Track.kindToProto(track.kind), | ||
muted: false, | ||
}; | ||
switch (track.kind) { | ||
case Track_1.Track.Kind.Audio: | ||
publication = new RemoteAudioTrackPublication_1.RemoteAudioTrackPublication(info, track); | ||
break; | ||
case Track_1.Track.Kind.Video: | ||
publication = new RemoteVideoTrackPublication_1.RemoteVideoTrackPublication(info, track); | ||
break; | ||
default: | ||
throw new errors_1.TrackInvalidError(); | ||
if (!sid.startsWith('TR')) { | ||
// find the first track that matches type | ||
this.tracks.forEach((p) => { | ||
if (!publication && mediaTrack.kind === p.kind.toString()) { | ||
publication = p; | ||
} | ||
}); | ||
} | ||
this.addTrackPublication(publication); | ||
// only send this after metadata is filled in, which indicates the track | ||
// is published AFTER client connected to room | ||
if (this.hasMetadata) { | ||
this.emit(events_1.ParticipantEvent.TrackPublished, publication); | ||
} | ||
} | ||
else { | ||
publication.track = track; | ||
// set track name etc | ||
track.name = publication.trackName; | ||
track.sid = publication.trackSid; | ||
if (!publication) { | ||
loglevel_1.default.error('could not find published track', this.sid, sid); | ||
return; | ||
} | ||
publication.track = track; | ||
// set track name etc | ||
track.name = publication.trackName; | ||
track.sid = publication.trackSid; | ||
// when media track is ended, fire the event | ||
@@ -75,0 +69,0 @@ mediaTrack.onended = (ev) => { |
@@ -80,4 +80,4 @@ "use strict"; | ||
this.engine = new RTCEngine_1.RTCEngine(client, config); | ||
this.engine.on(events_2.EngineEvent.MediaTrackAdded, (mediaTrack) => { | ||
this.onTrackAdded(mediaTrack); | ||
this.engine.on(events_2.EngineEvent.MediaTrackAdded, (mediaTrack, streams) => { | ||
this.onTrackAdded(mediaTrack, streams); | ||
}); | ||
@@ -97,5 +97,12 @@ this.engine.on(events_2.EngineEvent.DataChannelAdded, (dataChannel) => { | ||
} | ||
onTrackAdded(mediaTrack) { | ||
// create remote participant if not created yet | ||
const [participantId, trackId] = utils_1.unpackTrackId(mediaTrack.id); | ||
onTrackAdded(mediaTrack, streams) { | ||
let participantId; | ||
let trackId; | ||
if (streams.length > 0) { | ||
participantId = streams[0].id; | ||
trackId = mediaTrack.id; | ||
} | ||
else { | ||
[participantId, trackId] = utils_1.unpackTrackId(mediaTrack.id); | ||
} | ||
const participant = this.getOrCreateParticipant(participantId); | ||
@@ -102,0 +109,0 @@ participant.addSubscribedMediaTrack(mediaTrack, trackId); |
@@ -1,2 +0,2 @@ | ||
declare const version = "0.3.0"; | ||
declare const version = "0.3.1"; | ||
export { version }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
const version = '0.3.0'; | ||
const version = '0.3.1'; | ||
exports.version = version; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "livekit-client", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "JavaScript/TypeScript client SDK for LiveKit", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4463
286189