@livekit/rtc-node 0.11.0 → 0.12.0
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/audio_frame.cjs +94 -0
- package/dist/audio_frame.cjs.map +1 -0
- package/dist/audio_frame.js +64 -67
- package/dist/audio_frame.js.map +1 -1
- package/dist/audio_resampler.cjs +153 -0
- package/dist/audio_resampler.cjs.map +1 -0
- package/dist/audio_resampler.js +129 -134
- package/dist/audio_resampler.js.map +1 -1
- package/dist/audio_source.cjs +116 -0
- package/dist/audio_source.cjs.map +1 -0
- package/dist/audio_source.js +92 -85
- package/dist/audio_source.js.map +1 -1
- package/dist/audio_stream.cjs +104 -0
- package/dist/audio_stream.cjs.map +1 -0
- package/dist/audio_stream.js +77 -78
- package/dist/audio_stream.js.map +1 -1
- package/dist/e2ee.cjs +268 -0
- package/dist/e2ee.cjs.map +1 -0
- package/dist/e2ee.d.ts.map +1 -1
- package/dist/e2ee.js +244 -221
- package/dist/e2ee.js.map +1 -1
- package/dist/ffi_client.cjs +101 -0
- package/dist/ffi_client.cjs.map +1 -0
- package/dist/ffi_client.js +73 -48
- package/dist/ffi_client.js.map +1 -1
- package/dist/index.cjs +188 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +130 -48
- package/dist/index.js.map +1 -1
- package/dist/napi/native.d.cjs +17 -0
- package/dist/napi/native.d.cjs.map +1 -0
- package/dist/napi/native.d.js +1 -0
- package/dist/napi/native.d.js.map +1 -0
- package/dist/napi/native.d.ts +5 -5
- package/dist/native.cjs +301 -0
- package/dist/native.d.ts +19 -0
- package/dist/native.js +15 -0
- package/dist/participant.cjs +388 -0
- package/dist/participant.cjs.map +1 -0
- package/dist/participant.js +363 -339
- package/dist/participant.js.map +1 -1
- package/dist/proto/audio_frame_pb.cjs +193 -0
- package/dist/proto/audio_frame_pb.cjs.map +1 -0
- package/dist/proto/audio_frame_pb.d.ts +8 -8
- package/dist/proto/audio_frame_pb.d.ts.map +1 -1
- package/dist/proto/audio_frame_pb.js +122 -322
- package/dist/proto/audio_frame_pb.js.map +1 -1
- package/dist/proto/e2ee_pb.cjs +131 -0
- package/dist/proto/e2ee_pb.cjs.map +1 -0
- package/dist/proto/e2ee_pb.js +76 -202
- package/dist/proto/e2ee_pb.js.map +1 -1
- package/dist/proto/ffi_pb.cjs +76 -0
- package/dist/proto/ffi_pb.cjs.map +1 -0
- package/dist/proto/ffi_pb.d.ts +6 -6
- package/dist/proto/ffi_pb.d.ts.map +1 -1
- package/dist/proto/ffi_pb.js +39 -98
- package/dist/proto/ffi_pb.js.map +1 -1
- package/dist/proto/handle_pb.cjs +33 -0
- package/dist/proto/handle_pb.cjs.map +1 -0
- package/dist/proto/handle_pb.js +6 -22
- package/dist/proto/handle_pb.js.map +1 -1
- package/dist/proto/participant_pb.cjs +50 -0
- package/dist/proto/participant_pb.cjs.map +1 -0
- package/dist/proto/participant_pb.d.ts +1 -1
- package/dist/proto/participant_pb.d.ts.map +1 -1
- package/dist/proto/participant_pb.js +20 -58
- package/dist/proto/participant_pb.js.map +1 -1
- package/dist/proto/room_pb.cjs +370 -0
- package/dist/proto/room_pb.cjs.map +1 -0
- package/dist/proto/room_pb.d.ts +16 -16
- package/dist/proto/room_pb.d.ts.map +1 -1
- package/dist/proto/room_pb.js +245 -638
- package/dist/proto/room_pb.js.map +1 -1
- package/dist/proto/rpc_pb.cjs +63 -0
- package/dist/proto/rpc_pb.cjs.map +1 -0
- package/dist/proto/rpc_pb.js +26 -72
- package/dist/proto/rpc_pb.js.map +1 -1
- package/dist/proto/stats_pb.cjs +256 -0
- package/dist/proto/stats_pb.cjs.map +1 -0
- package/dist/proto/stats_pb.js +175 -456
- package/dist/proto/stats_pb.js.map +1 -1
- package/dist/proto/track_pb.cjs +116 -0
- package/dist/proto/track_pb.cjs.map +1 -0
- package/dist/proto/track_pb.d.ts +3 -3
- package/dist/proto/track_pb.d.ts.map +1 -1
- package/dist/proto/track_pb.js +68 -174
- package/dist/proto/track_pb.js.map +1 -1
- package/dist/proto/video_frame_pb.cjs +161 -0
- package/dist/proto/video_frame_pb.cjs.map +1 -0
- package/dist/proto/video_frame_pb.d.ts +5 -5
- package/dist/proto/video_frame_pb.d.ts.map +1 -1
- package/dist/proto/video_frame_pb.js +103 -271
- package/dist/proto/video_frame_pb.js.map +1 -1
- package/dist/room.cjs +440 -0
- package/dist/room.cjs.map +1 -0
- package/dist/room.js +384 -373
- package/dist/room.js.map +1 -1
- package/dist/rpc.cjs +89 -0
- package/dist/rpc.cjs.map +1 -0
- package/dist/rpc.js +59 -63
- package/dist/rpc.js.map +1 -1
- package/dist/track.cjs +100 -0
- package/dist/track.cjs.map +1 -0
- package/dist/track.js +66 -62
- package/dist/track.js.map +1 -1
- package/dist/track_publication.cjs +106 -0
- package/dist/track_publication.cjs.map +1 -0
- package/dist/track_publication.js +76 -74
- package/dist/track_publication.js.map +1 -1
- package/dist/transcription.cjs +17 -0
- package/dist/transcription.cjs.map +1 -0
- package/dist/transcription.js +0 -1
- package/dist/transcription.js.map +1 -1
- package/dist/types.cjs +17 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.js +0 -1
- package/dist/types.js.map +1 -1
- package/dist/version.cjs +29 -0
- package/dist/version.cjs.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +4 -1
- package/dist/version.js.map +1 -1
- package/dist/video_frame.cjs +242 -0
- package/dist/video_frame.cjs.map +1 -0
- package/dist/video_frame.js +212 -201
- package/dist/video_frame.js.map +1 -1
- package/dist/video_source.cjs +63 -0
- package/dist/video_source.cjs.map +1 -0
- package/dist/video_source.d.ts.map +1 -1
- package/dist/video_source.js +42 -37
- package/dist/video_source.js.map +1 -1
- package/dist/video_stream.cjs +103 -0
- package/dist/video_stream.cjs.map +1 -0
- package/dist/video_stream.js +76 -77
- package/dist/video_stream.js.map +1 -1
- package/package.json +18 -9
- package/src/audio_frame.ts +2 -2
- package/src/audio_source.ts +2 -2
- package/src/e2ee.ts +2 -2
- package/src/napi/native.d.ts +5 -5
- package/src/proto/audio_frame_pb.ts +12 -12
- package/src/proto/e2ee_pb.ts +1 -1
- package/src/proto/ffi_pb.ts +13 -13
- package/src/proto/handle_pb.ts +1 -1
- package/src/proto/participant_pb.ts +3 -3
- package/src/proto/room_pb.ts +24 -24
- package/src/proto/rpc_pb.ts +1 -1
- package/src/proto/stats_pb.ts +1 -1
- package/src/proto/track_pb.ts +7 -7
- package/src/proto/video_frame_pb.ts +9 -9
- package/src/version.ts +1 -1
- package/src/video_frame.ts +1 -1
- package/src/video_source.ts +5 -1
package/dist/participant.js
CHANGED
|
@@ -1,355 +1,379 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
|
|
211
|
-
track_publication.track = track;
|
|
212
|
-
this.trackPublications.set(track_publication.sid, track_publication);
|
|
213
|
-
return track_publication;
|
|
352
|
+
}
|
|
214
353
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
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
|