@livekit/rtc-node 0.11.1 → 0.12.1

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 (135) hide show
  1. package/dist/audio_frame.cjs +94 -0
  2. package/dist/audio_frame.cjs.map +1 -0
  3. package/dist/audio_frame.js +64 -67
  4. package/dist/audio_frame.js.map +1 -1
  5. package/dist/audio_resampler.cjs +153 -0
  6. package/dist/audio_resampler.cjs.map +1 -0
  7. package/dist/audio_resampler.js +129 -134
  8. package/dist/audio_resampler.js.map +1 -1
  9. package/dist/audio_source.cjs +116 -0
  10. package/dist/audio_source.cjs.map +1 -0
  11. package/dist/audio_source.js +92 -85
  12. package/dist/audio_source.js.map +1 -1
  13. package/dist/audio_stream.cjs +104 -0
  14. package/dist/audio_stream.cjs.map +1 -0
  15. package/dist/audio_stream.js +77 -78
  16. package/dist/audio_stream.js.map +1 -1
  17. package/dist/e2ee.cjs +268 -0
  18. package/dist/e2ee.cjs.map +1 -0
  19. package/dist/e2ee.d.ts.map +1 -1
  20. package/dist/e2ee.js +244 -221
  21. package/dist/e2ee.js.map +1 -1
  22. package/dist/ffi_client.cjs +95 -0
  23. package/dist/ffi_client.cjs.map +1 -0
  24. package/dist/ffi_client.d.ts +2 -2
  25. package/dist/ffi_client.d.ts.map +1 -1
  26. package/dist/ffi_client.js +67 -48
  27. package/dist/ffi_client.js.map +1 -1
  28. package/dist/index.cjs +166 -0
  29. package/dist/index.cjs.map +1 -0
  30. package/dist/index.d.ts +5 -5
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +119 -48
  33. package/dist/index.js.map +1 -1
  34. package/dist/napi/native.d.cjs +17 -0
  35. package/dist/napi/native.d.cjs.map +1 -0
  36. package/dist/napi/native.d.js +1 -0
  37. package/dist/napi/native.d.js.map +1 -0
  38. package/dist/native.cjs +301 -0
  39. package/dist/native.d.ts +19 -0
  40. package/dist/native.js +15 -0
  41. package/dist/participant.cjs +388 -0
  42. package/dist/participant.cjs.map +1 -0
  43. package/dist/participant.js +363 -339
  44. package/dist/participant.js.map +1 -1
  45. package/dist/proto/audio_frame_pb.cjs +193 -0
  46. package/dist/proto/audio_frame_pb.cjs.map +1 -0
  47. package/dist/proto/audio_frame_pb.js +120 -320
  48. package/dist/proto/audio_frame_pb.js.map +1 -1
  49. package/dist/proto/e2ee_pb.cjs +131 -0
  50. package/dist/proto/e2ee_pb.cjs.map +1 -0
  51. package/dist/proto/e2ee_pb.js +76 -202
  52. package/dist/proto/e2ee_pb.js.map +1 -1
  53. package/dist/proto/ffi_pb.cjs +76 -0
  54. package/dist/proto/ffi_pb.cjs.map +1 -0
  55. package/dist/proto/ffi_pb.js +33 -92
  56. package/dist/proto/ffi_pb.js.map +1 -1
  57. package/dist/proto/handle_pb.cjs +33 -0
  58. package/dist/proto/handle_pb.cjs.map +1 -0
  59. package/dist/proto/handle_pb.js +6 -22
  60. package/dist/proto/handle_pb.js.map +1 -1
  61. package/dist/proto/participant_pb.cjs +50 -0
  62. package/dist/proto/participant_pb.cjs.map +1 -0
  63. package/dist/proto/participant_pb.js +19 -57
  64. package/dist/proto/participant_pb.js.map +1 -1
  65. package/dist/proto/room_pb.cjs +370 -0
  66. package/dist/proto/room_pb.cjs.map +1 -0
  67. package/dist/proto/room_pb.js +239 -632
  68. package/dist/proto/room_pb.js.map +1 -1
  69. package/dist/proto/rpc_pb.cjs +63 -0
  70. package/dist/proto/rpc_pb.cjs.map +1 -0
  71. package/dist/proto/rpc_pb.js +26 -72
  72. package/dist/proto/rpc_pb.js.map +1 -1
  73. package/dist/proto/stats_pb.cjs +256 -0
  74. package/dist/proto/stats_pb.cjs.map +1 -0
  75. package/dist/proto/stats_pb.js +175 -456
  76. package/dist/proto/stats_pb.js.map +1 -1
  77. package/dist/proto/track_pb.cjs +116 -0
  78. package/dist/proto/track_pb.cjs.map +1 -0
  79. package/dist/proto/track_pb.js +65 -171
  80. package/dist/proto/track_pb.js.map +1 -1
  81. package/dist/proto/video_frame_pb.cjs +161 -0
  82. package/dist/proto/video_frame_pb.cjs.map +1 -0
  83. package/dist/proto/video_frame_pb.js +101 -269
  84. package/dist/proto/video_frame_pb.js.map +1 -1
  85. package/dist/room.cjs +440 -0
  86. package/dist/room.cjs.map +1 -0
  87. package/dist/room.js +384 -373
  88. package/dist/room.js.map +1 -1
  89. package/dist/rpc.cjs +89 -0
  90. package/dist/rpc.cjs.map +1 -0
  91. package/dist/rpc.js +59 -63
  92. package/dist/rpc.js.map +1 -1
  93. package/dist/track.cjs +100 -0
  94. package/dist/track.cjs.map +1 -0
  95. package/dist/track.js +66 -62
  96. package/dist/track.js.map +1 -1
  97. package/dist/track_publication.cjs +106 -0
  98. package/dist/track_publication.cjs.map +1 -0
  99. package/dist/track_publication.js +76 -74
  100. package/dist/track_publication.js.map +1 -1
  101. package/dist/transcription.cjs +17 -0
  102. package/dist/transcription.cjs.map +1 -0
  103. package/dist/transcription.js +0 -1
  104. package/dist/transcription.js.map +1 -1
  105. package/dist/types.cjs +17 -0
  106. package/dist/types.cjs.map +1 -0
  107. package/dist/types.js +0 -1
  108. package/dist/types.js.map +1 -1
  109. package/dist/version.cjs +29 -0
  110. package/dist/version.cjs.map +1 -0
  111. package/dist/version.d.ts +1 -1
  112. package/dist/version.js +4 -1
  113. package/dist/version.js.map +1 -1
  114. package/dist/video_frame.cjs +242 -0
  115. package/dist/video_frame.cjs.map +1 -0
  116. package/dist/video_frame.js +212 -201
  117. package/dist/video_frame.js.map +1 -1
  118. package/dist/video_source.cjs +63 -0
  119. package/dist/video_source.cjs.map +1 -0
  120. package/dist/video_source.d.ts.map +1 -1
  121. package/dist/video_source.js +42 -37
  122. package/dist/video_source.js.map +1 -1
  123. package/dist/video_stream.cjs +103 -0
  124. package/dist/video_stream.cjs.map +1 -0
  125. package/dist/video_stream.js +76 -77
  126. package/dist/video_stream.js.map +1 -1
  127. package/package.json +18 -9
  128. package/src/audio_frame.ts +2 -2
  129. package/src/audio_source.ts +2 -2
  130. package/src/e2ee.ts +2 -2
  131. package/src/ffi_client.ts +4 -4
  132. package/src/index.ts +14 -8
  133. package/src/version.ts +1 -1
  134. package/src/video_frame.ts +1 -1
  135. package/src/video_source.ts +5 -1
