livekit-server-sdk 2.8.0 → 2.9.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.
Files changed (66) hide show
  1. package/README.md +1 -1
  2. package/dist/AccessToken.cjs +169 -0
  3. package/dist/AccessToken.cjs.map +1 -0
  4. package/dist/AccessToken.js +130 -137
  5. package/dist/AccessToken.js.map +1 -1
  6. package/dist/AccessToken.test.cjs +147 -0
  7. package/dist/AccessToken.test.cjs.map +1 -0
  8. package/dist/AccessToken.test.js +129 -0
  9. package/dist/AccessToken.test.js.map +1 -0
  10. package/dist/AgentDispatchClient.cjs +133 -0
  11. package/dist/AgentDispatchClient.cjs.map +1 -0
  12. package/dist/AgentDispatchClient.d.ts +1 -1
  13. package/dist/AgentDispatchClient.d.ts.map +1 -1
  14. package/dist/AgentDispatchClient.js +102 -79
  15. package/dist/AgentDispatchClient.js.map +1 -1
  16. package/dist/EgressClient.cjs +381 -0
  17. package/dist/EgressClient.cjs.map +1 -0
  18. package/dist/EgressClient.js +349 -288
  19. package/dist/EgressClient.js.map +1 -1
  20. package/dist/IngressClient.cjs +164 -0
  21. package/dist/IngressClient.cjs.map +1 -0
  22. package/dist/IngressClient.js +131 -106
  23. package/dist/IngressClient.js.map +1 -1
  24. package/dist/RoomServiceClient.cjs +240 -0
  25. package/dist/RoomServiceClient.cjs.map +1 -0
  26. package/dist/RoomServiceClient.js +219 -151
  27. package/dist/RoomServiceClient.js.map +1 -1
  28. package/dist/ServiceBase.cjs +49 -0
  29. package/dist/ServiceBase.cjs.map +1 -0
  30. package/dist/ServiceBase.js +25 -28
  31. package/dist/ServiceBase.js.map +1 -1
  32. package/dist/SipClient.cjs +379 -0
  33. package/dist/SipClient.cjs.map +1 -0
  34. package/dist/SipClient.d.ts +15 -0
  35. package/dist/SipClient.d.ts.map +1 -1
  36. package/dist/SipClient.js +360 -260
  37. package/dist/SipClient.js.map +1 -1
  38. package/dist/TwirpRPC.cjs +71 -0
  39. package/dist/TwirpRPC.cjs.map +1 -0
  40. package/dist/TwirpRPC.d.ts.map +1 -1
  41. package/dist/TwirpRPC.js +32 -29
  42. package/dist/TwirpRPC.js.map +1 -1
  43. package/dist/WebhookReceiver.cjs +78 -0
  44. package/dist/WebhookReceiver.cjs.map +1 -0
  45. package/dist/WebhookReceiver.js +48 -45
  46. package/dist/WebhookReceiver.js.map +1 -1
  47. package/dist/WebhookReceiver.test.cjs +38 -0
  48. package/dist/WebhookReceiver.test.cjs.map +1 -0
  49. package/dist/WebhookReceiver.test.js +37 -0
  50. package/dist/WebhookReceiver.test.js.map +1 -0
  51. package/dist/grants.cjs +53 -0
  52. package/dist/grants.cjs.map +1 -0
  53. package/dist/grants.js +25 -23
  54. package/dist/grants.js.map +1 -1
  55. package/dist/grants.test.cjs +27 -0
  56. package/dist/grants.test.cjs.map +1 -0
  57. package/dist/grants.test.js +26 -0
  58. package/dist/grants.test.js.map +1 -0
  59. package/dist/index.cjs +136 -0
  60. package/dist/index.cjs.map +1 -0
  61. package/dist/index.js +104 -12
  62. package/dist/index.js.map +1 -1
  63. package/package.json +12 -3
  64. package/src/AgentDispatchClient.ts +2 -2
  65. package/src/SipClient.ts +33 -0
  66. package/src/TwirpRPC.ts +1 -1
