livekit-client 2.18.2 → 2.18.4

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.
Files changed (30) hide show
  1. package/dist/livekit-client.esm.mjs +512 -288
  2. package/dist/livekit-client.esm.mjs.map +1 -1
  3. package/dist/livekit-client.umd.js +1 -1
  4. package/dist/livekit-client.umd.js.map +1 -1
  5. package/dist/src/room/PCTransport.d.ts.map +1 -1
  6. package/dist/src/room/RTCEngine.d.ts +2 -0
  7. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  8. package/dist/src/room/Room.d.ts +2 -0
  9. package/dist/src/room/Room.d.ts.map +1 -1
  10. package/dist/src/room/data-track/incoming/IncomingDataTrackManager.d.ts +4 -0
  11. package/dist/src/room/data-track/incoming/IncomingDataTrackManager.d.ts.map +1 -1
  12. package/dist/src/room/participant/RemoteParticipant.d.ts +4 -3
  13. package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
  14. package/dist/src/room/types.d.ts +1 -1
  15. package/dist/src/room/types.d.ts.map +1 -1
  16. package/dist/ts4.2/room/RTCEngine.d.ts +2 -0
  17. package/dist/ts4.2/room/Room.d.ts +2 -0
  18. package/dist/ts4.2/room/data-track/incoming/IncomingDataTrackManager.d.ts +4 -0
  19. package/dist/ts4.2/room/participant/RemoteParticipant.d.ts +4 -3
  20. package/dist/ts4.2/room/types.d.ts +1 -1
  21. package/package.json +3 -3
  22. package/src/room/PCTransport.ts +4 -3
  23. package/src/room/RTCEngine.ts +19 -0
  24. package/src/room/Room.ts +72 -20
  25. package/src/room/data-track/incoming/IncomingDataTrackManager.test.ts +331 -16
  26. package/src/room/data-track/incoming/IncomingDataTrackManager.ts +92 -41
  27. package/src/room/participant/RemoteParticipant.ts +14 -2
  28. package/src/room/token-source/utils.ts +3 -3
  29. package/src/room/types.ts +2 -1
  30. package/src/utils/deferrable-map.ts +2 -2
@@ -3869,6 +3869,9 @@ const DisconnectReason = /* @__PURE__ */proto3.makeEnum("livekit.DisconnectReaso
3869
3869
  }, {
3870
3870
  no: 15,
3871
3871
  name: "MEDIA_FAILURE"
3872
+ }, {
3873
+ no: 16,
3874
+ name: "AGENT_ERROR"
3872
3875
  }]);