@@ -1,355 +1,379 @@
1
- // SPDX-FileCopyrightText: 2024 LiveKit, Inc.
2
- //
3
- // SPDX-License-Identifier: Apache-2.0
4
- import { create } from '@bufbuild/protobuf';
5
- import { FfiClient, FfiHandle } from './ffi_client.js';
6
- import { ChatMessageSchema, EditChatMessageRequestSchema, PublishDataRequestSchema, PublishSipDtmfRequestSchema, PublishTrackRequestSchema, PublishTranscriptionRequestSchema, SendChatMessageRequestSchema, SetLocalAttributesRequestSchema, SetLocalMetadataRequestSchema, SetLocalNameRequestSchema, UnpublishTrackRequestSchema, } from './proto/room_pb.js';
7
- import { TranscriptionSegmentSchema } from './proto/room_pb.js';
8
- import { PerformRpcRequestSchema, RegisterRpcMethodRequestSchema, RpcMethodInvocationResponseRequestSchema, UnregisterRpcMethodRequestSchema, } from './proto/rpc_pb.js';
9
- import { RpcError } from './rpc.js';
10
- import { LocalTrackPublication } from './track_publication.js';
11
- export class Participant {
12
- constructor(owned_info) {
13
- this.trackPublications = new Map();
14
- this.info = owned_info.info;
15
- this.ffi_handle = new FfiHandle(owned_info.handle.id);
16
- }
17
- get sid() {
18
- return this.info.sid;
19
- }
20
- get name() {
21
- return this.info.name;
22
- }
23
- get identity() {
24
- return this.info.identity;
25
- }
26
- get metadata() {
27
- return this.info.metadata;
28
- }
29
- get attributes() {
30
- return this.info.attributes;
31
- }
32
- get kind() {
33
- return this.info.kind;
34
- }
1
+ import { create } from "@bufbuild/protobuf";
2
+ import { FfiClient, FfiHandle } from "./ffi_client.js";
3
+ import {
4
+ ChatMessageSchema,
5
+ EditChatMessageRequestSchema,
6
+ PublishDataRequestSchema,
7
+ PublishSipDtmfRequestSchema,
8
+ PublishTrackRequestSchema,
9
+ PublishTranscriptionRequestSchema,
10
+ SendChatMessageRequestSchema,
11
+ SetLocalAttributesRequestSchema,
12
+ SetLocalMetadataRequestSchema,
13
+ SetLocalNameRequestSchema,
14
+ UnpublishTrackRequestSchema
15
+ } from "./proto/room_pb.js";
16
+ import { TranscriptionSegmentSchema } from "./proto/room_pb.js";
17
+ import {
18
+ PerformRpcRequestSchema,
19
+ RegisterRpcMethodRequestSchema,
20
+ RpcMethodInvocationResponseRequestSchema,
21
+ UnregisterRpcMethodRequestSchema
22
+ } from "./proto/rpc_pb.js";
23
+ import { RpcError } from "./rpc.js";
24
+ import { LocalTrackPublication } from "./track_publication.js";
25
+ class Participant {
26
+ constructor(owned_info) {
27
+ this.trackPublications = /* @__PURE__ */ new Map();
28
+ this.info = owned_info.info;
29
+ this.ffi_handle = new FfiHandle(owned_info.handle.id);
30
+ }
31
+ get sid() {
32
+ return this.info.sid;
33
+ }
34
+ get name() {
35
+ return this.info.name;
36
+ }
37
+ get identity() {
38
+ return this.info.identity;
39
+ }
40
+ get metadata() {
41
+ return this.info.metadata;
42
+ }
43
+ get attributes() {
44
+ return this.info.attributes;
45
+ }
46
+ get kind() {
47
+ return this.info.kind;
48
+ }
35
49
  }
36
- export class LocalParticipant extends Participant {
37
- constructor() {
38
- super(...arguments);
39
- this.rpcHandlers = new Map();
40
- this.trackPublications = new Map();
50
+ class LocalParticipant extends Participant {
51
+ constructor() {
52
+ super(...arguments);
53
+ this.rpcHandlers = /* @__PURE__ */ new Map();
54
+ this.trackPublications = /* @__PURE__ */ new Map();
55
+ }
56
+ async publishData(data, options) {
57
+ const req = create(PublishDataRequestSchema, {
58
+ localParticipantHandle: this.ffi_handle.handle,
59
+ dataPtr: FfiClient.instance.retrievePtr(data),
60
+ dataLen: BigInt(data.byteLength),
61
+ reliable: options.reliable,
62
+ topic: options.topic,
63
+ destinationIdentities: options.destination_identities
64
+ });
65
+ const res = FfiClient.instance.request({
66
+ message: { case: "publishData", value: req }
67
+ });
68
+ const cb = await FfiClient.instance.waitFor((ev) => {
69
+ return ev.message.case == "publishData" && ev.message.value.asyncId == res.asyncId;
70
+ });
71
+ if (cb.error) {
72
+ throw new Error(cb.error);
41
73
  }
42
- async publishData(data, options) {
43
- const req = create(PublishDataRequestSchema, {
44
- localParticipantHandle: this.ffi_handle.handle,
45
- dataPtr: FfiClient.instance.retrievePtr(data),
46
- dataLen: BigInt(data.byteLength),
47
- reliable: options.reliable,
48
- topic: options.topic,
49
- destinationIdentities: options.destination_identities,
50
- });
51
- const res = FfiClient.instance.request({
52
- message: { case: 'publishData', value: req },
53
- });
54
- const cb = await FfiClient.instance.waitFor((ev) => {
55
- return ev.message.case == 'publishData' && ev.message.value.asyncId == res.asyncId;
56
- });
57
- if (cb.error) {
58
- throw new Error(cb.error);
59
- }
74
+ }
75
+ async publishDtmf(code, digit) {
76
+ const req = create(PublishSipDtmfRequestSchema, {
77
+ localParticipantHandle: this.ffi_handle.handle,
78
+ code,
79
+ digit
80
+ });
81
+ const res = FfiClient.instance.request({
82
+ message: { case: "publishSipDtmf", value: req }
83
+ });
84
+ const cb = await FfiClient.instance.waitFor((ev) => {
85
+ return ev.message.case == "publishSipDtmf" && ev.message.value.asyncId == res.asyncId;
86
+ });
87
+ if (cb.error) {
88
+ throw new Error(cb.error);
60
89
  }
61
- async publishDtmf(code, digit) {
62
- const req = create(PublishSipDtmfRequestSchema, {
63
- localParticipantHandle: this.ffi_handle.handle,
64
- code,
65
- digit,
66
- });
67
- const res = FfiClient.instance.request({
68
- message: { case: 'publishSipDtmf', value: req },
69
- });
70
- const cb = await FfiClient.instance.waitFor((ev) => {
71
- return ev.message.case == 'publishSipDtmf' && ev.message.value.asyncId == res.asyncId;
72
- });
73
- if (cb.error) {
74
- throw new Error(cb.error);
75
- }
90
+ }
91
+ async publishTranscription(transcription) {
92
+ const req = create(PublishTranscriptionRequestSchema, {
93
+ localParticipantHandle: this.ffi_handle.handle,
94
+ participantIdentity: transcription.participantIdentity,
95
+ segments: transcription.segments.map(
96
+ (s) => create(TranscriptionSegmentSchema, {
97
+ id: s.id,
98
+ text: s.text,
99
+ startTime: s.startTime,
100
+ endTime: s.endTime,
101
+ final: s.final,
102
+ language: s.language
103
+ })
104
+ ),
105
+ trackId: transcription.trackSid
106
+ });
107
+ const res = FfiClient.instance.request({
108
+ message: { case: "publishTranscription", value: req }
109
+ });
110
+ const cb = await FfiClient.instance.waitFor((ev) => {
111
+ return ev.message.case == "publishTranscription" && ev.message.value.asyncId == res.asyncId;
112
+ });
113
+ if (cb.error) {
114
+ throw new Error(cb.error);
76
115
  }
77
- async publishTranscription(transcription) {
78
- const req = create(PublishTranscriptionRequestSchema, {
79
- localParticipantHandle: this.ffi_handle.handle,
80
- participantIdentity: transcription.participantIdentity,
81
- segments: transcription.segments.map((s) => create(TranscriptionSegmentSchema, {
82
- id: s.id,
83
- text: s.text,
84
- startTime: s.startTime,
85
- endTime: s.endTime,
86
- final: s.final,
87
- language: s.language,
88
- })),
89
- trackId: transcription.trackSid,
90
- });
91
- const res = FfiClient.instance.request({
92
- message: { case: 'publishTranscription', value: req },
93
- });
94
- const cb = await FfiClient.instance.waitFor((ev) => {
95
- return ev.message.case == 'publishTranscription' && ev.message.value.asyncId == res.asyncId;
96
- });
97
- if (cb.error) {
98
- throw new Error(cb.error);
99
- }
116
+ }
117
+ async updateMetadata(metadata) {
118
+ const req = create(SetLocalMetadataRequestSchema, {
119
+ localParticipantHandle: this.ffi_handle.handle,
120
+ metadata
121
+ });
122
+ const res = FfiClient.instance.request({
123
+ message: { case: "setLocalMetadata", value: req }
124
+ });
125
+ await FfiClient.instance.waitFor((ev) => {
126
+ return ev.message.case == "setLocalMetadata" && ev.message.value.asyncId == res.asyncId;
127
+ });
128
+ }
129
+ /**
130
+ * Sends a chat message to participants in the room
131
+ *
132
+ * @param text - The text content of the chat message.
133
+ * @param destinationIdentities - An optional array of recipient identities to whom the message will be sent. If omitted, the message is broadcast to all participants.
134
+ * @param senderIdentity - An optional identity of the sender. If omitted, the default sender identity is used.
135
+ *
136
+ */
137
+ async sendChatMessage(text, destinationIdentities, senderIdentity) {
138
+ const req = create(SendChatMessageRequestSchema, {
139
+ localParticipantHandle: this.ffi_handle.handle,
140
+ message: text,
141
+ destinationIdentities,
142
+ senderIdentity
143
+ });
144
+ const res = FfiClient.instance.request({
145
+ message: { case: "sendChatMessage", value: req }
146
+ });
147
+ const cb = await FfiClient.instance.waitFor((ev) => {
148
+ return ev.message.case == "chatMessage" && ev.message.value.asyncId == res.asyncId;
149
+ });
150
+ if (cb.message.case !== "chatMessage") {
151
+ throw new Error(cb.message.value ?? "Unknown Error");
100
152
  }
101
- async updateMetadata(metadata) {
102
- const req = create(SetLocalMetadataRequestSchema, {
103
- localParticipantHandle: this.ffi_handle.handle,
104
- metadata: metadata,
105
- });
106
- const res = FfiClient.instance.request({
107
- message: { case: 'setLocalMetadata', value: req },
108
- });
109
- await FfiClient.instance.waitFor((ev) => {
110
- return ev.message.case == 'setLocalMetadata' && ev.message.value.asyncId == res.asyncId;
111
- });
153
+ const { id, timestamp, editTimestamp, message } = cb.message.value;
154
+ return { id, timestamp: Number(timestamp), editTimestamp: Number(editTimestamp), message };
155
+ }
156
+ /**
157
+ * @experimental
158
+ */
159
+ async editChatMessage(editText, originalMessage, destinationIdentities, senderIdentity) {
160
+ const req = create(EditChatMessageRequestSchema, {
161
+ localParticipantHandle: this.ffi_handle.handle,
162
+ editText,
163
+ originalMessage: create(ChatMessageSchema, {
164
+ ...originalMessage,
165
+ timestamp: BigInt(originalMessage.timestamp),
166
+ editTimestamp: originalMessage.editTimestamp ? BigInt(originalMessage.editTimestamp) : void 0
167
+ }),
168
+ destinationIdentities,
169
+ senderIdentity
170
+ });
171
+ const res = FfiClient.instance.request({
172
+ message: { case: "editChatMessage", value: req }
173
+ });
174
+ const cb = await FfiClient.instance.waitFor((ev) => {
175
+ return ev.message.case == "chatMessage" && ev.message.value.asyncId == res.asyncId;
176
+ });
177
+ if (cb.message.case !== "chatMessage") {
178
+ throw new Error(cb.message.value ?? "Unknown Error");
112
179
  }
113
- /**
114
- * Sends a chat message to participants in the room
115
- *
116
- * @param text - The text content of the chat message.
117
- * @param destinationIdentities - An optional array of recipient identities to whom the message will be sent. If omitted, the message is broadcast to all participants.
118
- * @param senderIdentity - An optional identity of the sender. If omitted, the default sender identity is used.
119
- *
120
- */
121
- async sendChatMessage(text, destinationIdentities, senderIdentity) {
122
- const req = create(SendChatMessageRequestSchema, {
123
- localParticipantHandle: this.ffi_handle.handle,
124
- message: text,
125
- destinationIdentities,
126
- senderIdentity,
127
- });
128
- const res = FfiClient.instance.request({
129
- message: { case: 'sendChatMessage', value: req },
130
- });
131
- const cb = await FfiClient.instance.waitFor((ev) => {
132
- return ev.message.case == 'chatMessage' && ev.message.value.asyncId == res.asyncId;
133
- });
134
- if (cb.message.case !== 'chatMessage') {
135
- throw new Error(cb.message.value ?? 'Unknown Error');
136
- }
137
- const { id, timestamp, editTimestamp, message } = cb.message.value;
138
- return { id, timestamp: Number(timestamp), editTimestamp: Number(editTimestamp), message };
180
+ const { id, timestamp, editTimestamp, message } = cb.message.value;
181
+ return { id, timestamp: Number(timestamp), editTimestamp: Number(editTimestamp), message };
182
+ }
183
+ async updateName(name) {
184
+ const req = create(SetLocalNameRequestSchema, {
185
+ localParticipantHandle: this.ffi_handle.handle,
186
+ name
187
+ });
188
+ const res = FfiClient.instance.request({
189
+ message: { case: "setLocalName", value: req }
190
+ });
191
+ await FfiClient.instance.waitFor((ev) => {
192
+ return ev.message.case == "setLocalName" && ev.message.value.asyncId == res.asyncId;
193
+ });
194
+ }
195
+ async setAttributes(attributes) {
196
+ const req = create(SetLocalAttributesRequestSchema, {
197
+ localParticipantHandle: this.ffi_handle.handle,
198
+ attributes: Array.from(Object.entries(attributes)).map(([key, value]) => {
199
+ return { key, value };
200
+ })
201
+ });
202
+ const res = FfiClient.instance.request({
203
+ message: { case: "setLocalAttributes", value: req }
204
+ });
205
+ await FfiClient.instance.waitFor((ev) => {
206
+ return ev.message.case == "setLocalAttributes" && ev.message.value.asyncId == res.asyncId;
207
+ });
208
+ }
209
+ async publishTrack(track, options) {
210
+ const req = create(PublishTrackRequestSchema, {
211
+ localParticipantHandle: this.ffi_handle.handle,
212
+ trackHandle: track.ffi_handle.handle,
213
+ options
214
+ });
215
+ const res = FfiClient.instance.request({
216
+ message: { case: "publishTrack", value: req }
217
+ });
218
+ const cb = await FfiClient.instance.waitFor((ev) => {
219
+ return ev.message.case == "publishTrack" && ev.message.value.asyncId == res.asyncId;
220
+ });
221
+ if (cb.message.case !== "publication") {
222
+ throw new Error(cb.message.value ?? "Unknown Error");
139
223
  }
140
- /**
141
- * @experimental
142
- */
143
- async editChatMessage(editText, originalMessage, destinationIdentities, senderIdentity) {
144
- const req = create(EditChatMessageRequestSchema, {
145
- localParticipantHandle: this.ffi_handle.handle,
146
- editText,
147
- originalMessage: create(ChatMessageSchema, {
148
- ...originalMessage,
149
- timestamp: BigInt(originalMessage.timestamp),
150
- editTimestamp: originalMessage.editTimestamp
151
- ? BigInt(originalMessage.editTimestamp)
152
- : undefined,
153
- }),
154
- destinationIdentities,
155
- senderIdentity,
156
- });
157
- const res = FfiClient.instance.request({
158
- message: { case: 'editChatMessage', value: req },
159
- });
160
- const cb = await FfiClient.instance.waitFor((ev) => {
161
- return ev.message.case == 'chatMessage' && ev.message.value.asyncId == res.asyncId;
162
- });
163
- if (cb.message.case !== 'chatMessage') {
164
- throw new Error(cb.message.value ?? 'Unknown Error');
165
- }
166
- const { id, timestamp, editTimestamp, message } = cb.message.value;
167
- return { id, timestamp: Number(timestamp), editTimestamp: Number(editTimestamp), message };
224
+ const track_publication = new LocalTrackPublication(cb.message.value);
225
+ track_publication.track = track;
226
+ this.trackPublications.set(track_publication.sid, track_publication);
227
+ return track_publication;
228
+ }
229
+ async unpublishTrack(trackSid) {
230
+ const req = create(UnpublishTrackRequestSchema, {
231
+ localParticipantHandle: this.ffi_handle.handle,
232
+ trackSid
233
+ });
234
+ const res = FfiClient.instance.request({
235
+ message: { case: "unpublishTrack", value: req }
236
+ });
237
+ const cb = await FfiClient.instance.waitFor((ev) => {
238
+ return ev.message.case == "unpublishTrack" && ev.message.value.asyncId == res.asyncId;
239
+ });
240
+ if (cb.error) {
241
+ throw new Error(cb.error);
168
242
  }
169
- async updateName(name) {
170
- const req = create(SetLocalNameRequestSchema, {
171
- localParticipantHandle: this.ffi_handle.handle,
172
- name: name,
173
- });
174
- const res = FfiClient.instance.request({
175
- message: { case: 'setLocalName', value: req },
176
- });
177
- await FfiClient.instance.waitFor((ev) => {
178
- return ev.message.case == 'setLocalName' && ev.message.value.asyncId == res.asyncId;
179
- });
243
+ const pub = this.trackPublications.get(trackSid);
244
+ if (pub) {
245
+ pub.track = void 0;
180
246
  }
181
- async setAttributes(attributes) {
182
- const req = create(SetLocalAttributesRequestSchema, {
183
- localParticipantHandle: this.ffi_handle.handle,
184
- attributes: Array.from(Object.entries(attributes)).map(([key, value]) => {
185
- return { key, value };
186
- }),
187
- });
188
- const res = FfiClient.instance.request({
189
- message: { case: 'setLocalAttributes', value: req },
190
- });
191
- await FfiClient.instance.waitFor((ev) => {
192
- return ev.message.case == 'setLocalAttributes' && ev.message.value.asyncId == res.asyncId;
193
- });
247
+ this.trackPublications.delete(trackSid);
248
+ }
249
+ /**
250
+ * Initiate an RPC call to a remote participant.
251
+ * @param params - Parameters for initiating the RPC call, see {@link PerformRpcParams}
252
+ * @returns A promise that resolves with the response payload or rejects with an error.
253
+ * @throws Error on failure. Details in `message`.
254
+ */
255
+ async performRpc({
256
+ destinationIdentity,
257
+ method,
258
+ payload,
259
+ responseTimeout
260
+ }) {
261
+ const req = create(PerformRpcRequestSchema, {
262
+ localParticipantHandle: this.ffi_handle.handle,
263
+ destinationIdentity,
264
+ method,
265
+ payload,
266
+ responseTimeoutMs: responseTimeout
267
+ });
268
+ const res = FfiClient.instance.request({
269
+ message: { case: "performRpc", value: req }
270
+ });
271
+ const cb = await FfiClient.instance.waitFor((ev) => {
272
+ return ev.message.case === "performRpc" && ev.message.value.asyncId === res.asyncId;
273
+ });
274
+ if (cb.error) {
275
+ throw RpcError.fromProto(cb.error);
194
276
  }
195
- async publishTrack(track, options) {
196
- const req = create(PublishTrackRequestSchema, {
197
- localParticipantHandle: this.ffi_handle.handle,
198
- trackHandle: track.ffi_handle.handle,
199
- options: options,
200
- });
201
- const res = FfiClient.instance.request({
202
- message: { case: 'publishTrack', value: req },
203
- });
204
- const cb = await FfiClient.instance.waitFor((ev) => {
205
- return ev.message.case == 'publishTrack' && ev.message.value.asyncId == res.asyncId;
206
- });
207
- if (cb.message.case !== 'publication') {
208
- throw new Error(cb.message.value ?? 'Unknown Error');
277
+ return cb.payload;
278
+ }
279
+ /**
280
+ * Establishes the participant as a receiver for calls of the specified RPC method.
281
+ * Will overwrite any existing callback for the same method.
282
+ *
283
+ * @param method - The name of the indicated RPC method
284
+ * @param handler - Will be invoked when an RPC request for this method is received
285
+ * @returns A promise that resolves when the method is successfully registered
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * room.localParticipant?.registerRpcMethod(
290
+ * 'greet',
291
+ * async (data: RpcInvocationData) => {
292
+ * console.log(`Received greeting from ${data.callerIdentity}: ${data.payload}`);
293
+ * return `Hello, ${data.callerIdentity}!`;
294
+ * }
295
+ * );
296
+ * ```
297
+ *
298
+ * See {@link RpcInvocationData} for more details on invocation params.
299
+ *
300
+ * The handler should return a Promise that resolves to a string.
301
+ * If unable to respond within `responseTimeout`, the request will result in an error on the caller's side.
302
+ *
303
+ * You may throw errors of type `RpcError` with a string `message` in the handler,
304
+ * and they will be received on the caller's side with the message intact.
305
+ * Other errors thrown in your handler will not be transmitted as-is, and will instead arrive to the caller as `1500` ("Application Error").
306
+ */
307
+ registerRpcMethod(method, handler) {
308
+ this.rpcHandlers.set(method, handler);
309
+ const req = create(RegisterRpcMethodRequestSchema, {
310
+ localParticipantHandle: this.ffi_handle.handle,
311
+ method
312
+ });
313
+ FfiClient.instance.request({
314
+ message: { case: "registerRpcMethod", value: req }
315
+ });
316
+ }
317
+ /**
318
+ * Unregisters a previously registered RPC method.
319
+ *
320
+ * @param method - The name of the RPC method to unregister
321
+ */
322
+ unregisterRpcMethod(method) {
323
+ this.rpcHandlers.delete(method);
324
+ const req = create(UnregisterRpcMethodRequestSchema, {
325
+ localParticipantHandle: this.ffi_handle.handle,
326
+ method
327
+ });
328
+ FfiClient.instance.request({
329
+ message: { case: "unregisterRpcMethod", value: req }
330
+ });
331
+ }
332
+ /** @internal */
333
+ async handleRpcMethodInvocation(invocationId, method, requestId, callerIdentity, payload, responseTimeout) {
334
+ let responseError = null;
335
+ let responsePayload = null;
336
+ const handler = this.rpcHandlers.get(method);
337
+ if (!handler) {
338
+ responseError = RpcError.builtIn("UNSUPPORTED_METHOD");
339
+ } else {
340
+ try {
341
+ responsePayload = await handler({ requestId, callerIdentity, payload, responseTimeout });
342
+ } catch (error) {
343
+ if (error instanceof RpcError) {
344
+ responseError = error;
345
+ } else {
346
+ console.warn(
347
+ `Uncaught error returned by RPC handler for ${method}. Returning APPLICATION_ERROR instead.`,
348
+ error
349
+ );
350
+ responseError = RpcError.builtIn("APPLICATION_ERROR");
209
351
  }
210
- const track_publication = new LocalTrackPublication(cb.message.value);
211
- track_publication.track = track;
212
- this.trackPublications.set(track_publication.sid, track_publication);
213
- return track_publication;
352
+ }
214
353
  }
215
- async unpublishTrack(trackSid) {
216
- const req = create(UnpublishTrackRequestSchema, {
217
- localParticipantHandle: this.ffi_handle.handle,
218
- trackSid: trackSid,
219
- });
220
- const res = FfiClient.instance.request({
221
- message: { case: 'unpublishTrack', value: req },
222
- });
223
- const cb = await FfiClient.instance.waitFor((ev) => {
224
- return ev.message.case == 'unpublishTrack' && ev.message.value.asyncId == res.asyncId;
225
- });
226
- if (cb.error) {
227
- throw new Error(cb.error);
228
- }
229
- const pub = this.trackPublications.get(trackSid);
230
- if (pub) {
231
- pub.track = undefined;
232
- }
233
- this.trackPublications.delete(trackSid);
234
- }
235
- /**
236
- * Initiate an RPC call to a remote participant.
237
- * @param params - Parameters for initiating the RPC call, see {@link PerformRpcParams}
238
- * @returns A promise that resolves with the response payload or rejects with an error.
239
- * @throws Error on failure. Details in `message`.
240
- */
241
- async performRpc({ destinationIdentity, method, payload, responseTimeout, }) {
242
- const req = create(PerformRpcRequestSchema, {
243
- localParticipantHandle: this.ffi_handle.handle,
244
- destinationIdentity,
245
- method,
246
- payload,
247
- responseTimeoutMs: responseTimeout,
248
- });
249
- const res = FfiClient.instance.request({
250
- message: { case: 'performRpc', value: req },
251
- });
252
- const cb = await FfiClient.instance.waitFor((ev) => {
253
- return ev.message.case === 'performRpc' && ev.message.value.asyncId === res.asyncId;
254
- });
255
- if (cb.error) {
256
- throw RpcError.fromProto(cb.error);
257
- }
258
- return cb.payload;
259
- }
260
- /**
261
- * Establishes the participant as a receiver for calls of the specified RPC method.
262
- * Will overwrite any existing callback for the same method.
263
- *
264
- * @param method - The name of the indicated RPC method
265
- * @param handler - Will be invoked when an RPC request for this method is received
266
- * @returns A promise that resolves when the method is successfully registered
267
- *
268
- * @example
269
- * ```typescript
270
- * room.localParticipant?.registerRpcMethod(
271
- * 'greet',
272
- * async (data: RpcInvocationData) => {
273
- * console.log(`Received greeting from ${data.callerIdentity}: ${data.payload}`);
274
- * return `Hello, ${data.callerIdentity}!`;
275
- * }
276
- * );
277
- * ```
278
- *
279
- * See {@link RpcInvocationData} for more details on invocation params.
280
- *
281
- * The handler should return a Promise that resolves to a string.
282
- * If unable to respond within `responseTimeout`, the request will result in an error on the caller's side.
283
- *
284
- * You may throw errors of type `RpcError` with a string `message` in the handler,
285
- * and they will be received on the caller's side with the message intact.
286
- * Other errors thrown in your handler will not be transmitted as-is, and will instead arrive to the caller as `1500` ("Application Error").
287
- */
288
- registerRpcMethod(method, handler) {
289
- this.rpcHandlers.set(method, handler);
290
- const req = create(RegisterRpcMethodRequestSchema, {
291
- localParticipantHandle: this.ffi_handle.handle,
292
- method,
293
- });
294
- FfiClient.instance.request({
295
- message: { case: 'registerRpcMethod', value: req },
296
- });
297
- }
298
- /**
299
- * Unregisters a previously registered RPC method.
300
- *
301
- * @param method - The name of the RPC method to unregister
302
- */
303
- unregisterRpcMethod(method) {
304
- this.rpcHandlers.delete(method);
305
- const req = create(UnregisterRpcMethodRequestSchema, {
306
- localParticipantHandle: this.ffi_handle.handle,
307
- method,
308
- });
309
- FfiClient.instance.request({
310
- message: { case: 'unregisterRpcMethod', value: req },
311
- });
312
- }
313
- /** @internal */
314
- async handleRpcMethodInvocation(invocationId, method, requestId, callerIdentity, payload, responseTimeout) {
315
- let responseError = null;
316
- let responsePayload = null;
317
- const handler = this.rpcHandlers.get(method);
318
- if (!handler) {
319
- responseError = RpcError.builtIn('UNSUPPORTED_METHOD');
320
- }
321
- else {
322
- try {
323
- responsePayload = await handler({ requestId, callerIdentity, payload, responseTimeout });
324
- }
325
- catch (error) {
326
- if (error instanceof RpcError) {
327
- responseError = error;
328
- }
329
- else {
330
- console.warn(`Uncaught error returned by RPC handler for ${method}. Returning APPLICATION_ERROR instead.`, error);
331
- responseError = RpcError.builtIn('APPLICATION_ERROR');
332
- }
333
- }
334
- }
335
- const req = create(RpcMethodInvocationResponseRequestSchema, {
336
- localParticipantHandle: this.ffi_handle.handle,
337
- invocationId,
338
- error: responseError ? responseError.toProto() : undefined,
339
- payload: responsePayload ?? undefined,
340
- });
341
- const res = FfiClient.instance.request({
342
- message: { case: 'rpcMethodInvocationResponse', value: req },
343
- });
344
- if (res.error) {
345
- console.warn(`error sending rpc method invocation response: ${res.error}`);
346
- }
354
+ const req = create(RpcMethodInvocationResponseRequestSchema, {
355
+ localParticipantHandle: this.ffi_handle.handle,
356
+ invocationId,
357
+ error: responseError ? responseError.toProto() : void 0,
358
+ payload: responsePayload ?? void 0
359
+ });
360
+ const res = FfiClient.instance.request({
361
+ message: { case: "rpcMethodInvocationResponse", value: req }
362
+ });
363
+ if (res.error) {
364
+ console.warn(`error sending rpc method invocation response: ${res.error}`);
347
365
  }
366
+ }
348
367
  }
349
- export class RemoteParticipant extends Participant {
350
- constructor(owned_info) {
351
- super(owned_info);
352
- this.trackPublications = new Map();
353
- }
368
+ class RemoteParticipant extends Participant {
369
+ constructor(owned_info) {
370
+ super(owned_info);
371
+ this.trackPublications = /* @__PURE__ */ new Map();
372
+ }
354
373
  }
374
+ export {
375
+ LocalParticipant,
376
+ Participant,
377
+ RemoteParticipant
378
+ };
355
379
  //# sourceMappingURL=participant.js.map