package/dist/SipClient.js CHANGED
@@ -1,271 +1,371 @@
1
- // SPDX-FileCopyrightText: 2024 LiveKit, Inc.
2
- //
3
- // SPDX-License-Identifier: Apache-2.0
4
- import { CreateSIPDispatchRuleRequest, CreateSIPInboundTrunkRequest, CreateSIPOutboundTrunkRequest, CreateSIPParticipantRequest, CreateSIPTrunkRequest, DeleteSIPDispatchRuleRequest, DeleteSIPTrunkRequest, ListSIPDispatchRuleRequest, ListSIPDispatchRuleResponse, ListSIPInboundTrunkRequest, ListSIPInboundTrunkResponse, ListSIPOutboundTrunkRequest, ListSIPOutboundTrunkResponse, ListSIPTrunkRequest, ListSIPTrunkResponse, SIPDispatchRule, SIPDispatchRuleDirect, SIPDispatchRuleIndividual, SIPDispatchRuleInfo, SIPInboundTrunkInfo, SIPOutboundTrunkInfo, SIPParticipantInfo, SIPTransport, SIPTrunkInfo, TransferSIPParticipantRequest, } from '@livekit/protocol';
5
- import ServiceBase from './ServiceBase.js';
6
- import { TwirpRpc, livekitPackage } from './TwirpRPC.js';
7
- const svc = 'SIP';
8
- /**
9
- * Client to access Egress APIs
10
- */
11
- export class SipClient extends ServiceBase {
12
- /**
13
- * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
14
- * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
15
- * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
16
- */
17
- constructor(host, apiKey, secret) {
18
- super(apiKey, secret);
19
- this.rpc = new TwirpRpc(host, livekitPackage);
1
+ import { Duration } from "@bufbuild/protobuf";
2
+ import {
3
+ CreateSIPDispatchRuleRequest,
4
+ CreateSIPInboundTrunkRequest,
5
+ CreateSIPOutboundTrunkRequest,
6
+ CreateSIPParticipantRequest,
7
+ CreateSIPTrunkRequest,
8
+ DeleteSIPDispatchRuleRequest,
9
+ DeleteSIPTrunkRequest,
10
+ ListSIPDispatchRuleRequest,
11
+ ListSIPDispatchRuleResponse,
12
+ ListSIPInboundTrunkRequest,
13
+ ListSIPInboundTrunkResponse,
14
+ ListSIPOutboundTrunkRequest,
15
+ ListSIPOutboundTrunkResponse,
16
+ ListSIPTrunkRequest,
17
+ ListSIPTrunkResponse,
18
+ SIPDispatchRule,
19
+ SIPDispatchRuleDirect,
20
+ SIPDispatchRuleIndividual,
21
+ SIPDispatchRuleInfo,
22
+ SIPInboundTrunkInfo,
23
+ SIPOutboundTrunkInfo,
24
+ SIPParticipantInfo,
25
+ SIPTransport,
26
+ SIPTrunkInfo,
27
+ TransferSIPParticipantRequest
28
+ } from "@livekit/protocol";
29
+ import ServiceBase from "./ServiceBase.js";
30
+ import { TwirpRpc, livekitPackage } from "./TwirpRPC.js";
31
+ const svc = "SIP";
32
+ class SipClient extends ServiceBase {
33
+ /**
34
+ * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
35
+ * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
36
+ * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
37
+ */
38
+ constructor(host, apiKey, secret) {
39
+ super(apiKey, secret);
40
+ this.rpc = new TwirpRpc(host, livekitPackage);
41
+ }
42
+ /**
43
+ * @param number - phone number of the trunk
44
+ * @param opts - CreateSipTrunkOptions
45
+ * @deprecated use `createSipInboundTrunk` or `createSipOutboundTrunk`
46
+ */
47
+ async createSipTrunk(number, opts) {
48
+ let inboundAddresses;
49
+ let inboundNumbers;
50
+ let inboundUsername = "";
51
+ let inboundPassword = "";
52
+ let outboundAddress = "";
53
+ let outboundUsername = "";
54
+ let outboundPassword = "";
55
+ let name = "";
56
+ let metadata = "";
57
+ if (opts !== void 0) {
58
+ inboundAddresses = opts.inbound_addresses;
59
+ inboundNumbers = opts.inbound_numbers;
60
+ inboundUsername = opts.inbound_username || "";
61
+ inboundPassword = opts.inbound_password || "";
62
+ outboundAddress = opts.outbound_address || "";
63
+ outboundUsername = opts.outbound_username || "";
64
+ outboundPassword = opts.outbound_password || "";
65
+ name = opts.name || "";
66
+ metadata = opts.metadata || "";
20
67
  }
21
- /**
22
- * @param number - phone number of the trunk
23
- * @param opts - CreateSipTrunkOptions
24
- * @deprecated use `createSipInboundTrunk` or `createSipOutboundTrunk`
25
- */
26
- async createSipTrunk(number, opts) {
27
- let inboundAddresses;
28
- let inboundNumbers;
29
- let inboundUsername = '';
30
- let inboundPassword = '';
31
- let outboundAddress = '';
32
- let outboundUsername = '';
33
- let outboundPassword = '';
34
- let name = '';
35
- let metadata = '';
36
- if (opts !== undefined) {
37
- inboundAddresses = opts.inbound_addresses;
38
- inboundNumbers = opts.inbound_numbers;
39
- inboundUsername = opts.inbound_username || '';
40
- inboundPassword = opts.inbound_password || '';
41
- outboundAddress = opts.outbound_address || '';
42
- outboundUsername = opts.outbound_username || '';
43
- outboundPassword = opts.outbound_password || '';
44
- name = opts.name || '';
45
- metadata = opts.metadata || '';
46
- }
47
- const req = new CreateSIPTrunkRequest({
48
- name: name,
49
- metadata: metadata,
50
- inboundAddresses: inboundAddresses,
51
- inboundNumbers: inboundNumbers,
52
- inboundUsername: inboundUsername,
53
- inboundPassword: inboundPassword,
54
- outboundNumber: number,
55
- outboundAddress: outboundAddress,
56
- outboundUsername: outboundUsername,
57
- outboundPassword: outboundPassword,
58
- }).toJson();
59
- const data = await this.rpc.request(svc, 'CreateSIPTrunk', req, await this.authHeader({}, { admin: true }));
60
- return SIPTrunkInfo.fromJson(data, { ignoreUnknownFields: true });
61
- }
62
- /**
63
- * @param name - human-readable name of the trunk
64
- * @param numbers - phone numbers of the trunk
65
- * @param opts - CreateSipTrunkOptions
66
- */
67
- async createSipInboundTrunk(name, numbers, opts) {
68
- let allowedAddresses;
69
- let allowedNumbers;
70
- let authUsername = '';
71
- let authPassword = '';
72
- let metadata = '';
73
- if (opts !== undefined) {
74
- allowedAddresses = opts.allowed_addresses;
75
- allowedNumbers = opts.allowed_numbers;
76
- authUsername = opts.auth_username || '';
77
- authPassword = opts.auth_password || '';
78
- metadata = opts.metadata || '';
79
- }
80
- const req = new CreateSIPInboundTrunkRequest({
81
- trunk: new SIPInboundTrunkInfo({
82
- name: name,
83
- numbers: numbers,
84
- metadata: metadata,
85
- allowedAddresses: allowedAddresses,
86
- allowedNumbers: allowedNumbers,
87
- authUsername: authUsername,
88
- authPassword: authPassword,
89
- }),
90
- }).toJson();
91
- const data = await this.rpc.request(svc, 'CreateSIPInboundTrunk', req, await this.authHeader({}, { admin: true }));
92
- return SIPInboundTrunkInfo.fromJson(data, { ignoreUnknownFields: true });
93
- }
94
- /**
95
- * @param name - human-readable name of the trunk
96
- * @param address - hostname and port of the SIP server to dial
97
- * @param numbers - phone numbers of the trunk
98
- * @param opts - CreateSipTrunkOptions
99
- */
100
- async createSipOutboundTrunk(name, address, numbers, opts) {
101
- let authUsername = '';
102
- let authPassword = '';
103
- let transport = SIPTransport.SIP_TRANSPORT_AUTO;
104
- let metadata = '';
105
- if (opts !== undefined) {
106
- authUsername = opts.auth_username || '';
107
- authPassword = opts.auth_password || '';
108
- transport = opts.transport || SIPTransport.SIP_TRANSPORT_AUTO;
109
- metadata = opts.metadata || '';
110
- }
111
- const req = new CreateSIPOutboundTrunkRequest({
112
- trunk: new SIPOutboundTrunkInfo({
113
- name: name,
114
- address: address,
115
- numbers: numbers,
116
- metadata: metadata,
117
- transport: transport,
118
- authUsername: authUsername,
119
- authPassword: authPassword,
120
- }),
121
- }).toJson();
122
- const data = await this.rpc.request(svc, 'CreateSIPOutboundTrunk', req, await this.authHeader({}, { admin: true }));
123
- return SIPOutboundTrunkInfo.fromJson(data, { ignoreUnknownFields: true });
124
- }
125
- /**
126
- * @deprecated use `listSipInboundTrunk` or `listSipOutboundTrunk`
127
- */
128
- async listSipTrunk() {
129
- var _a;
130
- const req = {};
131
- const data = await this.rpc.request(svc, 'ListSIPTrunk', new ListSIPTrunkRequest(req).toJson(), await this.authHeader({}, { admin: true }));
132
- return (_a = ListSIPTrunkResponse.fromJson(data, { ignoreUnknownFields: true }).items) !== null && _a !== void 0 ? _a : [];
68
+ const req = new CreateSIPTrunkRequest({
69
+ name,
70
+ metadata,
71
+ inboundAddresses,
72
+ inboundNumbers,
73
+ inboundUsername,
74
+ inboundPassword,
75
+ outboundNumber: number,
76
+ outboundAddress,
77
+ outboundUsername,
78
+ outboundPassword
79
+ }).toJson();
80
+ const data = await this.rpc.request(
81
+ svc,
82
+ "CreateSIPTrunk",
83
+ req,
84
+ await this.authHeader({}, { admin: true })
85
+ );
86
+ return SIPTrunkInfo.fromJson(data, { ignoreUnknownFields: true });
87
+ }
88
+ /**
89
+ * @param name - human-readable name of the trunk
90
+ * @param numbers - phone numbers of the trunk
91
+ * @param opts - CreateSipTrunkOptions
92
+ */
93
+ async createSipInboundTrunk(name, numbers, opts) {
94
+ let allowedAddresses;
95
+ let allowedNumbers;
96
+ let authUsername = "";
97
+ let authPassword = "";
98
+ let metadata = "";
99
+ let headers = {};
100
+ let headersToAttributes = {};
101
+ if (opts !== void 0) {
102
+ allowedAddresses = opts.allowed_addresses;
103
+ allowedNumbers = opts.allowed_numbers;
104
+ authUsername = opts.auth_username || "";
105
+ authPassword = opts.auth_password || "";
106
+ metadata = opts.metadata || "";
107
+ headers = opts.headers || {};
108
+ headersToAttributes = opts.headersToAttributes || {};
133
109
  }
134
- async listSipInboundTrunk() {
135
- var _a;
136
- const req = {};
137
- const data = await this.rpc.request(svc, 'ListSIPInboundTrunk', new ListSIPInboundTrunkRequest(req).toJson(), await this.authHeader({}, { admin: true }));
138
- return (_a = ListSIPInboundTrunkResponse.fromJson(data, { ignoreUnknownFields: true }).items) !== null && _a !== void 0 ? _a : [];
110
+ const req = new CreateSIPInboundTrunkRequest({
111
+ trunk: new SIPInboundTrunkInfo({
112
+ name,
113
+ numbers,
114
+ metadata,
115
+ allowedAddresses,
116
+ allowedNumbers,
117
+ authUsername,
118
+ authPassword,
119
+ headers,
120
+ headersToAttributes
121
+ })
122
+ }).toJson();
123
+ const data = await this.rpc.request(
124
+ svc,
125
+ "CreateSIPInboundTrunk",
126
+ req,
127
+ await this.authHeader({}, { admin: true })
128
+ );
129
+ return SIPInboundTrunkInfo.fromJson(data, { ignoreUnknownFields: true });
130
+ }
131
+ /**
132
+ * @param name - human-readable name of the trunk
133
+ * @param address - hostname and port of the SIP server to dial
134
+ * @param numbers - phone numbers of the trunk
135
+ * @param opts - CreateSipTrunkOptions
136
+ */
137
+ async createSipOutboundTrunk(name, address, numbers, opts) {
138
+ let authUsername = "";
139
+ let authPassword = "";
140
+ let transport = SIPTransport.SIP_TRANSPORT_AUTO;
141
+ let metadata = "";
142
+ let headers = {};
143
+ let headersToAttributes = {};
144
+ if (opts !== void 0) {
145
+ authUsername = opts.auth_username || "";
146
+ authPassword = opts.auth_password || "";
147
+ transport = opts.transport || SIPTransport.SIP_TRANSPORT_AUTO;
148
+ metadata = opts.metadata || "";
149
+ headers = opts.headers || {};
150
+ headersToAttributes = opts.headersToAttributes || {};
139
151
  }
140
- async listSipOutboundTrunk() {
141
- var _a;
142
- const req = {};
143
- const data = await this.rpc.request(svc, 'ListSIPOutboundTrunk', new ListSIPOutboundTrunkRequest(req).toJson(), await this.authHeader({}, { admin: true }));
144
- return (_a = ListSIPOutboundTrunkResponse.fromJson(data, { ignoreUnknownFields: true }).items) !== null && _a !== void 0 ? _a : [];
152
+ const req = new CreateSIPOutboundTrunkRequest({
153
+ trunk: new SIPOutboundTrunkInfo({
154
+ name,
155
+ address,
156
+ numbers,
157
+ metadata,
158
+ transport,
159
+ authUsername,
160
+ authPassword,
161
+ headers,
162
+ headersToAttributes
163
+ })
164
+ }).toJson();
165
+ const data = await this.rpc.request(
166
+ svc,
167
+ "CreateSIPOutboundTrunk",
168
+ req,
169
+ await this.authHeader({}, { admin: true })
170
+ );
171
+ return SIPOutboundTrunkInfo.fromJson(data, { ignoreUnknownFields: true });
172
+ }
173
+ /**
174
+ * @deprecated use `listSipInboundTrunk` or `listSipOutboundTrunk`
175
+ */
176
+ async listSipTrunk() {
177
+ const req = {};
178
+ const data = await this.rpc.request(
179
+ svc,
180
+ "ListSIPTrunk",
181
+ new ListSIPTrunkRequest(req).toJson(),
182
+ await this.authHeader({}, { admin: true })
183
+ );
184
+ return ListSIPTrunkResponse.fromJson(data, { ignoreUnknownFields: true }).items ?? [];
185
+ }
186
+ async listSipInboundTrunk() {
187
+ const req = {};
188
+ const data = await this.rpc.request(
189
+ svc,
190
+ "ListSIPInboundTrunk",
191
+ new ListSIPInboundTrunkRequest(req).toJson(),
192
+ await this.authHeader({}, { admin: true })
193
+ );
194
+ return ListSIPInboundTrunkResponse.fromJson(data, { ignoreUnknownFields: true }).items ?? [];
195
+ }
196
+ async listSipOutboundTrunk() {
197
+ const req = {};
198
+ const data = await this.rpc.request(
199
+ svc,
200
+ "ListSIPOutboundTrunk",
201
+ new ListSIPOutboundTrunkRequest(req).toJson(),
202
+ await this.authHeader({}, { admin: true })
203
+ );
204
+ return ListSIPOutboundTrunkResponse.fromJson(data, { ignoreUnknownFields: true }).items ?? [];
205
+ }
206
+ /**
207
+ * @param sipTrunkId - sip trunk to delete
208
+ */
209
+ async deleteSipTrunk(sipTrunkId) {
210
+ const data = await this.rpc.request(
211
+ svc,
212
+ "DeleteSIPTrunk",
213
+ new DeleteSIPTrunkRequest({ sipTrunkId }).toJson(),
214
+ await this.authHeader({}, { admin: true })
215
+ );
216
+ return SIPTrunkInfo.fromJson(data, { ignoreUnknownFields: true });
217
+ }
218
+ /**
219
+ * @param rule - sip dispatch rule
220
+ * @param opts - CreateSipDispatchRuleOptions
221
+ */
222
+ async createSipDispatchRule(rule, opts) {
223
+ let trunkIds;
224
+ let hidePhoneNumber = false;
225
+ let name = "";
226
+ let metadata = "";
227
+ let ruleProto = void 0;
228
+ if (opts !== void 0) {
229
+ trunkIds = opts.trunkIds;
230
+ hidePhoneNumber = opts.hidePhoneNumber || false;
231
+ name = opts.name || "";
232
+ metadata = opts.metadata || "";
145
233
  }
146
- /**
147
- * @param sipTrunkId - sip trunk to delete
148
- */
149
- async deleteSipTrunk(sipTrunkId) {
150
- const data = await this.rpc.request(svc, 'DeleteSIPTrunk', new DeleteSIPTrunkRequest({ sipTrunkId }).toJson(), await this.authHeader({}, { admin: true }));
151
- return SIPTrunkInfo.fromJson(data, { ignoreUnknownFields: true });
152
- }
153
- /**
154
- * @param rule - sip dispatch rule
155
- * @param opts - CreateSipDispatchRuleOptions
156
- */
157
- async createSipDispatchRule(rule, opts) {
158
- let trunkIds;
159
- let hidePhoneNumber = false;
160
- let name = '';
161
- let metadata = '';
162
- let ruleProto = undefined;
163
- if (opts !== undefined) {
164
- trunkIds = opts.trunkIds;
165
- hidePhoneNumber = opts.hidePhoneNumber || false;
166
- name = opts.name || '';
167
- metadata = opts.metadata || '';
168
- }
169
- if (rule.type == 'direct') {
170
- ruleProto = new SIPDispatchRule({
171
- rule: {
172
- case: 'dispatchRuleDirect',
173
- value: new SIPDispatchRuleDirect({
174
- roomName: rule.roomName,
175
- pin: rule.pin || '',
176
- }),
177
- },
178
- });
234
+ if (rule.type == "direct") {
235
+ ruleProto = new SIPDispatchRule({
236
+ rule: {
237
+ case: "dispatchRuleDirect",
238
+ value: new SIPDispatchRuleDirect({
239
+ roomName: rule.roomName,
240
+ pin: rule.pin || ""
241
+ })
179
242
  }
180
- else if (rule.type == 'individual') {
181
- ruleProto = new SIPDispatchRule({
182
- rule: {
183
- case: 'dispatchRuleIndividual',
184
- value: new SIPDispatchRuleIndividual({
185
- roomPrefix: rule.roomPrefix,
186
- pin: rule.pin || '',
187
- }),
188
- },
189
- });
243
+ });
244
+ } else if (rule.type == "individual") {
245
+ ruleProto = new SIPDispatchRule({
246
+ rule: {
247
+ case: "dispatchRuleIndividual",
248
+ value: new SIPDispatchRuleIndividual({
249
+ roomPrefix: rule.roomPrefix,
250
+ pin: rule.pin || ""
251
+ })
190
252
  }
191
- const req = new CreateSIPDispatchRuleRequest({
192
- rule: ruleProto,
193
- trunkIds: trunkIds,
194
- hidePhoneNumber: hidePhoneNumber,
195
- name: name,
196
- metadata: metadata,
197
- }).toJson();
198
- const data = await this.rpc.request(svc, 'CreateSIPDispatchRule', req, await this.authHeader({}, { admin: true }));
199
- return SIPDispatchRuleInfo.fromJson(data, { ignoreUnknownFields: true });
200
- }
201
- async listSipDispatchRule() {
202
- var _a;
203
- const req = {};
204
- const data = await this.rpc.request(svc, 'ListSIPDispatchRule', new ListSIPDispatchRuleRequest(req).toJson(), await this.authHeader({}, { admin: true }));
205
- return (_a = ListSIPDispatchRuleResponse.fromJson(data, { ignoreUnknownFields: true }).items) !== null && _a !== void 0 ? _a : [];
253
+ });
206
254
  }
207
- /**
208
- * @param sipDispatchRuleId - sip trunk to delete
209
- */
210
- async deleteSipDispatchRule(sipDispatchRuleId) {
211
- const data = await this.rpc.request(svc, 'DeleteSIPDispatchRule', new DeleteSIPDispatchRuleRequest({ sipDispatchRuleId }).toJson(), await this.authHeader({}, { admin: true }));
212
- return SIPDispatchRuleInfo.fromJson(data, { ignoreUnknownFields: true });
255
+ const req = new CreateSIPDispatchRuleRequest({
256
+ rule: ruleProto,
257
+ trunkIds,
258
+ hidePhoneNumber,
259
+ name,
260
+ metadata
261
+ }).toJson();
262
+ const data = await this.rpc.request(
263
+ svc,
264
+ "CreateSIPDispatchRule",
265
+ req,
266
+ await this.authHeader({}, { admin: true })
267
+ );
268
+ return SIPDispatchRuleInfo.fromJson(data, { ignoreUnknownFields: true });
269
+ }
270
+ async listSipDispatchRule() {
271
+ const req = {};
272
+ const data = await this.rpc.request(
273
+ svc,
274
+ "ListSIPDispatchRule",
275
+ new ListSIPDispatchRuleRequest(req).toJson(),
276
+ await this.authHeader({}, { admin: true })
277
+ );
278
+ return ListSIPDispatchRuleResponse.fromJson(data, { ignoreUnknownFields: true }).items ?? [];
279
+ }
280
+ /**
281
+ * @param sipDispatchRuleId - sip trunk to delete
282
+ */
283
+ async deleteSipDispatchRule(sipDispatchRuleId) {
284
+ const data = await this.rpc.request(
285
+ svc,
286
+ "DeleteSIPDispatchRule",
287
+ new DeleteSIPDispatchRuleRequest({ sipDispatchRuleId }).toJson(),
288
+ await this.authHeader({}, { admin: true })
289
+ );
290
+ return SIPDispatchRuleInfo.fromJson(data, { ignoreUnknownFields: true });
291
+ }
292
+ /**
293
+ * @param sipTrunkId - sip trunk to use for the call
294
+ * @param number - number to dial
295
+ * @param roomName - room to attach the call to
296
+ * @param opts - CreateSipParticipantOptions
297
+ */
298
+ async createSipParticipant(sipTrunkId, number, roomName, opts) {
299
+ let participantIdentity = "";
300
+ let participantName = "";
301
+ let participantMetadata = "";
302
+ let dtmf = "";
303
+ let playRingtone = false;
304
+ let playDialtone = false;
305
+ let hidePhoneNumber = false;
306
+ let ringingTimeout = void 0;
307
+ let maxCallDuration = void 0;
308
+ let enableKrisp = void 0;
309
+ if (opts !== void 0) {
310
+ participantIdentity = opts.participantIdentity || "";
311
+ participantName = opts.participantName || "";
312
+ participantMetadata = opts.participantMetadata || "";
313
+ dtmf = opts.dtmf || "";
314
+ playRingtone = opts.playRingtone || false;
315
+ playDialtone = opts.playDialtone || playRingtone;
316
+ hidePhoneNumber = opts.hidePhoneNumber || false;
317
+ ringingTimeout = opts.ringingTimeout || void 0;
318
+ maxCallDuration = opts.maxCallDuration || void 0;
319
+ enableKrisp = opts.enableKrisp || void 0;
213
320
  }
214
- /**
215
- * @param sipTrunkId - sip trunk to use for the call
216
- * @param number - number to dial
217
- * @param roomName - room to attach the call to
218
- * @param opts - CreateSipParticipantOptions
219
- */
220
- async createSipParticipant(sipTrunkId, number, roomName, opts) {
221
- let participantIdentity = '';
222
- let participantName = '';
223
- let participantMetadata = '';
224
- let dtmf = '';
225
- let playRingtone = false;
226
- let playDialtone = false;
227
- let hidePhoneNumber = false;
228
- if (opts !== undefined) {
229
- participantIdentity = opts.participantIdentity || '';
230
- participantName = opts.participantName || '';
231
- participantMetadata = opts.participantMetadata || '';
232
- dtmf = opts.dtmf || '';
233
- playRingtone = opts.playRingtone || false;
234
- playDialtone = opts.playDialtone || playRingtone; // Enable PlayDialtone if either PlayDialtone or playRingtone is set
235
- hidePhoneNumber = opts.hidePhoneNumber || false;
236
- }
237
- const req = new CreateSIPParticipantRequest({
238
- sipTrunkId: sipTrunkId,
239
- sipCallTo: number,
240
- roomName: roomName,
241
- participantIdentity: participantIdentity,
242
- participantName: participantName,
243
- participantMetadata: participantMetadata,
244
- dtmf: dtmf,
245
- playRingtone: playDialtone,
246
- playDialtone: playDialtone,
247
- hidePhoneNumber: hidePhoneNumber,
248
- }).toJson();
249
- const data = await this.rpc.request(svc, 'CreateSIPParticipant', req, await this.authHeader({}, { call: true }));
250
- return SIPParticipantInfo.fromJson(data, { ignoreUnknownFields: true });
251
- }
252
- /**
253
- * @param roomName - room the SIP participant to transfer is connectd to
254
- * @param participantIdentity - identity of the SIP participant to transfer
255
- * @param transferTo - SIP URL to transfer the participant to
256
- */
257
- async transferSipParticipant(roomName, participantIdentity, transferTo, opts) {
258
- let playDialtone = false;
259
- if (opts !== undefined) {
260
- playDialtone = opts.playDialtone || false;
261
- }
262
- const req = new TransferSIPParticipantRequest({
263
- participantIdentity: participantIdentity,
264
- roomName: roomName,
265
- transferTo: transferTo,
266
- playDialtone: playDialtone,
267
- }).toJson();
268
- await this.rpc.request(svc, 'TransferSIPParticipant', req, await this.authHeader({ roomAdmin: true, room: roomName }, { call: true }));
321
+ const req = new CreateSIPParticipantRequest({
322
+ sipTrunkId,
323
+ sipCallTo: number,
324
+ roomName,
325
+ participantIdentity,
326
+ participantName,
327
+ participantMetadata,
328
+ dtmf,
329
+ playRingtone: playDialtone,
330
+ playDialtone,
331
+ hidePhoneNumber,
332
+ ringingTimeout: ringingTimeout ? new Duration({ seconds: BigInt(ringingTimeout) }) : void 0,
333
+ maxCallDuration: maxCallDuration ? new Duration({ seconds: BigInt(maxCallDuration) }) : void 0,
334
+ enableKrisp
335
+ }).toJson();
336
+ const data = await this.rpc.request(
337
+ svc,
338
+ "CreateSIPParticipant",
339
+ req,
340
+ await this.authHeader({}, { call: true })
341
+ );
342
+ return SIPParticipantInfo.fromJson(data, { ignoreUnknownFields: true });
343
+ }
344
+ /**
345
+ * @param roomName - room the SIP participant to transfer is connectd to
346
+ * @param participantIdentity - identity of the SIP participant to transfer
347
+ * @param transferTo - SIP URL to transfer the participant to
348
+ */
349
+ async transferSipParticipant(roomName, participantIdentity, transferTo, opts) {
350
+ let playDialtone = false;
351
+ if (opts !== void 0) {
352
+ playDialtone = opts.playDialtone || false;
269
353
  }
354
+ const req = new TransferSIPParticipantRequest({
355
+ participantIdentity,
356
+ roomName,
357
+ transferTo,
358
+ playDialtone
359
+ }).toJson();
360
+ await this.rpc.request(
361
+ svc,
362
+ "TransferSIPParticipant",
363
+ req,
364
+ await this.authHeader({ roomAdmin: true, room: roomName }, { call: true })
365
+ );
366
+ }
270
367
  }
368
+ export {
369
+ SipClient
370
+ };
271
371
  //# sourceMappingURL=SipClient.js.map