3873
3876
  const ReconnectReason = /* @__PURE__ */proto3.makeEnum("livekit.ReconnectReason", [{
3874
3877
  no: 0,
@@ -3918,6 +3921,13 @@ const AudioTrackFeature = /* @__PURE__ */proto3.makeEnum("livekit.AudioTrackFeat
3918
3921
  no: 6,
3919
3922
  name: "TF_PRECONNECT_BUFFER"
3920
3923
  }]);
3924
+ const PacketTrailerFeature = /* @__PURE__ */proto3.makeEnum("livekit.PacketTrailerFeature", [{
3925
+ no: 0,
3926
+ name: "PTF_USER_TIMESTAMP"
3927
+ }, {
3928
+ no: 1,
3929
+ name: "PTF_FRAME_ID"
3930
+ }]);
3921
3931
  const Room$1 = /* @__PURE__ */proto3.makeMessageType("livekit.Room", () => [{
3922
3932
  no: 1,
3923
3933
  name: "sid",
@@ -4069,6 +4079,12 @@ const ParticipantPermission = /* @__PURE__ */proto3.makeMessageType("livekit.Par
4069
4079
  kind: "scalar",
4070
4080
  T: 8
4071
4081
  /* ScalarType.BOOL */
4082
+ }, {
4083
+ no: 13,
4084
+ name: "can_manage_agent_session",
4085
+ kind: "scalar",
4086
+ T: 8
4087
+ /* ScalarType.BOOL */
4072
4088
  }]);
4073
4089
  const ParticipantInfo = /* @__PURE__ */proto3.makeMessageType("livekit.ParticipantInfo", () => [{
4074
4090
  no: 1,
@@ -4172,6 +4188,12 @@ const ParticipantInfo = /* @__PURE__ */proto3.makeMessageType("livekit.Participa
4172
4188
  kind: "message",
4173
4189
  T: DataTrackInfo$1,
4174
4190
  repeated: true
4191
+ }, {
4192
+ no: 20,
4193
+ name: "client_protocol",
4194
+ kind: "scalar",
4195
+ T: 5
4196
+ /* ScalarType.INT32 */
4175
4197
  }]);
4176
4198
  const ParticipantInfo_State = /* @__PURE__ */proto3.makeEnum("livekit.ParticipantInfo.State", [{
4177
4199
  no: 0,
@@ -4385,6 +4407,12 @@ const TrackInfo = /* @__PURE__ */proto3.makeMessageType("livekit.TrackInfo", ()
4385
4407
  name: "backup_codec_policy",
4386
4408
  kind: "enum",
4387
4409
  T: proto3.getEnumType(BackupCodecPolicy$1)
4410
+ }, {
4411
+ no: 21,
4412
+ name: "packet_trailer_features",
4413
+ kind: "enum",
4414
+ T: proto3.getEnumType(PacketTrailerFeature),
4415
+ repeated: true
4388
4416
  }]);
4389
4417
  const DataTrackInfo$1 = /* @__PURE__ */proto3.makeMessageType("livekit.DataTrackInfo", () => [{
4390
4418
  no: 1,
@@ -4889,6 +4917,12 @@ const RpcRequest = /* @__PURE__ */proto3.makeMessageType("livekit.RpcRequest", (
4889
4917
  kind: "scalar",
4890
4918
  T: 13
4891
4919
  /* ScalarType.UINT32 */
4920
+ }, {
4921
+ no: 6,
4922
+ name: "compressed_payload",
4923
+ kind: "scalar",
4924
+ T: 12
4925
+ /* ScalarType.BYTES */
4892
4926
  }]);
4893
4927
  const RpcAck = /* @__PURE__ */proto3.makeMessageType("livekit.RpcAck", () => [{
4894
4928
  no: 1,
@@ -4915,6 +4949,12 @@ const RpcResponse = /* @__PURE__ */proto3.makeMessageType("livekit.RpcResponse",
4915
4949
  kind: "message",
4916
4950
  T: RpcError$1,
4917
4951
  oneof: "value"
4952
+ }, {
4953
+ no: 4,
4954
+ name: "compressed_payload",
4955
+ kind: "scalar",
4956
+ T: 12,
4957
+ oneof: "value"
4918
4958
  }]);
4919
4959
  const RpcError$1 = /* @__PURE__ */proto3.makeMessageType("livekit.RpcError", () => [{
4920
4960
  no: 1,
@@ -5062,6 +5102,12 @@ const ClientInfo = /* @__PURE__ */proto3.makeMessageType("livekit.ClientInfo", (
5062
5102
  kind: "scalar",
5063
5103
  T: 9
5064
5104
  /* ScalarType.STRING */
5105
+ }, {
5106
+ no: 12,
5107
+ name: "client_protocol",
5108
+ kind: "scalar",
5109
+ T: 5
5110
+ /* ScalarType.INT32 */
5065
5111
  }]);
5066
5112
  const ClientInfo_SDK = /* @__PURE__ */proto3.makeEnum("livekit.ClientInfo.SDK", [{
5067
5113
  no: 0,
@@ -5383,6 +5429,13 @@ const SubscribedAudioCodec = /* @__PURE__ */proto3.makeMessageType("livekit.Subs
5383
5429
  T: 8
5384
5430
  /* ScalarType.BOOL */
5385
5431
  }]);
5432
+ const JobRestartPolicy = /* @__PURE__ */proto3.makeEnum("livekit.JobRestartPolicy", [{
5433
+ no: 0,
5434
+ name: "JRP_ON_FAILURE"
5435
+ }, {
5436
+ no: 1,
5437
+ name: "JRP_NEVER"
5438
+ }]);
5386
5439
  const RoomAgentDispatch = /* @__PURE__ */proto3.makeMessageType("livekit.RoomAgentDispatch", () => [{
5387
5440
  no: 1,
5388
5441
  name: "agent_name",
@@ -5395,6 +5448,11 @@ const RoomAgentDispatch = /* @__PURE__ */proto3.makeMessageType("livekit.RoomAge
5395
5448
  kind: "scalar",
5396
5449
  T: 9
5397
5450
  /* ScalarType.STRING */
5451
+ }, {
5452
+ no: 3,
5453
+ name: "restart_policy",
5454
+ kind: "enum",
5455
+ T: proto3.getEnumType(JobRestartPolicy)
5398
5456
  }]);
5399
5457
  const SignalTarget = /* @__PURE__ */proto3.makeEnum("livekit.SignalTarget", [{
5400
5458
  no: 0,
@@ -5832,6 +5890,12 @@ const AddTrackRequest = /* @__PURE__ */proto3.makeMessageType("livekit.AddTrackR
5832
5890
  kind: "enum",
5833
5891
  T: proto3.getEnumType(AudioTrackFeature),
5834
5892
  repeated: true
5893
+ }, {
5894
+ no: 18,
5895
+ name: "packet_trailer_features",
5896
+ kind: "enum",
5897
+ T: proto3.getEnumType(PacketTrailerFeature),
5898
+ repeated: true
5835
5899
  }]);
5836
5900
  const PublishDataTrackRequest = /* @__PURE__ */proto3.makeMessageType("livekit.PublishDataTrackRequest", () => [{
5837
5901
  no: 1,
@@ -6936,6 +7000,31 @@ const MediaSectionsRequirement = /* @__PURE__ */proto3.makeMessageType("livekit.
6936
7000
  T: 13
6937
7001
  /* ScalarType.UINT32 */
6938
7002
  }]);
7003
+ const EncodingOptionsPreset = /* @__PURE__ */proto3.makeEnum("livekit.EncodingOptionsPreset", [{
7004
+ no: 0,
7005
+ name: "H264_720P_30"
7006
+ }, {
7007
+ no: 1,
7008
+ name: "H264_720P_60"
7009
+ }, {
7010
+ no: 2,
7011
+ name: "H264_1080P_30"
7012
+ }, {
7013
+ no: 3,
7014
+ name: "H264_1080P_60"
7015
+ }, {
7016
+ no: 4,
7017
+ name: "PORTRAIT_H264_720P_30"
7018
+ }, {
7019
+ no: 5,
7020
+ name: "PORTRAIT_H264_720P_60"
7021
+ }, {
7022
+ no: 6,
7023
+ name: "PORTRAIT_H264_1080P_30"
7024
+ }, {
7025
+ no: 7,
7026
+ name: "PORTRAIT_H264_1080P_60"
7027
+ }]);
6939
7028
  const EncodedFileType = /* @__PURE__ */proto3.makeEnum("livekit.EncodedFileType", [{
6940
7029
  no: 0,
6941
7030
  name: "DEFAULT_FILETYPE"
@@ -6949,6 +7038,19 @@ const EncodedFileType = /* @__PURE__ */proto3.makeEnum("livekit.EncodedFileType"
6949
7038
  no: 3,
6950
7039
  name: "MP3"
6951
7040
  }]);
7041
+ const StreamProtocol = /* @__PURE__ */proto3.makeEnum("livekit.StreamProtocol", [{
7042
+ no: 0,
7043
+ name: "DEFAULT_PROTOCOL"
7044
+ }, {
7045
+ no: 1,
7046
+ name: "RTMP"
7047
+ }, {
7048
+ no: 2,
7049
+ name: "SRT"
7050
+ }, {
7051
+ no: 3,
7052
+ name: "WEBSOCKET"
7053
+ }]);
6952
7054
  const SegmentedFileProtocol = /* @__PURE__ */proto3.makeEnum("livekit.SegmentedFileProtocol", [{
6953
7055
  no: 0,
6954
7056
  name: "DEFAULT_SEGMENTED_FILE_PROTOCOL"
@@ -6973,16 +7075,6 @@ const ImageFileSuffix = /* @__PURE__ */proto3.makeEnum("livekit.ImageFileSuffix"
6973
7075
  no: 2,
6974
7076
  name: "IMAGE_SUFFIX_NONE_OVERWRITE"
6975
7077
  }]);
6976
- const StreamProtocol = /* @__PURE__ */proto3.makeEnum("livekit.StreamProtocol", [{
6977
- no: 0,
6978
- name: "DEFAULT_PROTOCOL"
6979
- }, {
6980
- no: 1,
6981
- name: "RTMP"
6982
- }, {
6983
- no: 2,
6984
- name: "SRT"
6985
- }]);
6986
7078
  const AudioMixing = /* @__PURE__ */proto3.makeEnum("livekit.AudioMixing", [{
6987
7079
  no: 0,
6988
7080
  name: "DEFAULT_MIXING"
@@ -6993,168 +7085,88 @@ const AudioMixing = /* @__PURE__ */proto3.makeEnum("livekit.AudioMixing", [{
6993
7085
  no: 2,
6994
7086
  name: "DUAL_CHANNEL_ALTERNATE"
6995
7087
  }]);
6996
- const EncodingOptionsPreset = /* @__PURE__ */proto3.makeEnum("livekit.EncodingOptionsPreset", [{
6997
- no: 0,
6998
- name: "H264_720P_30"
6999
- }, {
7000
- no: 1,
7001
- name: "H264_720P_60"
7002
- }, {
7003
- no: 2,
7004
- name: "H264_1080P_30"
7005
- }, {
7006
- no: 3,
7007
- name: "H264_1080P_60"
7008
- }, {
7009
- no: 4,
7010
- name: "PORTRAIT_H264_720P_30"
7011
- }, {
7012
- no: 5,
7013
- name: "PORTRAIT_H264_720P_60"
7014
- }, {
7015
- no: 6,
7016
- name: "PORTRAIT_H264_1080P_30"
7017
- }, {
7018
- no: 7,
7019
- name: "PORTRAIT_H264_1080P_60"
7020
- }]);
7021
- const RoomCompositeEgressRequest = /* @__PURE__ */proto3.makeMessageType("livekit.RoomCompositeEgressRequest", () => [{
7088
+ const EncodingOptions = /* @__PURE__ */proto3.makeMessageType("livekit.EncodingOptions", () => [{
7022
7089
  no: 1,
7023
- name: "room_name",
7090
+ name: "width",
7024
7091
  kind: "scalar",
7025
- T: 9
7026
- /* ScalarType.STRING */
7092
+ T: 5
7093
+ /* ScalarType.INT32 */
7027
7094
  }, {
7028
7095
  no: 2,
7029
- name: "layout",
7096
+ name: "height",
7030
7097
  kind: "scalar",
7031
- T: 9
7032
- /* ScalarType.STRING */
7098
+ T: 5
7099
+ /* ScalarType.INT32 */
7033
7100
  }, {
7034
7101
  no: 3,
7035
- name: "audio_only",
7102
+ name: "depth",
7036
7103
  kind: "scalar",
7037
- T: 8
7038
- /* ScalarType.BOOL */
7039
- }, {
7040
- no: 15,
7041
- name: "audio_mixing",
7042
- kind: "enum",
7043
- T: proto3.getEnumType(AudioMixing)
7104
+ T: 5
7105
+ /* ScalarType.INT32 */
7044
7106
  }, {
7045
7107
  no: 4,
7046
- name: "video_only",
7108
+ name: "framerate",
7047
7109
  kind: "scalar",
7048
- T: 8
7049
- /* ScalarType.BOOL */
7110
+ T: 5
7111
+ /* ScalarType.INT32 */
7050
7112
  }, {
7051
7113
  no: 5,
7052
- name: "custom_base_url",
7053
- kind: "scalar",
7054
- T: 9
7055
- /* ScalarType.STRING */
7114
+ name: "audio_codec",
7115
+ kind: "enum",
7116
+ T: proto3.getEnumType(AudioCodec)
7056
7117
  }, {
7057
7118
  no: 6,
7058
- name: "file",
7059
- kind: "message",
7060
- T: EncodedFileOutput,
7061
- oneof: "output"
7119
+ name: "audio_bitrate",
7120
+ kind: "scalar",
7121
+ T: 5
7122
+ /* ScalarType.INT32 */
7062
7123
  }, {
7063
7124
  no: 7,
7064
- name: "stream",
7065
- kind: "message",
7066
- T: StreamOutput,
7067
- oneof: "output"
7068
- }, {
7069
- no: 10,
7070
- name: "segments",
7071
- kind: "message",
7072
- T: SegmentedFileOutput,
7073
- oneof: "output"
7125
+ name: "audio_frequency",
7126
+ kind: "scalar",
7127
+ T: 5
7128
+ /* ScalarType.INT32 */
7074
7129
  }, {
7075
7130
  no: 8,
7076
- name: "preset",
7131
+ name: "video_codec",
7077
7132
  kind: "enum",
7078
- T: proto3.getEnumType(EncodingOptionsPreset),
7079
- oneof: "options"
7133
+ T: proto3.getEnumType(VideoCodec)
7080
7134
  }, {
7081
7135
  no: 9,
7082
- name: "advanced",
7083
- kind: "message",
7084
- T: EncodingOptions,
7085
- oneof: "options"
7136
+ name: "video_bitrate",
7137
+ kind: "scalar",
7138
+ T: 5
7139
+ /* ScalarType.INT32 */
7140
+ }, {
7141
+ no: 10,
7142
+ name: "key_frame_interval",
7143
+ kind: "scalar",
7144
+ T: 1
7145
+ /* ScalarType.DOUBLE */
7086
7146
  }, {
7087
7147
  no: 11,
7088
- name: "file_outputs",
7089
- kind: "message",
7090
- T: EncodedFileOutput,
7091
- repeated: true
7148
+ name: "audio_quality",
7149
+ kind: "scalar",
7150
+ T: 5
7151
+ /* ScalarType.INT32 */
7092
7152
  }, {
7093
7153
  no: 12,
7094
- name: "stream_outputs",
7095
- kind: "message",
7096
- T: StreamOutput,
7097
- repeated: true
7098
- }, {
7099
- no: 13,
7100
- name: "segment_outputs",
7101
- kind: "message",
7102
- T: SegmentedFileOutput,
7103
- repeated: true
7104
- }, {
7105
- no: 14,
7106
- name: "image_outputs",
7107
- kind: "message",
7108
- T: ImageOutput,
7109
- repeated: true
7110
- }, {
7111
- no: 16,
7112
- name: "webhooks",
7113
- kind: "message",
7114
- T: WebhookConfig,
7115
- repeated: true
7154
+ name: "video_quality",
7155
+ kind: "scalar",
7156
+ T: 5
7157
+ /* ScalarType.INT32 */
7116
7158
  }]);
7117
- const EncodedFileOutput = /* @__PURE__ */proto3.makeMessageType("livekit.EncodedFileOutput", () => [{
7159
+ const StreamOutput = /* @__PURE__ */proto3.makeMessageType("livekit.StreamOutput", () => [{
7118
7160
  no: 1,
7119
- name: "file_type",
7161
+ name: "protocol",
7120
7162
  kind: "enum",
7121
- T: proto3.getEnumType(EncodedFileType)
7163
+ T: proto3.getEnumType(StreamProtocol)
7122
7164
  }, {
7123
7165
  no: 2,
7124
- name: "filepath",
7125
- kind: "scalar",
7126
- T: 9
7127
- /* ScalarType.STRING */
7128
- }, {
7129
- no: 6,
7130
- name: "disable_manifest",
7166
+ name: "urls",
7131
7167
  kind: "scalar",
7132
- T: 8
7133
- /* ScalarType.BOOL */
7134
- }, {
7135
- no: 3,
7136
- name: "s3",
7137
- kind: "message",
7138
- T: S3Upload,
7139
- oneof: "output"
7140
- }, {
7141
- no: 4,
7142
- name: "gcp",
7143
- kind: "message",
7144
- T: GCPUpload,
7145
- oneof: "output"
7146
- }, {
7147
- no: 5,
7148
- name: "azure",
7149
- kind: "message",
7150
- T: AzureBlobUpload,
7151
- oneof: "output"
7152
- }, {
7153
- no: 7,
7154
- name: "aliOSS",
7155
- kind: "message",
7156
- T: AliOSSUpload,
7157
- oneof: "output"
7168
+ T: 9,
7169
+ repeated: true
7158
7170
  }]);
7159
7171
  const SegmentedFileOutput = /* @__PURE__ */proto3.makeMessageType("livekit.SegmentedFileOutput", () => [{
7160
7172
  no: 1,
@@ -7455,146 +7467,201 @@ const ProxyConfig = /* @__PURE__ */proto3.makeMessageType("livekit.ProxyConfig",
7455
7467
  T: 9
7456
7468
  /* ScalarType.STRING */
7457
7469
  }]);
7458
- const StreamOutput = /* @__PURE__ */proto3.makeMessageType("livekit.StreamOutput", () => [{
7470
+ const AutoParticipantEgress = /* @__PURE__ */proto3.makeMessageType("livekit.AutoParticipantEgress", () => [{
7459
7471
  no: 1,
7460
- name: "protocol",
7472
+ name: "preset",
7461
7473
  kind: "enum",
7462
- T: proto3.getEnumType(StreamProtocol)
7474
+ T: proto3.getEnumType(EncodingOptionsPreset),
7475
+ oneof: "options"
7476
+ }, {
7477
+ no: 2,
7478
+ name: "advanced",
7479
+ kind: "message",
7480
+ T: EncodingOptions,
7481
+ oneof: "options"
7482
+ }, {
7483
+ no: 3,
7484
+ name: "file_outputs",
7485
+ kind: "message",
7486
+ T: EncodedFileOutput,
7487
+ repeated: true
7488
+ }, {
7489
+ no: 4,
7490
+ name: "segment_outputs",
7491
+ kind: "message",
7492
+ T: SegmentedFileOutput,
7493
+ repeated: true
7494
+ }]);
7495
+ const AutoTrackEgress = /* @__PURE__ */proto3.makeMessageType("livekit.AutoTrackEgress", () => [{
7496
+ no: 1,
7497
+ name: "filepath",
7498
+ kind: "scalar",
7499
+ T: 9
7500
+ /* ScalarType.STRING */
7501
+ }, {
7502
+ no: 5,
7503
+ name: "disable_manifest",
7504
+ kind: "scalar",
7505
+ T: 8
7506
+ /* ScalarType.BOOL */
7507
+ }, {
7508
+ no: 2,
7509
+ name: "s3",
7510
+ kind: "message",
7511
+ T: S3Upload,
7512
+ oneof: "output"
7513
+ }, {
7514
+ no: 3,
7515
+ name: "gcp",
7516
+ kind: "message",
7517
+ T: GCPUpload,
7518
+ oneof: "output"
7519
+ }, {
7520
+ no: 4,
7521
+ name: "azure",
7522
+ kind: "message",
7523
+ T: AzureBlobUpload,
7524
+ oneof: "output"
7463
7525
  }, {
7464
- no: 2,
7465
- name: "urls",
7466
- kind: "scalar",
7467
- T: 9,
7468
- repeated: true
7526
+ no: 6,
7527
+ name: "aliOSS",
7528
+ kind: "message",
7529
+ T: AliOSSUpload,
7530
+ oneof: "output"
7469
7531
  }]);
7470
- const EncodingOptions = /* @__PURE__ */proto3.makeMessageType("livekit.EncodingOptions", () => [{
7532
+ const RoomCompositeEgressRequest = /* @__PURE__ */proto3.makeMessageType("livekit.RoomCompositeEgressRequest", () => [{
7471
7533
  no: 1,
7472
- name: "width",
7534
+ name: "room_name",
7473
7535
  kind: "scalar",
7474
- T: 5
7475
- /* ScalarType.INT32 */
7536
+ T: 9
7537
+ /* ScalarType.STRING */
7476
7538
  }, {
7477
7539
  no: 2,
7478
- name: "height",
7540
+ name: "layout",
7479
7541
  kind: "scalar",
7480
- T: 5
7481
- /* ScalarType.INT32 */
7542
+ T: 9
7543
+ /* ScalarType.STRING */
7482
7544
  }, {
7483
7545
  no: 3,
7484
- name: "depth",
7546
+ name: "audio_only",
7485
7547
  kind: "scalar",
7486
- T: 5
7487
- /* ScalarType.INT32 */
7548
+ T: 8
7549
+ /* ScalarType.BOOL */
7550
+ }, {
7551
+ no: 15,
7552
+ name: "audio_mixing",
7553
+ kind: "enum",
7554
+ T: proto3.getEnumType(AudioMixing)
7488
7555
  }, {
7489
7556
  no: 4,
7490
- name: "framerate",
7557
+ name: "video_only",
7491
7558
  kind: "scalar",
7492
- T: 5
7493
- /* ScalarType.INT32 */
7559
+ T: 8
7560
+ /* ScalarType.BOOL */
7494
7561
  }, {
7495
7562
  no: 5,
7496
- name: "audio_codec",
7497
- kind: "enum",
7498
- T: proto3.getEnumType(AudioCodec)
7499
- }, {
7500
- no: 6,
7501
- name: "audio_bitrate",
7563
+ name: "custom_base_url",
7502
7564
  kind: "scalar",
7503
- T: 5
7504
- /* ScalarType.INT32 */
7565
+ T: 9
7566
+ /* ScalarType.STRING */
7505
7567
  }, {
7506
- no: 11,
7507
- name: "audio_quality",
7508
- kind: "scalar",
7509
- T: 5
7510
- /* ScalarType.INT32 */
7568
+ no: 6,
7569
+ name: "file",
7570
+ kind: "message",
7571
+ T: EncodedFileOutput,
7572
+ oneof: "output"
7511
7573
  }, {
7512
7574
  no: 7,
7513
- name: "audio_frequency",
7514
- kind: "scalar",
7515
- T: 5
7516
- /* ScalarType.INT32 */
7517
- }, {
7518
- no: 8,
7519
- name: "video_codec",
7520
- kind: "enum",
7521
- T: proto3.getEnumType(VideoCodec)
7522
- }, {
7523
- no: 9,
7524
- name: "video_bitrate",
7525
- kind: "scalar",
7526
- T: 5
7527
- /* ScalarType.INT32 */
7528
- }, {
7529
- no: 12,
7530
- name: "video_quality",
7531
- kind: "scalar",
7532
- T: 5
7533
- /* ScalarType.INT32 */
7575
+ name: "stream",
7576
+ kind: "message",
7577
+ T: StreamOutput,
7578
+ oneof: "output"
7534
7579
  }, {
7535
7580
  no: 10,
7536
- name: "key_frame_interval",
7537
- kind: "scalar",
7538
- T: 1
7539
- /* ScalarType.DOUBLE */
7540
- }]);
7541
- const AutoParticipantEgress = /* @__PURE__ */proto3.makeMessageType("livekit.AutoParticipantEgress", () => [{
7542
- no: 1,
7581
+ name: "segments",
7582
+ kind: "message",
7583
+ T: SegmentedFileOutput,
7584
+ oneof: "output"
7585
+ }, {
7586
+ no: 8,
7543
7587
  name: "preset",
7544
7588
  kind: "enum",
7545
7589
  T: proto3.getEnumType(EncodingOptionsPreset),
7546
7590
  oneof: "options"
7547
7591
  }, {
7548
- no: 2,
7592
+ no: 9,
7549
7593
  name: "advanced",
7550
7594
  kind: "message",
7551
7595
  T: EncodingOptions,
7552
7596
  oneof: "options"
7553
7597
  }, {
7554
- no: 3,
7598
+ no: 11,
7555
7599
  name: "file_outputs",
7556
7600
  kind: "message",
7557
7601
  T: EncodedFileOutput,
7558
7602
  repeated: true
7559
7603
  }, {
7560
- no: 4,
7604
+ no: 12,
7605
+ name: "stream_outputs",
7606
+ kind: "message",
7607
+ T: StreamOutput,
7608
+ repeated: true
7609
+ }, {
7610
+ no: 13,
7561
7611
  name: "segment_outputs",
7562
7612
  kind: "message",
7563
7613
  T: SegmentedFileOutput,
7564
7614
  repeated: true
7615
+ }, {
7616
+ no: 14,
7617
+ name: "image_outputs",
7618
+ kind: "message",
7619
+ T: ImageOutput,
7620
+ repeated: true
7621
+ }, {
7622
+ no: 16,
7623
+ name: "webhooks",
7624
+ kind: "message",
7625
+ T: WebhookConfig,
7626
+ repeated: true
7565
7627
  }]);
7566
- const AutoTrackEgress = /* @__PURE__ */proto3.makeMessageType("livekit.AutoTrackEgress", () => [{
7628
+ const EncodedFileOutput = /* @__PURE__ */proto3.makeMessageType("livekit.EncodedFileOutput", () => [{
7567
7629
  no: 1,
7630
+ name: "file_type",
7631
+ kind: "enum",
7632
+ T: proto3.getEnumType(EncodedFileType)
7633
+ }, {
7634
+ no: 2,
7568
7635
  name: "filepath",
7569
7636
  kind: "scalar",
7570
7637
  T: 9
7571
7638
  /* ScalarType.STRING */
7572
7639
  }, {
7573
- no: 5,
7640
+ no: 6,
7574
7641
  name: "disable_manifest",
7575
7642
  kind: "scalar",
7576
7643
  T: 8
7577
7644
  /* ScalarType.BOOL */
7578
7645
  }, {
7579
- no: 2,
7646
+ no: 3,
7580
7647
  name: "s3",
7581
7648
  kind: "message",
7582
7649
  T: S3Upload,
7583
7650
  oneof: "output"
7584
7651
  }, {
7585
- no: 3,
7652
+ no: 4,
7586
7653
  name: "gcp",
7587
7654
  kind: "message",
7588
7655
  T: GCPUpload,
7589
7656
  oneof: "output"
7590
7657
  }, {
7591
- no: 4,
7658
+ no: 5,
7592
7659
  name: "azure",
7593
7660
  kind: "message",
7594
7661
  T: AzureBlobUpload,
7595
7662
  oneof: "output"
7596
7663
  }, {
7597
- no: 6,
7664
+ no: 7,
7598
7665
  name: "aliOSS",
7599
7666
  kind: "message",
7600
7667
  T: AliOSSUpload,
@@ -7675,6 +7742,16 @@ const RoomConfiguration = /* @__PURE__ */proto3.makeMessageType("livekit.RoomCon
7675
7742
  kind: "message",
7676
7743
  T: RoomAgentDispatch,
7677
7744
  repeated: true
7745
+ }, {
7746
+ no: 12,
7747
+ name: "tags",
7748
+ kind: "map",
7749
+ K: 9,
7750
+ V: {
7751
+ kind: "scalar",
7752
+ T: 9
7753
+ /* ScalarType.STRING */
7754
+ }
7678
7755
  }]);
7679
7756
  const TokenSourceRequest = /* @__PURE__ */proto3.makeMessageType("livekit.TokenSourceRequest", () => [{
7680
7757
  no: 1,
@@ -8627,6 +8704,11 @@ function wrapPeerConnectionEvent(window, eventNameToWrap, wrapper) {
8627
8704
  if (!window.RTCPeerConnection) {
8628
8705
  return;
8629
8706
  }
8707
+ const addEventListener = Object.getOwnPropertyDescriptor(EventTarget.prototype, 'addEventListener');
8708
+ if (!addEventListener.writable) {
8709
+ log$4('Unable to polyfill events');
8710
+ return;
8711
+ }
8630
8712
  const proto = window.RTCPeerConnection.prototype;
8631
8713
  const nativeAddEventListener = proto.addEventListener;
8632
8714
  proto.addEventListener = function (nativeEventName, cb) {
@@ -8769,7 +8851,7 @@ function detectBrowser(window) {
8769
8851
  // Chrome 74 removed webkitGetUserMedia on http as well so we need the
8770
8852
  // more complicated fallback to webkitRTCPeerConnection.
8771
8853
  result.browser = 'chrome';
8772
- result.version = parseInt(extractVersion(navigator.userAgent, /Chrom(e|ium)\/(\d+)\./, 2));
8854
+ result.version = parseInt(extractVersion(navigator.userAgent, /Chrom(e|ium)\/(\d+)\./, 2)) || null;
8773
8855
  } else if (window.RTCPeerConnection && navigator.userAgent.match(/AppleWebKit\/(\d+)\./)) {
8774
8856
  // Safari.
8775
8857
  result.browser = 'safari';
@@ -9043,7 +9125,11 @@ function shimGetUserMedia$2(window, browserDetails) {
9043
9125
  function shimMediaStream(window) {
9044
9126
  window.MediaStream = window.MediaStream || window.webkitMediaStream;
9045
9127
  }
9046
- function shimOnTrack$1(window) {
9128
+ function shimOnTrack$1(window, browserDetails) {
9129
+ if (browserDetails.version > 102) {
9130
+ // Unified plan is supported so no need to do anything.
9131
+ return;
9132
+ }
9047
9133
  if (typeof window === 'object' && window.RTCPeerConnection && !('ontrack' in window.RTCPeerConnection.prototype)) {
9048
9134
  Object.defineProperty(window.RTCPeerConnection.prototype, 'ontrack', {
9049
9135
  get() {
@@ -9206,7 +9292,10 @@ function shimGetSendersWithDtmf(window) {
9206
9292
  });
9207
9293
  }
9208
9294
  }
9209
- function shimSenderReceiverGetStats(window) {
9295
+ function shimSenderReceiverGetStats(window, browserDetails) {
9296
+ if (browserDetails.version >= 67) {
9297
+ return;
9298
+ }
9210
9299
  if (!(typeof window === 'object' && window.RTCPeerConnection && window.RTCRtpSender && window.RTCRtpReceiver)) {
9211
9300
  return;
9212
9301
  }
@@ -9573,6 +9662,10 @@ function shimPeerConnection$1(window, browserDetails) {
9573
9662
 
9574
9663
  // Attempt to fix ONN in plan-b mode.
9575
9664
  function fixNegotiationNeeded(window, browserDetails) {
9665
+ if (browserDetails.version > 102) {
9666
+ // Plan-B is no longer supported.
9667
+ return;
9668
+ }
9576
9669
  wrapPeerConnectionEvent(window, 'negotiationneeded', e => {
9577
9670
  const pc = e.target;
9578
9671
  if (browserDetails.version < 72 || pc.getConfiguration && pc.getConfiguration().sdpSemantics === 'plan-b') {
@@ -9708,6 +9801,15 @@ function shimPeerConnection(window, browserDetails) {
9708
9801
  window.RTCPeerConnection.prototype[method] = methodObj[method];
9709
9802
  });
9710
9803
  }
9804
+ }
9805
+ function shimGetStats(window, browserDetails) {
9806
+ if (typeof window !== 'object' || !(window.RTCPeerConnection || window.mozRTCPeerConnection)) {
9807
+ return; // probably media.peerconnection.enabled=false in about:config
9808
+ }
9809
+ if (browserDetails.version >= 151) {
9810
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1056433
9811
+ return;
9812
+ }
9711
9813
  const modernStatsTypes = {
9712
9814
  inboundrtp: 'inbound-rtp',
9713
9815
  outboundrtp: 'outbound-rtp',
@@ -9718,6 +9820,10 @@ function shimPeerConnection(window, browserDetails) {
9718
9820
  const nativeGetStats = window.RTCPeerConnection.prototype.getStats;
9719
9821
  window.RTCPeerConnection.prototype.getStats = function getStats() {
9720
9822
  const [selector, onSucc, onErr] = arguments;
9823
+ if (this.signalingState === 'closed') {
9824
+ // No longer required in FF151+
9825
+ return Promise.resolve(new Map());
9826
+ }
9721
9827
  return nativeGetStats.apply(this, [selector || null]).then(stats => {
9722
9828
  if (browserDetails.version < 53 && !onSucc) {
9723
9829
  // Shim only promise getStats with spec-hyphens in type names
@@ -9932,7 +10038,7 @@ function shimCreateAnswer(window) {
9932
10038
  }
9933
10039
  return origCreateAnswer.apply(this, arguments);
9934
10040
  };
9935
- }var firefoxShim=/*#__PURE__*/Object.freeze({__proto__:null,shimAddTransceiver:shimAddTransceiver,shimCreateAnswer:shimCreateAnswer,shimCreateOffer:shimCreateOffer,shimGetDisplayMedia:shimGetDisplayMedia,shimGetParameters:shimGetParameters,shimGetUserMedia:shimGetUserMedia$1,shimOnTrack:shimOnTrack,shimPeerConnection:shimPeerConnection,shimRTCDataChannel:shimRTCDataChannel,shimReceiverGetStats:shimReceiverGetStats,shimRemoveStream:shimRemoveStream,shimSenderGetStats:shimSenderGetStats});/*
10041
+ }var firefoxShim=/*#__PURE__*/Object.freeze({__proto__:null,shimAddTransceiver:shimAddTransceiver,shimCreateAnswer:shimCreateAnswer,shimCreateOffer:shimCreateOffer,shimGetDisplayMedia:shimGetDisplayMedia,shimGetParameters:shimGetParameters,shimGetStats:shimGetStats,shimGetUserMedia:shimGetUserMedia$1,shimOnTrack:shimOnTrack,shimPeerConnection:shimPeerConnection,shimRTCDataChannel:shimRTCDataChannel,shimReceiverGetStats:shimReceiverGetStats,shimRemoveStream:shimRemoveStream,shimSenderGetStats:shimSenderGetStats});/*
9936
10042
  * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
9937
10043
  *
9938
10044
  * Use of this source code is governed by a BSD-style license
@@ -10367,7 +10473,7 @@ function requireSdp() {
10367
10473
  const type = candidate.type;
10368
10474
  sdp.push('typ');
10369
10475
  sdp.push(type);
10370
- if (type !== 'host' && candidate.relatedAddress && candidate.relatedPort) {
10476
+ if (type !== 'host' && candidate.relatedAddress && candidate.relatedPort !== undefined) {
10371
10477
  sdp.push('raddr');
10372
10478
  sdp.push(candidate.relatedAddress);
10373
10479
  sdp.push('rport');
@@ -10440,6 +10546,8 @@ function requireSdp() {
10440
10546
  // Parses a fmtp line, returns dictionary. Sample input:
10441
10547
  // a=fmtp:96 vbr=on;cng=on
10442
10548
  // Also deals with vbr=on; cng=on
10549
+ // Non-key-value such as telephone-events `0-15` get parsed as
10550
+ // {`0-15`:undefined}
10443
10551
  SDPUtils.parseFmtp = function (line) {
10444
10552
  const parsed = {};
10445
10553
  let kv;
@@ -11213,15 +11321,21 @@ function shimMaxMessageSize(window, browserDetails) {
11213
11321
  return origSetRemoteDescription.apply(this, arguments);
11214
11322
  };
11215
11323
  }
11216
- function shimSendThrowTypeError(window) {
11324
+ function shimSendThrowTypeError(window, browserDetails) {
11217
11325
  if (!(window.RTCPeerConnection && 'createDataChannel' in window.RTCPeerConnection.prototype)) {
11218
11326
  return;
11219
11327
  }
11328
+ if (browserDetails.browser === 'chrome' && browserDetails.version > 149) {
11329
+ // Fixed by https://issues.chromium.org/issues/490588131
11330
+ return;
11331
+ }
11220
11332
 
11221
11333
  // Note: Although Firefox >= 57 has a native implementation, the maximum
11222
11334
  // message size can be reset for all data channels at a later stage.
11223
11335
  // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1426831
11224
-
11336
+ if (browserDetails.browser === 'firefox' && browserDetails.version > 60) {
11337
+ return;
11338
+ }
11225
11339
  function wrapDcSend(dc, pc) {
11226
11340
  const origDataChannelSend = dc.send;
11227
11341
  dc.send = function send() {
@@ -11459,16 +11573,16 @@ function adapterFactory() {
11459
11573
  shimGetUserMedia$2(window, browserDetails);
11460
11574
  shimMediaStream(window);
11461
11575
  shimPeerConnection$1(window, browserDetails);
11462
- shimOnTrack$1(window);
11576
+ shimOnTrack$1(window, browserDetails);
11463
11577
  shimAddTrackRemoveTrack(window, browserDetails);
11464
11578
  shimGetSendersWithDtmf(window);
11465
- shimSenderReceiverGetStats(window);
11579
+ shimSenderReceiverGetStats(window, browserDetails);
11466
11580
  fixNegotiationNeeded(window, browserDetails);
11467
11581
  shimRTCIceCandidate(window);
11468
11582
  shimRTCIceCandidateRelayProtocol(window);
11469
11583
  shimConnectionState(window);
11470
11584
  shimMaxMessageSize(window, browserDetails);
11471
- shimSendThrowTypeError(window);
11585
+ shimSendThrowTypeError(window, browserDetails);
11472
11586
  removeExtmapAllowMixed(window, browserDetails);
11473
11587
  break;
11474
11588
  case 'firefox':
@@ -11485,6 +11599,7 @@ function adapterFactory() {
11485
11599
  shimParameterlessSetLocalDescription(window);
11486
11600
  shimGetUserMedia$1(window, browserDetails);
11487
11601
  shimPeerConnection(window, browserDetails);
11602
+ shimGetStats(window, browserDetails);
11488
11603
  shimOnTrack(window);
11489
11604
  shimRemoveStream(window);
11490
11605
  shimSenderGetStats(window);
@@ -11497,7 +11612,7 @@ function adapterFactory() {
11497
11612
  shimRTCIceCandidate(window);
11498
11613
  shimConnectionState(window);
11499
11614
  shimMaxMessageSize(window, browserDetails);
11500
- shimSendThrowTypeError(window);
11615
+ shimSendThrowTypeError(window, browserDetails);
11501
11616
  break;
11502
11617
  case 'safari':
11503
11618
  if (!safariShim || !options.shimSafari) {
@@ -11522,7 +11637,7 @@ function adapterFactory() {
11522
11637
  shimRTCIceCandidate(window);
11523
11638
  shimRTCIceCandidateRelayProtocol(window);
11524
11639
  shimMaxMessageSize(window, browserDetails);
11525
- shimSendThrowTypeError(window);
11640
+ shimSendThrowTypeError(window, browserDetails);
11526
11641
  removeExtmapAllowMixed(window, browserDetails);
11527
11642
  break;
11528
11643
  default:
@@ -11629,7 +11744,7 @@ function getMatch(exp, ua) {
11629
11744
  }
11630
11745
  function getOSVersion(ua) {
11631
11746
  return ua.includes('mac os') ? getMatch(/\(.+?(\d+_\d+(:?_\d+)?)/, ua, 1).replace(/_/g, '.') : undefined;
11632
- }var version$1 = "2.18.2";const version = version$1;
11747
+ }var version$1 = "2.18.4";const version = version$1;
11633
11748
  const protocolVersion = 16;/** Base error that all LiveKit specific custom errors inherit from. */
11634
11749
  class LivekitError extends Error {
11635
11750
  constructor(code, message, options) {
@@ -17043,6 +17158,7 @@ class PCTransport extends eventsExports.EventEmitter {
17043
17158
  if (!this._pc) {
17044
17159
  return;
17045
17160
  }
17161
+ this.pendingInitialOffer = undefined;
17046
17162
  this._pc.close();
17047
17163
  this._pc.onconnectionstatechange = null;
17048
17164
  this._pc.oniceconnectionstatechange = null;
@@ -17130,7 +17246,7 @@ class PCTransport extends eventsExports.EventEmitter {
17130
17246
  this.remoteStereoMids = stereoMids;
17131
17247
  this.remoteNackMids = nackMids;
17132
17248
  } else if (sd.type === 'answer') {
17133
- if (this.pendingInitialOffer) {
17249
+ if (this.pendingInitialOffer && this._pc) {
17134
17250
  const initialOffer = this.pendingInitialOffer;
17135
17251
  this.pendingInitialOffer = undefined;
17136
17252
  const sdpParsed = libExports.parse((_a = initialOffer.sdp) !== null && _a !== void 0 ? _a : '');
@@ -17452,6 +17568,7 @@ class PCTransport extends eventsExports.EventEmitter {
17452
17568
  }
17453
17569
  setMungedSDP(sd, munged, remote) {
17454
17570
  return __awaiter(this, void 0, void 0, function* () {
17571
+ var _a, _b;
17455
17572
  if (munged) {
17456
17573
  const originalSdp = sd.sdp;
17457
17574
  sd.sdp = munged;
@@ -17473,9 +17590,9 @@ class PCTransport extends eventsExports.EventEmitter {
17473
17590
  }
17474
17591
  try {
17475
17592
  if (remote) {
17476
- yield this.pc.setRemoteDescription(sd);
17593
+ yield (_a = this._pc) === null || _a === void 0 ? void 0 : _a.setRemoteDescription(sd);
17477
17594
  } else {
17478
- yield this.pc.setLocalDescription(sd);
17595
+ yield (_b = this._pc) === null || _b === void 0 ? void 0 : _b.setLocalDescription(sd);
17479
17596
  }
17480
17597
  } catch (e) {
17481
17598
  let msg = 'unknown error';
@@ -20256,6 +20373,7 @@ class RTCEngine extends eventsExports.EventEmitter {
20256
20373
  /** specifies how often an initial join connection is allowed to retry */
20257
20374
  this.maxJoinAttempts = 1;
20258
20375
  this.shouldFailNext = false;
20376
+ this.shouldFailOnV1Path = false;
20259
20377
  this.log = livekitLogger;
20260
20378
  this.reliableDataSequence = 1;
20261
20379
  this.reliableMessageBuffer = new DataPacketBuffer();
@@ -20557,6 +20675,11 @@ class RTCEngine extends eventsExports.EventEmitter {
20557
20675
  if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
20558
20676
  throw ConnectionError.cancelled('Connection aborted');
20559
20677
  }
20678
+ if (!useV0Path && _this2.shouldFailOnV1Path) {
20679
+ _this2.shouldFailOnV1Path = false;
20680
+ throw ConnectionError.serviceNotFound('Simulated v1 path failure', 'v0-rtc');
20681
+ }
20682
+ livekitLogger.warn('joining signal with ', url);
20560
20683
  const joinResponse = yield _this2.client.join(url, token, opts, abortSignal, useV0Path, offerProto);
20561
20684
  _this2._isClosed = false;
20562
20685
  _this2.latestJoinResponse = joinResponse;
@@ -20606,6 +20729,10 @@ class RTCEngine extends eventsExports.EventEmitter {
20606
20729
  }
20607
20730
  } else if (e.reason === ConnectionErrorReason.ServiceNotFound) {
20608
20731
  _this2.log.warn("Initial connection failed: ".concat(e.message, " \u2013 Retrying"));
20732
+ if (_this2.pcManager) {
20733
+ _this2.pcManager.onStateChange = undefined;
20734
+ yield _this2.cleanupPeerConnections();
20735
+ }
20609
20736
  return _this2.join(url, token, opts, abortSignal, true);
20610
20737
  }
20611
20738
  }
@@ -21706,6 +21833,11 @@ class RTCEngine extends eventsExports.EventEmitter {
21706
21833
  // debugging method to fail the next reconnect/resume attempt
21707
21834
  this.shouldFailNext = true;
21708
21835
  }
21836
+ /* @internal */
21837
+ failNextV1Path() {
21838
+ // debugging method to fail the next connection attempt for /rtc/v1 to trigger the fallback version
21839
+ this.shouldFailOnV1Path = true;
21840
+ }
21709
21841
  dataChannelsInfo() {
21710
21842
  const infos = [];
21711
21843
  const getInfo = (dc, target) => {
@@ -23463,55 +23595,82 @@ class IncomingDataTrackManager extends eventsExports.EventEmitter {
23463
23595
  let bufferSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : READABLE_STREAM_DEFAULT_BUFFER_SIZE;
23464
23596
  let streamController = null;
23465
23597
  const sfuSubscriptionComplete = new Future();
23598
+ const detachSignal = () => {
23599
+ signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', onAbort);
23600
+ };
23601
+ const cleanup = () => {
23602
+ detachSignal();
23603
+ if (!streamController) {
23604
+ log$1.warn("ReadableStream subscribed to ".concat(sid, " was not started."));
23605
+ return;
23606
+ }
23607
+ const descriptor = this.descriptors.get(sid);
23608
+ if (!descriptor) {
23609
+ log$1.warn("Unknown track ".concat(sid, ", skipping cancel..."));
23610
+ return;
23611
+ }
23612
+ if (descriptor.subscription.type !== 'active') {
23613
+ log$1.warn("Subscription for track ".concat(sid, " is not active, skipping cancel..."));
23614
+ return;
23615
+ }
23616
+ descriptor.subscription.streamControllers.delete(streamController);
23617
+ // If no active stream controllers are left, also unsubscribe on the SFU end.
23618
+ if (descriptor.subscription.streamControllers.size === 0) {
23619
+ this.unSubscribeRequest(descriptor.info.sid);
23620
+ }
23621
+ };
23622
+ const onAbort = () => {
23623
+ var _a;
23624
+ if (!streamController) {
23625
+ return;
23626
+ }
23627
+ const currentDescriptor = this.descriptors.get(sid);
23628
+ if ((currentDescriptor === null || currentDescriptor === void 0 ? void 0 : currentDescriptor.subscription.type) === 'active') {
23629
+ currentDescriptor.subscription.streamControllers.delete(streamController);
23630
+ }
23631
+ streamController.error(DataTrackSubscribeError.cancelled());
23632
+ (_a = sfuSubscriptionComplete.reject) === null || _a === void 0 ? void 0 : _a.call(sfuSubscriptionComplete, DataTrackSubscribeError.cancelled());
23633
+ cleanup();
23634
+ };
23466
23635
  const stream = new ReadableStream({
23467
23636
  start: controller => {
23468
23637
  streamController = controller;
23469
- const onAbort = () => {
23470
- var _a;
23471
- controller.error(DataTrackSubscribeError.cancelled());
23472
- (_a = sfuSubscriptionComplete.reject) === null || _a === void 0 ? void 0 : _a.call(sfuSubscriptionComplete, DataTrackSubscribeError.cancelled());
23473
- };
23474
23638
  this.subscribeRequest(sid, signal).then(() => __awaiter(this, void 0, void 0, function* () {
23475
- var _a;
23476
- signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', onAbort);
23639
+ var _a, _b, _c;
23477
23640
  const descriptor = this.descriptors.get(sid);
23478
23641
  if (!descriptor) {
23479
23642
  log$1.error("Unknown track ".concat(sid));
23643
+ const err = DataTrackSubscribeError.disconnected();
23644
+ controller.error(err);
23645
+ (_a = sfuSubscriptionComplete.reject) === null || _a === void 0 ? void 0 : _a.call(sfuSubscriptionComplete, err);
23480
23646
  return;
23481
23647
  }
23482
23648
  if (descriptor.subscription.type !== 'active') {
23483
23649
  log$1.error("Subscription for track ".concat(sid, " is not active"));
23650
+ const err = DataTrackSubscribeError.disconnected();
23651
+ controller.error(err);
23652
+ (_b = sfuSubscriptionComplete.reject) === null || _b === void 0 ? void 0 : _b.call(sfuSubscriptionComplete, err);
23484
23653
  return;
23485
23654
  }
23486
- descriptor.subscription.streamControllers.add(controller);
23487
- (_a = sfuSubscriptionComplete.resolve) === null || _a === void 0 ? void 0 : _a.call(sfuSubscriptionComplete);
23655
+ // Attach the abort signal, aborting immediately if the abort signal was fired while
23656
+ // subscribeRequest was in flight.
23657
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
23658
+ onAbort();
23659
+ return;
23660
+ }
23661
+ signal === null || signal === void 0 ? void 0 : signal.addEventListener('abort', onAbort);
23662
+ descriptor.subscription.streamControllers.set(controller, detachSignal);
23663
+ (_c = sfuSubscriptionComplete.resolve) === null || _c === void 0 ? void 0 : _c.call(sfuSubscriptionComplete);
23488
23664
  })).catch(err => {
23489
23665
  var _a;
23666
+ // subscribeRequest rejected (cancelled, timed out, disconnected). The signal
23667
+ // listener was never attached in this path, so nothing to detach.
23490
23668
  controller.error(err);
23491
23669
  (_a = sfuSubscriptionComplete.reject) === null || _a === void 0 ? void 0 : _a.call(sfuSubscriptionComplete, err);
23492
- }).finally(() => {
23493
- signal === null || signal === void 0 ? void 0 : signal.removeEventListener('abort', onAbort);
23494
23670
  });
23495
23671
  },
23496
23672
  cancel: () => {
23497
- if (!streamController) {
23498
- log$1.warn("ReadableStream subscribed to ".concat(sid, " was not started."));
23499
- return;
23500
- }
23501
- const descriptor = this.descriptors.get(sid);
23502
- if (!descriptor) {
23503
- log$1.warn("Unknown track ".concat(sid, ", skipping cancel..."));
23504
- return;
23505
- }
23506
- if (descriptor.subscription.type !== 'active') {
23507
- log$1.warn("Subscription for track ".concat(sid, " is not active, skipping cancel..."));
23508
- return;
23509
- }
23510
- descriptor.subscription.streamControllers.delete(streamController);
23511
- // If no active stream controllers are left, also unsubscribe on the SFU end.
23512
- if (descriptor.subscription.streamControllers.size === 0) {
23513
- this.unSubscribeRequest(descriptor.info.sid);
23514
- }
23673
+ cleanup();
23515
23674
  }
23516
23675
  }, new CountQueuingStrategy({
23517
23676
  highWaterMark: bufferSize
@@ -23649,9 +23808,7 @@ class IncomingDataTrackManager extends eventsExports.EventEmitter {
23649
23808
  log$1.warn("Unexpected descriptor state in unSubscribeRequest, expected active, found ".concat((_a = descriptor.subscription) === null || _a === void 0 ? void 0 : _a.type));
23650
23809
  return;
23651
23810
  }
23652
- for (const controller of descriptor.subscription.streamControllers) {
23653
- controller.close();
23654
- }
23811
+ this.closeStreamControllers(descriptor.subscription.streamControllers, sid);
23655
23812
  // FIXME: this might be wrong? Shouldn't this only occur if it is the last subscription to
23656
23813
  // terminate?
23657
23814
  const previousDescriptorSubscription = descriptor.subscription;
@@ -23664,6 +23821,23 @@ class IncomingDataTrackManager extends eventsExports.EventEmitter {
23664
23821
  subscribe: false
23665
23822
  });
23666
23823
  }
23824
+ /** Detach abort-signal listeners and close all downstream stream controllers for an active
23825
+ * subscription. Used when the subscription is being torn down by the manager (unsubscribe,
23826
+ * unpublish, or shutdown). */
23827
+ closeStreamControllers(streamControllers, sid) {
23828
+ for (const [controller, detachSignal] of streamControllers) {
23829
+ // Detach before close so we don't leak a listener on the user's AbortSignal.
23830
+ detachSignal();
23831
+ try {
23832
+ controller.close();
23833
+ } catch (err) {
23834
+ // Defensive: if the controller has already been errored (e.g. by a racing abort whose
23835
+ // listener removed itself before we got here), close() throws. There's nothing
23836
+ // meaningful to do other than log — the stream is already terminal.
23837
+ log$1.warn("Failed to close readable stream for track ".concat(sid, ": ").concat(err));
23838
+ }
23839
+ }
23840
+ }
23667
23841
  /** SFU notification that track publications have changed.
23668
23842
  *
23669
23843
  * This event is produced from both {@link JoinResponse} and {@link ParticipantUpdate}
@@ -23745,9 +23919,7 @@ class IncomingDataTrackManager extends eventsExports.EventEmitter {
23745
23919
  }
23746
23920
  this.descriptors.delete(sid);
23747
23921
  if (descriptor.subscription.type === 'active') {
23748
- descriptor.subscription.streamControllers.forEach(controller => {
23749
- controller.close();
23750
- });
23922
+ this.closeStreamControllers(descriptor.subscription.streamControllers, sid);
23751
23923
  this.subscriptionHandles.delete(descriptor.subscription.subcriptionHandle);
23752
23924
  }
23753
23925
  this.emit('trackUnpublished', {
@@ -23797,7 +23969,7 @@ class IncomingDataTrackManager extends eventsExports.EventEmitter {
23797
23969
  type: 'active',
23798
23970
  subcriptionHandle: assignedHandle,
23799
23971
  pipeline,
23800
- streamControllers: new Set()
23972
+ streamControllers: new Map()
23801
23973
  };
23802
23974
  this.subscriptionHandles.set(assignedHandle, sid);
23803
23975
  (_b = (_a = previousDescriptorSubscription.completionFuture).resolve) === null || _b === void 0 ? void 0 : _b.call(_a);
@@ -23834,7 +24006,7 @@ class IncomingDataTrackManager extends eventsExports.EventEmitter {
23834
24006
  return;
23835
24007
  }
23836
24008
  // Broadcast to all downstream subscribers
23837
- for (const controller of descriptor.subscription.streamControllers) {
24009
+ for (const controller of descriptor.subscription.streamControllers.keys()) {
23838
24010
  if (controller.desiredSize !== null && controller.desiredSize <= 0) {
23839
24011
  log$1.warn("Cannot send frame to subscribers: readable stream is full (desiredSize is ".concat(controller.desiredSize, "). To increase this threshold, set a higher 'options.highWaterMark' when calling .subscribe()."));
23840
24012
  continue;
@@ -23892,7 +24064,7 @@ class IncomingDataTrackManager extends eventsExports.EventEmitter {
23892
24064
  (_b = (_a = descriptor.subscription.completionFuture).reject) === null || _b === void 0 ? void 0 : _b.call(_a, DataTrackSubscribeError.disconnected());
23893
24065
  }
23894
24066
  if (descriptor.subscription.type === 'active') {
23895
- descriptor.subscription.streamControllers.forEach(controller => controller.close());
24067
+ this.closeStreamControllers(descriptor.subscription.streamControllers, descriptor.info.sid);
23896
24068
  }
23897
24069
  }
23898
24070
  this.descriptors.clear();
@@ -27641,14 +27813,14 @@ class DeferrableMap extends Map {
27641
27813
  this.pending = new Map();
27642
27814
  }
27643
27815
  set(key, value) {
27644
- var _a;
27816
+ var _a, _b;
27645
27817
  super.set(key, value);
27646
27818
  // Resolve any futures waiting on this key.
27647
- const futures = this.pending.get(key);
27819
+ const futures = (_a = this.pending) === null || _a === void 0 ? void 0 : _a.get(key);
27648
27820
  if (futures) {
27649
27821
  for (const future of futures) {
27650
27822
  if (!future.isResolved) {
27651
- (_a = future.resolve) === null || _a === void 0 ? void 0 : _a.call(future, value);
27823
+ (_b = future.resolve) === null || _b === void 0 ? void 0 : _b.call(future, value);
27652
27824
  }
27653
27825
  }
27654
27826
  this.pending.delete(key);
@@ -27656,7 +27828,7 @@ class DeferrableMap extends Map {
27656
27828
  return this;
27657
27829
  }
27658
27830
  get [Symbol.toStringTag]() {
27659
- return 'WaitableMap';
27831
+ return 'DeferrableMap';
27660
27832
  }
27661
27833
  getDeferred(key, signal) {
27662
27834
  return __awaiter(this, void 0, void 0, function* () {
@@ -27979,8 +28151,13 @@ class DeferrableMap extends Map {
27979
28151
  }
27980
28152
  }class RemoteParticipant extends Participant {
27981
28153
  /** @internal */
27982
- static fromParticipantInfo(signalClient, pi, loggerOptions) {
27983
- return new RemoteParticipant(signalClient, pi.sid, pi.identity, pi.name, pi.metadata, pi.attributes, loggerOptions, pi.kind);
28154
+ static fromParticipantInfo(signalClient, pi, loggerOptions, manager) {
28155
+ return new RemoteParticipant(signalClient, pi.sid, pi.identity, pi.name, pi.metadata, pi.attributes, loggerOptions, pi.kind, pi.dataTracks.map(dti => {
28156
+ const info = DataTrackInfo.from(dti);
28157
+ return new RemoteDataTrack(info, manager, {
28158
+ publisherIdentity: pi.identity
28159
+ });
28160
+ }));
27984
28161
  }
27985
28162
  get logContext() {
27986
28163
  return Object.assign(Object.assign({}, super.logContext), {
@@ -27991,12 +28168,15 @@ class DeferrableMap extends Map {
27991
28168
  /** @internal */
27992
28169
  constructor(signalClient, sid, identity, name, metadata, attributes, loggerOptions) {
27993
28170
  let kind = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : ParticipantInfo_Kind.STANDARD;
28171
+ let remoteDataTracks = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : [];
27994
28172
  super(sid, identity || '', name, metadata, attributes, loggerOptions, kind);
27995
28173
  this.signalClient = signalClient;
27996
28174
  this.trackPublications = new Map();
27997
28175
  this.audioTrackPublications = new Map();
27998
28176
  this.videoTrackPublications = new Map();
27999
- this.dataTracks = new DeferrableMap();
28177
+ this.dataTracks = new DeferrableMap(remoteDataTracks.map(remoteDataTrack => {
28178
+ return [remoteDataTrack.info.name, remoteDataTrack];
28179
+ }));
28000
28180
  this.volumeMap = new Map();
28001
28181
  }
28002
28182
  addTrackPublication(publication) {
@@ -29290,18 +29470,7 @@ class Room extends eventsExports.EventEmitter {
29290
29470
  }).on(EngineEvent.DCBufferStatusChanged, (status, kind) => {
29291
29471
  this.emit(RoomEvent.DCBufferStatusChanged, status, kind);
29292
29472
  }).on(EngineEvent.LocalTrackSubscribed, subscribedSid => {
29293
- const trackPublication = this.localParticipant.getTrackPublications().find(_ref2 => {
29294
- let {
29295
- trackSid
29296
- } = _ref2;
29297
- return trackSid === subscribedSid;
29298
- });
29299
- if (!trackPublication) {
29300
- this.log.warn('could not find local track subscription for subscribed event', this.logContext);
29301
- return;
29302
- }
29303
- this.localParticipant.emit(ParticipantEvent.LocalTrackSubscribed, trackPublication);
29304
- this.emitWhenConnected(RoomEvent.LocalTrackSubscribed, trackPublication, this.localParticipant);
29473
+ this.handleLocalTrackSubscribed(subscribedSid);
29305
29474
  }).on(EngineEvent.RoomMoved, roomMoved => {
29306
29475
  this.log.debug('room moved', roomMoved);
29307
29476
  if (roomMoved.room) {
@@ -29337,8 +29506,8 @@ class Room extends eventsExports.EventEmitter {
29337
29506
  }
29338
29507
  this.outgoingDataTrackManager.receivedSfuUnpublishResponse(event.info.pubHandle);
29339
29508
  }).on(EngineEvent.DataTrackSubscriberHandles, event => {
29340
- const handleToSidMapping = new Map(Object.entries(event.subHandles).map(_ref3 => {
29341
- let [key, value] = _ref3;
29509
+ const handleToSidMapping = new Map(Object.entries(event.subHandles).map(_ref2 => {
29510
+ let [key, value] = _ref2;
29342
29511
  return [parseInt(key, 10), value.trackSid];
29343
29512
  }));
29344
29513
  this.incomingDataTrackManager.receivedSfuSubscriberHandles(handleToSidMapping);
@@ -29444,6 +29613,9 @@ class Room extends eventsExports.EventEmitter {
29444
29613
  // @ts-expect-error function is private
29445
29614
  yield this.engine.client.handleOnClose('simulate disconnect');
29446
29615
  break;
29616
+ case 'fail-on-v1-path':
29617
+ this.engine.failNextV1Path();
29618
+ break;
29447
29619
  case 'speaker':
29448
29620
  req = new SimulateScenario({
29449
29621
  scenario: {
@@ -29767,6 +29939,56 @@ class Room extends eventsExports.EventEmitter {
29767
29939
  this.emit(RoomEvent.EncryptionError, new Error("Encrypted ".concat(publication.source, " track received from participant ").concat(participant.sid, ", but room does not have encryption enabled!")));
29768
29940
  }
29769
29941
  }
29942
+ handleLocalTrackSubscribed(subscribedSid) {
29943
+ const findPublication = () => this.localParticipant.getTrackPublications().find(_ref3 => {
29944
+ let {
29945
+ trackSid
29946
+ } = _ref3;
29947
+ return trackSid === subscribedSid;
29948
+ });
29949
+ const trackPublication = findPublication();
29950
+ if (trackPublication) {
29951
+ this.emitLocalTrackSubscribed(trackPublication);
29952
+ return;
29953
+ }
29954
+ // the track publication may not be registered yet if the server signals
29955
+ // the subscription before publishTrack has finished adding the publication.
29956
+ // defer with a timeout until LocalTrackPublished fires for the matching trackSid
29957
+ this.log.debug('deferring LocalTrackSubscribed, publication not yet available', Object.assign(Object.assign({}, this.logContext), {
29958
+ subscribedSid
29959
+ }));
29960
+ const TIMEOUT_MS = 10000;
29961
+ let timer;
29962
+ const onPublished = pub => {
29963
+ if (pub.trackSid === subscribedSid) {
29964
+ cleanup();
29965
+ this.emitLocalTrackSubscribed(pub);
29966
+ }
29967
+ };
29968
+ const cleanup = () => {
29969
+ clearTimeout(timer);
29970
+ this.localParticipant.off(ParticipantEvent.LocalTrackPublished, onPublished);
29971
+ this.off(RoomEvent.Disconnected, cleanup);
29972
+ };
29973
+ this.localParticipant.on(ParticipantEvent.LocalTrackPublished, onPublished);
29974
+ this.once(RoomEvent.Disconnected, cleanup);
29975
+ timer = setTimeout(() => {
29976
+ cleanup();
29977
+ // final attempt in case the publication was added without emitting the event
29978
+ const pub = findPublication();
29979
+ if (pub) {
29980
+ this.emitLocalTrackSubscribed(pub);
29981
+ } else {
29982
+ this.log.warn('could not find local track publication for LocalTrackSubscribed event after timeout', Object.assign(Object.assign({}, this.logContext), {
29983
+ subscribedSid
29984
+ }));
29985
+ }
29986
+ }, TIMEOUT_MS);
29987
+ }
29988
+ emitLocalTrackSubscribed(trackPublication) {
29989
+ this.localParticipant.emit(ParticipantEvent.LocalTrackSubscribed, trackPublication);
29990
+ this.emitWhenConnected(RoomEvent.LocalTrackSubscribed, trackPublication, this.localParticipant);
29991
+ }
29770
29992
  handleDisconnect() {
29771
29993
  let shouldStopTracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
29772
29994
  let reason = arguments.length > 1 ? arguments[1] : undefined;
@@ -29971,7 +30193,7 @@ class Room extends eventsExports.EventEmitter {
29971
30193
  participant = RemoteParticipant.fromParticipantInfo(this.engine.client, info, {
29972
30194
  loggerContextCb: () => this.logContext,
29973
30195
  loggerName: this.options.loggerName
29974
- });
30196
+ }, this.incomingDataTrackManager);
29975
30197
  } else {
29976
30198
  participant = new RemoteParticipant(this.engine.client, '', identity, undefined, undefined, undefined, {
29977
30199
  loggerContextCb: () => this.logContext,
@@ -31332,7 +31554,9 @@ function decodeTokenPayload(token) {
31332
31554
  } = payload,
31333
31555
  rest = __rest(payload, ["roomConfig"]);
31334
31556
  const mappedPayload = Object.assign(Object.assign({}, rest), {
31335
- roomConfig: payload.roomConfig ? RoomConfiguration.fromJson(payload.roomConfig) : undefined
31557
+ roomConfig: payload.roomConfig ? RoomConfiguration.fromJson(payload.roomConfig, {
31558
+ ignoreUnknownFields: true
31559
+ }) : undefined
31336
31560
  });
31337
31561
  return mappedPayload;
31338
31562
  }