livekit-client 1.0.4 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/livekit-client.esm.mjs +218 -106
- package/dist/livekit-client.esm.mjs.map +1 -1
- package/dist/livekit-client.umd.js +1 -1
- package/dist/livekit-client.umd.js.map +1 -1
- package/dist/src/proto/livekit_rtc.d.ts +7 -0
- package/dist/src/proto/livekit_rtc.d.ts.map +1 -1
- package/dist/src/room/Room.d.ts.map +1 -1
- package/dist/src/room/participant/LocalParticipant.d.ts +8 -4
- package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
- package/dist/src/room/track/LocalVideoTrack.d.ts +2 -1
- package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
- package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
- package/dist/src/room/utils.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/proto/livekit_rtc.ts +12 -0
- package/src/room/Room.ts +0 -8
- package/src/room/participant/LocalParticipant.ts +202 -88
- package/src/room/track/LocalVideoTrack.ts +34 -7
- package/src/room/track/RemoteVideoTrack.ts +2 -2
- package/src/room/utils.ts +3 -2
@@ -7049,7 +7049,8 @@ function createBaseAddTrackRequest() {
|
|
7049
7049
|
disableDtx: false,
|
7050
7050
|
source: 0,
|
7051
7051
|
layers: [],
|
7052
|
-
simulcastCodecs: []
|
7052
|
+
simulcastCodecs: [],
|
7053
|
+
sid: ''
|
7053
7054
|
};
|
7054
7055
|
}
|
7055
7056
|
|
@@ -7097,6 +7098,10 @@ const AddTrackRequest = {
|
|
7097
7098
|
SimulcastCodec.encode(v, writer.uint32(82).fork()).ldelim();
|
7098
7099
|
}
|
7099
7100
|
|
7101
|
+
if (message.sid !== '') {
|
7102
|
+
writer.uint32(90).string(message.sid);
|
7103
|
+
}
|
7104
|
+
|
7100
7105
|
return writer;
|
7101
7106
|
},
|
7102
7107
|
|
@@ -7149,6 +7154,10 @@ const AddTrackRequest = {
|
|
7149
7154
|
message.simulcastCodecs.push(SimulcastCodec.decode(reader, reader.uint32()));
|
7150
7155
|
break;
|
7151
7156
|
|
7157
|
+
case 11:
|
7158
|
+
message.sid = reader.string();
|
7159
|
+
break;
|
7160
|
+
|
7152
7161
|
default:
|
7153
7162
|
reader.skipType(tag & 7);
|
7154
7163
|
break;
|
@@ -7169,7 +7178,8 @@ const AddTrackRequest = {
|
|
7169
7178
|
disableDtx: isSet(object.disableDtx) ? Boolean(object.disableDtx) : false,
|
7170
7179
|
source: isSet(object.source) ? trackSourceFromJSON(object.source) : 0,
|
7171
7180
|
layers: Array.isArray(object === null || object === void 0 ? void 0 : object.layers) ? object.layers.map(e => VideoLayer.fromJSON(e)) : [],
|
7172
|
-
simulcastCodecs: Array.isArray(object === null || object === void 0 ? void 0 : object.simulcastCodecs) ? object.simulcastCodecs.map(e => SimulcastCodec.fromJSON(e)) : []
|
7181
|
+
simulcastCodecs: Array.isArray(object === null || object === void 0 ? void 0 : object.simulcastCodecs) ? object.simulcastCodecs.map(e => SimulcastCodec.fromJSON(e)) : [],
|
7182
|
+
sid: isSet(object.sid) ? String(object.sid) : ''
|
7173
7183
|
};
|
7174
7184
|
},
|
7175
7185
|
|
@@ -7196,11 +7206,12 @@ const AddTrackRequest = {
|
|
7196
7206
|
obj.simulcastCodecs = [];
|
7197
7207
|
}
|
7198
7208
|
|
7209
|
+
message.sid !== undefined && (obj.sid = message.sid);
|
7199
7210
|
return obj;
|
7200
7211
|
},
|
7201
7212
|
|
7202
7213
|
fromPartial(object) {
|
7203
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
7214
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
7204
7215
|
|
7205
7216
|
const message = createBaseAddTrackRequest();
|
7206
7217
|
message.cid = (_a = object.cid) !== null && _a !== void 0 ? _a : '';
|
@@ -7213,6 +7224,7 @@ const AddTrackRequest = {
|
|
7213
7224
|
message.source = (_h = object.source) !== null && _h !== void 0 ? _h : 0;
|
7214
7225
|
message.layers = ((_j = object.layers) === null || _j === void 0 ? void 0 : _j.map(e => VideoLayer.fromPartial(e))) || [];
|
7215
7226
|
message.simulcastCodecs = ((_k = object.simulcastCodecs) === null || _k === void 0 ? void 0 : _k.map(e => SimulcastCodec.fromPartial(e))) || [];
|
7227
|
+
message.sid = (_l = object.sid) !== null && _l !== void 0 ? _l : '';
|
7216
7228
|
return message;
|
7217
7229
|
}
|
7218
7230
|
|
@@ -10058,7 +10070,7 @@ function computeBitrate(currentStats, prevStats) {
|
|
10058
10070
|
return (bytesNow - bytesPrev) * 8 * 1000 / (currentStats.timestamp - prevStats.timestamp);
|
10059
10071
|
}
|
10060
10072
|
|
10061
|
-
var version$1 = "1.
|
10073
|
+
var version$1 = "1.1.2";
|
10062
10074
|
|
10063
10075
|
const version = version$1;
|
10064
10076
|
const protocolVersion = 8;
|
@@ -10130,9 +10142,10 @@ function getEmptyVideoStreamTrack() {
|
|
10130
10142
|
var _a;
|
10131
10143
|
|
10132
10144
|
if (!emptyVideoStreamTrack) {
|
10133
|
-
const canvas = document.createElement('canvas');
|
10134
|
-
|
10135
|
-
canvas.
|
10145
|
+
const canvas = document.createElement('canvas'); // the canvas size is set to 16, because electron apps seem to fail with smaller values
|
10146
|
+
|
10147
|
+
canvas.width = 16;
|
10148
|
+
canvas.height = 16;
|
10136
10149
|
(_a = canvas.getContext('2d')) === null || _a === void 0 ? void 0 : _a.fillRect(0, 0, canvas.width, canvas.height); // @ts-ignore
|
10137
10150
|
|
10138
10151
|
const emptyStream = canvas.captureStream();
|
@@ -11514,6 +11527,7 @@ class LocalAudioTrack extends LocalTrack {
|
|
11514
11527
|
|
11515
11528
|
}
|
11516
11529
|
|
11530
|
+
const refreshSubscribedCodecAfterNewCodec = 5000;
|
11517
11531
|
class LocalVideoTrack extends LocalTrack {
|
11518
11532
|
constructor(mediaTrack, constraints) {
|
11519
11533
|
super(mediaTrack, Track.Kind.Video, constraints);
|
@@ -11730,7 +11744,14 @@ class LocalVideoTrack extends LocalTrack {
|
|
11730
11744
|
return;
|
11731
11745
|
}
|
11732
11746
|
|
11733
|
-
simulcastCodecInfo.sender = sender;
|
11747
|
+
simulcastCodecInfo.sender = sender; // browser will reenable disabled codec/layers after new codec has been published,
|
11748
|
+
// so refresh subscribedCodecs after publish a new codec
|
11749
|
+
|
11750
|
+
setTimeout(() => {
|
11751
|
+
if (this.subscribedCodecs) {
|
11752
|
+
this.setPublishingCodecs(this.subscribedCodecs);
|
11753
|
+
}
|
11754
|
+
}, refreshSubscribedCodecAfterNewCodec);
|
11734
11755
|
}
|
11735
11756
|
/**
|
11736
11757
|
* @internal
|
@@ -11739,25 +11760,41 @@ class LocalVideoTrack extends LocalTrack {
|
|
11739
11760
|
|
11740
11761
|
|
11741
11762
|
async setPublishingCodecs(codecs) {
|
11742
|
-
livekitLogger.debug('setting publishing codecs',
|
11763
|
+
livekitLogger.debug('setting publishing codecs', {
|
11764
|
+
codecs,
|
11765
|
+
currentCodec: this.codec
|
11766
|
+
}); // only enable simulcast codec for preference codec setted
|
11767
|
+
|
11768
|
+
if (!this.codec && codecs.length > 0) {
|
11769
|
+
await this.setPublishingLayers(codecs[0].qualities);
|
11770
|
+
return [];
|
11771
|
+
}
|
11772
|
+
|
11773
|
+
this.subscribedCodecs = codecs;
|
11774
|
+
const newCodecs = [];
|
11743
11775
|
|
11744
11776
|
for await (const codec of codecs) {
|
11745
|
-
if (this.codec === codec.codec) {
|
11777
|
+
if (!this.codec || this.codec === codec.codec) {
|
11746
11778
|
await this.setPublishingLayers(codec.qualities);
|
11747
11779
|
} else {
|
11748
11780
|
const simulcastCodecInfo = this.simulcastCodecs.get(codec.codec);
|
11749
11781
|
livekitLogger.debug("try setPublishingCodec for ".concat(codec.codec), simulcastCodecInfo);
|
11750
11782
|
|
11751
11783
|
if (!simulcastCodecInfo || !simulcastCodecInfo.sender) {
|
11752
|
-
|
11753
|
-
|
11754
|
-
|
11755
|
-
|
11784
|
+
for (const q of codec.qualities) {
|
11785
|
+
if (q.enabled) {
|
11786
|
+
newCodecs.push(codec.codec);
|
11787
|
+
break;
|
11788
|
+
}
|
11789
|
+
}
|
11790
|
+
} else if (simulcastCodecInfo.encodings) {
|
11756
11791
|
livekitLogger.debug("try setPublishingLayersForSender ".concat(codec.codec));
|
11757
11792
|
await setPublishingLayersForSender(simulcastCodecInfo.sender, simulcastCodecInfo.encodings, codec.qualities);
|
11758
11793
|
}
|
11759
11794
|
}
|
11760
11795
|
}
|
11796
|
+
|
11797
|
+
return newCodecs;
|
11761
11798
|
}
|
11762
11799
|
/**
|
11763
11800
|
* @internal
|
@@ -12364,7 +12401,7 @@ class HTMLElementInfo {
|
|
12364
12401
|
}
|
12365
12402
|
|
12366
12403
|
height() {
|
12367
|
-
return this.element.
|
12404
|
+
return this.element.clientHeight;
|
12368
12405
|
}
|
12369
12406
|
|
12370
12407
|
observe() {
|
@@ -13605,7 +13642,7 @@ class RemoteParticipant extends Participant {
|
|
13605
13642
|
|
13606
13643
|
}
|
13607
13644
|
|
13608
|
-
const
|
13645
|
+
const compatibleCodec = 'vp8';
|
13609
13646
|
class LocalParticipant extends Participant {
|
13610
13647
|
/** @internal */
|
13611
13648
|
constructor(sid, identity, engine, options) {
|
@@ -13654,8 +13691,8 @@ class LocalParticipant extends Participant {
|
|
13654
13691
|
this.onTrackMuted(track, track.isMuted);
|
13655
13692
|
};
|
13656
13693
|
|
13657
|
-
this.handleSubscribedQualityUpdate = update => {
|
13658
|
-
var _a, _b
|
13694
|
+
this.handleSubscribedQualityUpdate = async update => {
|
13695
|
+
var _a, _b;
|
13659
13696
|
|
13660
13697
|
if (!((_a = this.roomOptions) === null || _a === void 0 ? void 0 : _a.dynacast)) {
|
13661
13698
|
return;
|
@@ -13672,9 +13709,18 @@ class LocalParticipant extends Participant {
|
|
13672
13709
|
}
|
13673
13710
|
|
13674
13711
|
if (update.subscribedCodecs.length > 0) {
|
13675
|
-
(
|
13712
|
+
if (!pub.videoTrack) {
|
13713
|
+
return;
|
13714
|
+
}
|
13715
|
+
|
13716
|
+
const newCodecs = await pub.videoTrack.setPublishingCodecs(update.subscribedCodecs);
|
13717
|
+
|
13718
|
+
for await (const codec of newCodecs) {
|
13719
|
+
livekitLogger.debug("publish ".concat(codec, " for ").concat(pub.videoTrack.sid));
|
13720
|
+
await this.publishAdditionalCodecForTrack(pub.videoTrack, codec, pub.options);
|
13721
|
+
}
|
13676
13722
|
} else if (update.subscribedQualities.length > 0) {
|
13677
|
-
(
|
13723
|
+
(_b = pub.videoTrack) === null || _b === void 0 ? void 0 : _b.setPublishingLayers(update.subscribedQualities);
|
13678
13724
|
}
|
13679
13725
|
};
|
13680
13726
|
|
@@ -13755,8 +13801,8 @@ class LocalParticipant extends Participant {
|
|
13755
13801
|
*/
|
13756
13802
|
|
13757
13803
|
|
13758
|
-
setCameraEnabled(enabled) {
|
13759
|
-
return this.setTrackEnabled(Track.Source.Camera, enabled);
|
13804
|
+
setCameraEnabled(enabled, options) {
|
13805
|
+
return this.setTrackEnabled(Track.Source.Camera, enabled, options);
|
13760
13806
|
}
|
13761
13807
|
/**
|
13762
13808
|
* Enable or disable a participant's microphone track.
|
@@ -13766,8 +13812,8 @@ class LocalParticipant extends Participant {
|
|
13766
13812
|
*/
|
13767
13813
|
|
13768
13814
|
|
13769
|
-
setMicrophoneEnabled(enabled) {
|
13770
|
-
return this.setTrackEnabled(Track.Source.Microphone, enabled);
|
13815
|
+
setMicrophoneEnabled(enabled, options) {
|
13816
|
+
return this.setTrackEnabled(Track.Source.Microphone, enabled, options);
|
13771
13817
|
}
|
13772
13818
|
/**
|
13773
13819
|
* Start or stop sharing a participant's screen
|
@@ -13775,8 +13821,8 @@ class LocalParticipant extends Participant {
|
|
13775
13821
|
*/
|
13776
13822
|
|
13777
13823
|
|
13778
|
-
setScreenShareEnabled(enabled) {
|
13779
|
-
return this.setTrackEnabled(Track.Source.ScreenShare, enabled);
|
13824
|
+
setScreenShareEnabled(enabled, options) {
|
13825
|
+
return this.setTrackEnabled(Track.Source.ScreenShare, enabled, options);
|
13780
13826
|
}
|
13781
13827
|
/** @internal */
|
13782
13828
|
|
@@ -13791,14 +13837,10 @@ class LocalParticipant extends Participant {
|
|
13791
13837
|
|
13792
13838
|
return changed;
|
13793
13839
|
}
|
13794
|
-
/**
|
13795
|
-
* Enable or disable publishing for a track by source. This serves as a simple
|
13796
|
-
* way to manage the common tracks (camera, mic, or screen share).
|
13797
|
-
* Resolves with LocalTrackPublication if successful and void otherwise
|
13798
|
-
*/
|
13799
13840
|
|
13841
|
+
async setTrackEnabled(source, enabled, options) {
|
13842
|
+
var _a, _b;
|
13800
13843
|
|
13801
|
-
async setTrackEnabled(source, enabled) {
|
13802
13844
|
livekitLogger.debug('setTrackEnabled', {
|
13803
13845
|
source,
|
13804
13846
|
enabled
|
@@ -13809,7 +13851,7 @@ class LocalParticipant extends Participant {
|
|
13809
13851
|
if (track) {
|
13810
13852
|
await track.unmute();
|
13811
13853
|
} else {
|
13812
|
-
let
|
13854
|
+
let localTracks;
|
13813
13855
|
|
13814
13856
|
if (this.pendingPublishing.has(source)) {
|
13815
13857
|
livekitLogger.info('skipping duplicate published source', {
|
@@ -13824,28 +13866,35 @@ class LocalParticipant extends Participant {
|
|
13824
13866
|
try {
|
13825
13867
|
switch (source) {
|
13826
13868
|
case Track.Source.Camera:
|
13827
|
-
|
13828
|
-
video: true
|
13869
|
+
localTracks = await this.createTracks({
|
13870
|
+
video: (_a = options) !== null && _a !== void 0 ? _a : true
|
13829
13871
|
});
|
13830
13872
|
break;
|
13831
13873
|
|
13832
13874
|
case Track.Source.Microphone:
|
13833
|
-
|
13834
|
-
audio: true
|
13875
|
+
localTracks = await this.createTracks({
|
13876
|
+
audio: (_b = options) !== null && _b !== void 0 ? _b : true
|
13835
13877
|
});
|
13836
13878
|
break;
|
13837
13879
|
|
13838
13880
|
case Track.Source.ScreenShare:
|
13839
|
-
|
13840
|
-
audio: false
|
13841
|
-
});
|
13881
|
+
localTracks = await this.createScreenTracks(_objectSpread2({}, options));
|
13842
13882
|
break;
|
13843
13883
|
|
13844
13884
|
default:
|
13845
13885
|
throw new TrackInvalidError(source);
|
13846
13886
|
}
|
13847
13887
|
|
13848
|
-
|
13888
|
+
const publishPromises = [];
|
13889
|
+
|
13890
|
+
for (const localTrack of localTracks) {
|
13891
|
+
publishPromises.push(this.publishTrack(localTrack));
|
13892
|
+
}
|
13893
|
+
|
13894
|
+
const publishedTracks = await Promise.all(publishPromises); // for screen share publications including audio, this will only return the screen share publication, not the screen share audio one
|
13895
|
+
// revisit if we want to return an array of tracks instead for v2
|
13896
|
+
|
13897
|
+
[track] = publishedTracks;
|
13849
13898
|
} catch (e) {
|
13850
13899
|
if (e instanceof Error && !(e instanceof TrackInvalidError)) {
|
13851
13900
|
this.emit(ParticipantEvent.MediaDevicesError, e);
|
@@ -13860,6 +13909,11 @@ class LocalParticipant extends Participant {
|
|
13860
13909
|
// screenshare cannot be muted, unpublish instead
|
13861
13910
|
if (source === Track.Source.ScreenShare) {
|
13862
13911
|
track = this.unpublishTrack(track.track);
|
13912
|
+
const screenAudioTrack = this.getTrack(Track.Source.ScreenShareAudio);
|
13913
|
+
|
13914
|
+
if (screenAudioTrack && screenAudioTrack.track) {
|
13915
|
+
this.unpublishTrack(screenAudioTrack.track);
|
13916
|
+
}
|
13863
13917
|
} else {
|
13864
13918
|
await track.mute();
|
13865
13919
|
}
|
@@ -14080,7 +14134,6 @@ class LocalParticipant extends Participant {
|
|
14080
14134
|
|
14081
14135
|
let encodings;
|
14082
14136
|
let simEncodings;
|
14083
|
-
let simulcastTracks;
|
14084
14137
|
|
14085
14138
|
if (track.kind === Track.Kind.Video) {
|
14086
14139
|
// TODO: support react native, which doesn't expose getSettings
|
@@ -14091,26 +14144,30 @@ class LocalParticipant extends Participant {
|
|
14091
14144
|
req.width = width !== null && width !== void 0 ? width : 0;
|
14092
14145
|
req.height = height !== null && height !== void 0 ? height : 0; // for svc codecs, disable simulcast and use vp8 for backup codec
|
14093
14146
|
|
14094
|
-
if (track instanceof LocalVideoTrack
|
14095
|
-
|
14096
|
-
|
14097
|
-
|
14098
|
-
|
14099
|
-
|
14100
|
-
|
14101
|
-
|
14102
|
-
|
14103
|
-
|
14104
|
-
|
14105
|
-
|
14106
|
-
|
14107
|
-
|
14108
|
-
|
14109
|
-
|
14110
|
-
|
14111
|
-
|
14112
|
-
|
14113
|
-
|
14147
|
+
if (track instanceof LocalVideoTrack) {
|
14148
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.videoCodec) === 'vp9' || (opts === null || opts === void 0 ? void 0 : opts.videoCodec) === 'av1') {
|
14149
|
+
// set scalabilityMode to 'L3T3' by default
|
14150
|
+
opts.scalabilityMode = (_g = opts.scalabilityMode) !== null && _g !== void 0 ? _g : 'L3T3'; // add backup codec track
|
14151
|
+
|
14152
|
+
const simOpts = _objectSpread2({}, opts);
|
14153
|
+
|
14154
|
+
simOpts.simulcast = true;
|
14155
|
+
simOpts.scalabilityMode = undefined;
|
14156
|
+
simEncodings = computeVideoEncodings(track.source === Track.Source.ScreenShare, width, height, simOpts);
|
14157
|
+
} // set vp8 codec as backup for any other codecs
|
14158
|
+
|
14159
|
+
|
14160
|
+
if (opts.videoCodec && opts.videoCodec !== 'vp8') {
|
14161
|
+
req.simulcastCodecs = [{
|
14162
|
+
codec: opts.videoCodec,
|
14163
|
+
cid: track.mediaStreamTrack.id,
|
14164
|
+
enableSimulcastLayers: true
|
14165
|
+
}, {
|
14166
|
+
codec: compatibleCodec,
|
14167
|
+
cid: '',
|
14168
|
+
enableSimulcastLayers: true
|
14169
|
+
}];
|
14170
|
+
}
|
14114
14171
|
}
|
14115
14172
|
|
14116
14173
|
encodings = computeVideoEncodings(track.source === Track.Source.ScreenShare, width, height, opts);
|
@@ -14155,24 +14212,6 @@ class LocalParticipant extends Participant {
|
|
14155
14212
|
track.codec = opts.videoCodec;
|
14156
14213
|
}
|
14157
14214
|
|
14158
|
-
const localTrack = track;
|
14159
|
-
|
14160
|
-
if (simulcastTracks) {
|
14161
|
-
for await (const simulcastTrack of simulcastTracks) {
|
14162
|
-
const simTransceiverInit = {
|
14163
|
-
direction: 'sendonly'
|
14164
|
-
};
|
14165
|
-
|
14166
|
-
if (simulcastTrack.encodings) {
|
14167
|
-
simTransceiverInit.sendEncodings = simulcastTrack.encodings;
|
14168
|
-
}
|
14169
|
-
|
14170
|
-
const simTransceiver = await this.engine.publisher.pc.addTransceiver(simulcastTrack.mediaStreamTrack, simTransceiverInit);
|
14171
|
-
this.setPreferredCodec(simTransceiver, localTrack.kind, simulcastTrack.codec);
|
14172
|
-
localTrack.setSimulcastTrackSender(simulcastTrack.codec, simTransceiver.sender);
|
14173
|
-
}
|
14174
|
-
}
|
14175
|
-
|
14176
14215
|
this.engine.negotiate(); // store RTPSender
|
14177
14216
|
|
14178
14217
|
track.sender = transceiver.sender;
|
@@ -14188,6 +14227,86 @@ class LocalParticipant extends Participant {
|
|
14188
14227
|
this.emit(ParticipantEvent.LocalTrackPublished, publication);
|
14189
14228
|
return publication;
|
14190
14229
|
}
|
14230
|
+
/** @internal
|
14231
|
+
* publish additional codec to existing track
|
14232
|
+
*/
|
14233
|
+
|
14234
|
+
|
14235
|
+
async publishAdditionalCodecForTrack(track, videoCodec, options) {
|
14236
|
+
var _a, _b, _c, _d, _e;
|
14237
|
+
|
14238
|
+
const opts = _objectSpread2(_objectSpread2({}, (_a = this.roomOptions) === null || _a === void 0 ? void 0 : _a.publishDefaults), options); // clear scalabilityMode setting for backup codec
|
14239
|
+
|
14240
|
+
|
14241
|
+
opts.scalabilityMode = undefined;
|
14242
|
+
opts.videoCodec = videoCodec; // is it not published? if so skip
|
14243
|
+
|
14244
|
+
let existingPublication;
|
14245
|
+
this.tracks.forEach(publication => {
|
14246
|
+
if (!publication.track) {
|
14247
|
+
return;
|
14248
|
+
}
|
14249
|
+
|
14250
|
+
if (publication.track === track) {
|
14251
|
+
existingPublication = publication;
|
14252
|
+
}
|
14253
|
+
});
|
14254
|
+
|
14255
|
+
if (!existingPublication) {
|
14256
|
+
throw new TrackInvalidError('track is not published');
|
14257
|
+
}
|
14258
|
+
|
14259
|
+
if (!(track instanceof LocalVideoTrack)) {
|
14260
|
+
throw new TrackInvalidError('track is not a video track');
|
14261
|
+
}
|
14262
|
+
|
14263
|
+
const settings = track.mediaStreamTrack.getSettings();
|
14264
|
+
const width = (_b = settings.width) !== null && _b !== void 0 ? _b : (_c = track.dimensions) === null || _c === void 0 ? void 0 : _c.width;
|
14265
|
+
const height = (_d = settings.height) !== null && _d !== void 0 ? _d : (_e = track.dimensions) === null || _e === void 0 ? void 0 : _e.height;
|
14266
|
+
const encodings = computeVideoEncodings(track.source === Track.Source.ScreenShare, width, height, opts);
|
14267
|
+
const simulcastTrack = track.addSimulcastTrack(opts.videoCodec, encodings);
|
14268
|
+
const req = AddTrackRequest.fromPartial({
|
14269
|
+
cid: simulcastTrack.mediaStreamTrack.id,
|
14270
|
+
type: Track.kindToProto(track.kind),
|
14271
|
+
muted: track.isMuted,
|
14272
|
+
source: Track.sourceToProto(track.source),
|
14273
|
+
sid: track.sid,
|
14274
|
+
simulcastCodecs: [{
|
14275
|
+
codec: opts.videoCodec,
|
14276
|
+
cid: simulcastTrack.mediaStreamTrack.id,
|
14277
|
+
enableSimulcastLayers: opts.simulcast
|
14278
|
+
}]
|
14279
|
+
});
|
14280
|
+
req.layers = videoLayersFromEncodings(req.width, req.height, encodings);
|
14281
|
+
|
14282
|
+
if (!this.engine || this.engine.isClosed) {
|
14283
|
+
throw new UnexpectedConnectionState('cannot publish track when not connected');
|
14284
|
+
}
|
14285
|
+
|
14286
|
+
const ti = await this.engine.addTrack(req);
|
14287
|
+
|
14288
|
+
if (!this.engine.publisher) {
|
14289
|
+
throw new UnexpectedConnectionState('publisher is closed');
|
14290
|
+
}
|
14291
|
+
|
14292
|
+
const transceiverInit = {
|
14293
|
+
direction: 'sendonly'
|
14294
|
+
};
|
14295
|
+
|
14296
|
+
if (encodings) {
|
14297
|
+
transceiverInit.sendEncodings = encodings;
|
14298
|
+
} // addTransceiver for react-native is async. web is synchronous, but await won't effect it.
|
14299
|
+
|
14300
|
+
|
14301
|
+
const transceiver = await this.engine.publisher.pc.addTransceiver(simulcastTrack.mediaStreamTrack, transceiverInit);
|
14302
|
+
this.setPreferredCodec(transceiver, track.kind, opts.videoCodec);
|
14303
|
+
track.setSimulcastTrackSender(opts.videoCodec, transceiver.sender);
|
14304
|
+
this.engine.negotiate();
|
14305
|
+
livekitLogger.debug("published ".concat(opts.videoCodec, " for track ").concat(track.sid), {
|
14306
|
+
encodings,
|
14307
|
+
trackInfo: ti
|
14308
|
+
});
|
14309
|
+
}
|
14191
14310
|
|
14192
14311
|
unpublishTrack(track, stopOnUnpublish) {
|
14193
14312
|
var _a, _b; // look through all published tracks to find the right ones
|
@@ -14371,38 +14490,41 @@ class LocalParticipant extends Participant {
|
|
14371
14490
|
const cap = RTCRtpSender.getCapabilities(kind);
|
14372
14491
|
if (!cap) return;
|
14373
14492
|
livekitLogger.debug('get capabilities', cap);
|
14374
|
-
|
14375
|
-
const
|
14493
|
+
const matched = [];
|
14494
|
+
const partialMatched = [];
|
14495
|
+
const unmatched = [];
|
14376
14496
|
cap.codecs.forEach(c => {
|
14377
14497
|
const codec = c.mimeType.toLowerCase();
|
14498
|
+
|
14499
|
+
if (codec === 'audio/opus') {
|
14500
|
+
matched.push(c);
|
14501
|
+
return;
|
14502
|
+
}
|
14503
|
+
|
14378
14504
|
const matchesVideoCodec = codec === "video/".concat(videoCodec);
|
14379
14505
|
|
14380
|
-
if (
|
14381
|
-
|
14506
|
+
if (!matchesVideoCodec) {
|
14507
|
+
unmatched.push(c);
|
14382
14508
|
return;
|
14383
14509
|
} // for h264 codecs that have sdpFmtpLine available, use only if the
|
14384
14510
|
// profile-level-id is 42e01f for cross-browser compatibility
|
14385
14511
|
|
14386
14512
|
|
14387
|
-
if (videoCodec === 'h264'
|
14388
|
-
if (
|
14389
|
-
|
14390
|
-
|
14513
|
+
if (videoCodec === 'h264') {
|
14514
|
+
if (c.sdpFmtpLine && c.sdpFmtpLine.includes('profile-level-id=42e01f')) {
|
14515
|
+
matched.push(c);
|
14516
|
+
} else {
|
14517
|
+
partialMatched.push(c);
|
14391
14518
|
}
|
14392
|
-
}
|
14393
14519
|
|
14394
|
-
if (matchesVideoCodec || codec === 'audio/opus') {
|
14395
|
-
selected = c;
|
14396
14520
|
return;
|
14397
14521
|
}
|
14398
14522
|
|
14399
|
-
|
14523
|
+
matched.push(c);
|
14400
14524
|
});
|
14401
14525
|
|
14402
|
-
if (
|
14403
|
-
|
14404
|
-
codecs.unshift(selected);
|
14405
|
-
transceiver.setCodecPreferences(codecs);
|
14526
|
+
if ('setCodecPreferences' in transceiver) {
|
14527
|
+
transceiver.setCodecPreferences(matched.concat(partialMatched, unmatched));
|
14406
14528
|
}
|
14407
14529
|
}
|
14408
14530
|
/** @internal */
|
@@ -19255,8 +19377,6 @@ class Room extends events.exports.EventEmitter {
|
|
19255
19377
|
constructor(options) {
|
19256
19378
|
var _this;
|
19257
19379
|
|
19258
|
-
var _a, _b;
|
19259
|
-
|
19260
19380
|
super();
|
19261
19381
|
_this = this;
|
19262
19382
|
this.state = ConnectionState.Disconnected;
|
@@ -19681,14 +19801,6 @@ class Room extends events.exports.EventEmitter {
|
|
19681
19801
|
this.participants = new Map();
|
19682
19802
|
this.identityToSid = new Map();
|
19683
19803
|
this.options = options || {};
|
19684
|
-
|
19685
|
-
switch ((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.publishDefaults) === null || _b === void 0 ? void 0 : _b.videoCodec) {
|
19686
|
-
case 'av1':
|
19687
|
-
case 'vp9':
|
19688
|
-
this.options.publishDefaults.simulcast = undefined;
|
19689
|
-
break;
|
19690
|
-
}
|
19691
|
-
|
19692
19804
|
this.options.audioCaptureDefaults = _objectSpread2(_objectSpread2({}, audioDefaults), options === null || options === void 0 ? void 0 : options.audioCaptureDefaults);
|
19693
19805
|
this.options.videoCaptureDefaults = _objectSpread2(_objectSpread2({}, videoDefaults), options === null || options === void 0 ? void 0 : options.videoCaptureDefaults);
|
19694
19806
|
this.options.publishDefaults = _objectSpread2(_objectSpread2({}, publishDefaults), options === null || options === void 0 ? void 0 : options.publishDefaults);
|