@openvertice/bot-sdk 0.1.0 → 0.1.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.
- package/README.md +12 -3
- package/dist/src/gateway.d.ts +6 -1
- package/dist/src/gateway.d.ts.map +1 -1
- package/dist/src/gateway.js +169 -37
- package/dist/src/gateway.js.map +1 -1
- package/package.json +5 -21
- package/src/audio.ts +0 -88
- package/src/cliente.ts +0 -472
- package/src/gateway.ts +0 -354
- package/src/http.ts +0 -249
- package/src/index.ts +0 -41
- package/src/tipos.ts +0 -220
- package/src/voz-wrtc.ts +0 -100
- package/src/voz.ts +0 -407
- package/src/wav.ts +0 -71
- package/src/wrtc.d.ts +0 -4
package/README.md
CHANGED
|
@@ -74,9 +74,11 @@ await bot.start();
|
|
|
74
74
|
|
|
75
75
|
O SDK cuida do que ninguém quer escrever duas vezes: troca o token por sessão,
|
|
76
76
|
renova antes de vencer, manda batimento, retoma com `resume` e reconecta com
|
|
77
|
-
espera crescente.
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
espera crescente. Falhas transitórias — servidor fora, rede caindo, sessão que
|
|
78
|
+
não pôde ser renovada — são tentadas **indefinidamente** (espera de 1 s até
|
|
79
|
+
30 s); desistir só acontece nos casos definitivos abaixo. Token girado, bot
|
|
80
|
+
desativado ou outra conexão assumindo o mesmo bot **não** reconectam:
|
|
81
|
+
`bot.estado` vira `recusado` e o erro fica em `bot.ultimoErro`.
|
|
80
82
|
|
|
81
83
|
## Mensagem de voz (áudio no chat)
|
|
82
84
|
|
|
@@ -155,6 +157,13 @@ rodar `node dist/exemplos/eco.js` de outro diretório.
|
|
|
155
157
|
|
|
156
158
|
## Testes
|
|
157
159
|
|
|
160
|
+
A reconexão do gateway tem teste próprio, **sem servidor** (usa um `WebSocket`
|
|
161
|
+
falso e o `dist/` compilado):
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
npm run build && node testes/gateway-reconexao.mjs # backoff, recusa, queda e fechar()
|
|
165
|
+
```
|
|
166
|
+
|
|
158
167
|
Os testes de fumaça sobem o servidor de verdade (precisa do repositório do
|
|
159
168
|
Vértice ao lado):
|
|
160
169
|
|
package/dist/src/gateway.d.ts
CHANGED
|
@@ -50,8 +50,13 @@ export declare class Gateway {
|
|
|
50
50
|
/**
|
|
51
51
|
* Opens the socket and resolves once the bot is identified (`ready`).
|
|
52
52
|
*
|
|
53
|
+
* Transient failures — network drops, an unreachable server, a session that
|
|
54
|
+
* could not be renewed, a gateway that never answers — are retried with
|
|
55
|
+
* exponential backoff until the bot is ready. Only a definitive refusal (or
|
|
56
|
+
* {@link fechar}) stops the loop.
|
|
57
|
+
*
|
|
53
58
|
* @returns A promise that settles when the gateway is truly ready.
|
|
54
|
-
* @throws {Error} When the server refuses the bot or the
|
|
59
|
+
* @throws {Error} When the server refuses the bot or the gateway was closed.
|
|
55
60
|
*/
|
|
56
61
|
conectar(): Promise<void>;
|
|
57
62
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/gateway.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/gateway.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAkBpE;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GACvB,YAAY,GACZ,QAAQ,GACR,cAAc,GACd,WAAW,GACX,UAAU,CAAC;AAEf,iEAAiE;AACjE,MAAM,WAAW,aAAa;IAC5B,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,0EAA0E;IAC1E,MAAM,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,uCAAuC;IACvC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC9B,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAC;IACpB,gDAAgD;IAChD,QAAQ,EAAE,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACjE,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/D,sDAAsD;IACtD,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAUD;;;;;;;;;GASG;AACH,qBAAa,OAAO;;IAmBN,OAAO,CAAC,QAAQ,CAAC,MAAM;IADnC,6EAA6E;gBAChD,MAAM,EAAE,aAAa;IAElD,gCAAgC;IAChC,IAAI,MAAM,IAAI,eAAe,CAE5B;IAED,qEAAqE;IACrE,IAAI,WAAW,IAAI,MAAM,GAAG,IAAI,CAE/B;IAED;;;;;;;;;;OAUG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IA6NzB;;;;;;;;;OASG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,IAAI;IAO7D;;;;;OAKG;IACH,MAAM,CAAC,MAAM,SAAO,EAAE,MAAM,SAAkB,GAAG,IAAI;CA0GtD"}
|
package/dist/src/gateway.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
const ABERTO = 1;
|
|
3
3
|
/** How long without any server frame before the connection is assumed dead. */
|
|
4
4
|
const SEM_SINAL_MS = 90_000;
|
|
5
|
+
/** Deadline for a new socket to answer `hello`/`ready` before the attempt is abandoned. */
|
|
6
|
+
const SEM_RESPOSTA_MS = 15_000;
|
|
5
7
|
/** Codes where retrying is pointless: the server refused the bot. */
|
|
6
8
|
const DEFINITIVOS = new Set([4001, 4003, 4005]);
|
|
7
9
|
/** Another connection took over this bot: reconnecting would fight over it. */
|
|
@@ -27,7 +29,14 @@ export class Gateway {
|
|
|
27
29
|
#seq = 0;
|
|
28
30
|
#batida = null;
|
|
29
31
|
#vigia = null;
|
|
32
|
+
/** Deadline of the attempt in progress (waiting for `hello`/`ready`). */
|
|
33
|
+
#prazo = null;
|
|
34
|
+
/** Backoff timer between attempts. */
|
|
30
35
|
#recuo = null;
|
|
36
|
+
/** Wakes the backoff early, so `fechar()` can settle a sleeping `conectar()`. */
|
|
37
|
+
#acordar = null;
|
|
38
|
+
/** Connection cycle in progress; one at a time, no matter who asks. */
|
|
39
|
+
#corrida = null;
|
|
31
40
|
#tentativa = 0;
|
|
32
41
|
#encerrado = false;
|
|
33
42
|
#estado = "conectando";
|
|
@@ -46,42 +55,150 @@ export class Gateway {
|
|
|
46
55
|
/**
|
|
47
56
|
* Opens the socket and resolves once the bot is identified (`ready`).
|
|
48
57
|
*
|
|
58
|
+
* Transient failures — network drops, an unreachable server, a session that
|
|
59
|
+
* could not be renewed, a gateway that never answers — are retried with
|
|
60
|
+
* exponential backoff until the bot is ready. Only a definitive refusal (or
|
|
61
|
+
* {@link fechar}) stops the loop.
|
|
62
|
+
*
|
|
49
63
|
* @returns A promise that settles when the gateway is truly ready.
|
|
50
|
-
* @throws {Error} When the server refuses the bot or the
|
|
64
|
+
* @throws {Error} When the server refuses the bot or the gateway was closed.
|
|
51
65
|
*/
|
|
52
66
|
conectar() {
|
|
53
67
|
this.#encerrado = false;
|
|
54
|
-
|
|
68
|
+
// Already identified: nothing to open, and a healthy socket is not replaced.
|
|
69
|
+
if (this.#estado === "pronto")
|
|
70
|
+
return Promise.resolve();
|
|
71
|
+
if (this.#corrida)
|
|
72
|
+
return this.#corrida;
|
|
73
|
+
// A manual start begins with the short backoff again.
|
|
74
|
+
this.#tentativa = 0;
|
|
75
|
+
return this.#iniciarCiclo();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Starts a connection cycle, or joins the one already running.
|
|
79
|
+
*
|
|
80
|
+
* @returns The cycle promise; it settles on `ready`, on a definitive refusal
|
|
81
|
+
* or when {@link fechar} is called.
|
|
82
|
+
*/
|
|
83
|
+
#iniciarCiclo() {
|
|
84
|
+
if (this.#corrida)
|
|
85
|
+
return this.#corrida;
|
|
86
|
+
const corrida = this.#manterConectado().finally(() => {
|
|
87
|
+
if (this.#corrida === corrida)
|
|
88
|
+
this.#corrida = null;
|
|
89
|
+
});
|
|
90
|
+
this.#corrida = corrida;
|
|
91
|
+
return corrida;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Attempts the connection and retries until `ready` or a definitive refusal.
|
|
95
|
+
*
|
|
96
|
+
* Every failure comes back through here — including the ones that happen
|
|
97
|
+
* before a socket exists, such as a session that could not be renewed. It is
|
|
98
|
+
* a loop on purpose: a single retry used to end the reconnection, leaving the
|
|
99
|
+
* bot offline for good.
|
|
100
|
+
*/
|
|
101
|
+
async #manterConectado() {
|
|
102
|
+
for (;;) {
|
|
103
|
+
// `fechar()` may have run while we were sleeping in the backoff.
|
|
104
|
+
if (this.#encerrado)
|
|
105
|
+
throw new Error("gateway encerrado");
|
|
106
|
+
try {
|
|
107
|
+
await this.#abrir();
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
catch (erro) {
|
|
111
|
+
if (this.#encerrado)
|
|
112
|
+
throw erro;
|
|
113
|
+
await this.#esperarRecuo(erro);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Waits out the backoff before the next attempt.
|
|
119
|
+
*
|
|
120
|
+
* The wait is interruptible: {@link fechar} wakes it, so a `conectar()` call
|
|
121
|
+
* sleeping here settles instead of hanging until the timer fires.
|
|
122
|
+
*
|
|
123
|
+
* @param erro Failure that triggered the wait; it goes into the state detail.
|
|
124
|
+
*/
|
|
125
|
+
async #esperarRecuo(erro) {
|
|
126
|
+
this.#tentativa += 1;
|
|
127
|
+
const espera = Math.min(30_000, 500 * 2 ** Math.min(this.#tentativa, 6));
|
|
128
|
+
this.#mudar("reconectando", `${mensagemDe(erro)}: volta em ${espera} ms (tentativa ${this.#tentativa})`);
|
|
129
|
+
await new Promise((resolver) => {
|
|
130
|
+
this.#acordar = () => {
|
|
131
|
+
this.#acordar = null;
|
|
132
|
+
if (this.#recuo)
|
|
133
|
+
clearTimeout(this.#recuo);
|
|
134
|
+
this.#recuo = null;
|
|
135
|
+
resolver();
|
|
136
|
+
};
|
|
137
|
+
this.#recuo = setTimeout(() => this.#acordar?.(), espera);
|
|
138
|
+
this.#recuo.unref?.();
|
|
139
|
+
});
|
|
55
140
|
}
|
|
56
141
|
/**
|
|
57
142
|
* Opens one socket attempt.
|
|
58
143
|
*
|
|
59
|
-
* Resolves on
|
|
60
|
-
*
|
|
144
|
+
* Resolves on `ready` and rejects on any failure before it (socket error,
|
|
145
|
+
* close, no answer within {@link SEM_RESPOSTA_MS}, session error), which is
|
|
146
|
+
* what lets {@link #manterConectado} decide when to try again.
|
|
61
147
|
*/
|
|
62
148
|
async #abrir() {
|
|
63
149
|
this.#mudar("conectando");
|
|
64
150
|
const sessao = await this.opcoes.sessao();
|
|
151
|
+
// `fechar()` may have run while the session was being fetched: do not open
|
|
152
|
+
// a socket that nobody is waiting for.
|
|
153
|
+
if (this.#encerrado)
|
|
154
|
+
throw new Error("gateway encerrado");
|
|
65
155
|
this.#sessao = sessao;
|
|
66
156
|
return new Promise((resolver, rejeitar) => {
|
|
67
157
|
let concluido = false;
|
|
68
|
-
const
|
|
158
|
+
const concluir = (erro) => {
|
|
69
159
|
if (concluido)
|
|
70
160
|
return;
|
|
71
161
|
concluido = true;
|
|
72
|
-
|
|
162
|
+
if (this.#prazo)
|
|
163
|
+
clearTimeout(this.#prazo);
|
|
164
|
+
this.#prazo = null;
|
|
165
|
+
if (erro)
|
|
166
|
+
rejeitar(erro);
|
|
167
|
+
else
|
|
168
|
+
resolver();
|
|
73
169
|
};
|
|
74
170
|
let ws;
|
|
75
171
|
try {
|
|
76
172
|
ws = new WebSocket(this.opcoes.url);
|
|
77
173
|
}
|
|
78
174
|
catch (erro) {
|
|
79
|
-
|
|
175
|
+
concluir(erro instanceof Error ? erro : new Error(String(erro)));
|
|
80
176
|
return;
|
|
81
177
|
}
|
|
82
178
|
this.#ws = ws;
|
|
83
|
-
|
|
179
|
+
// A socket that opens but never answers would hang this attempt (and the
|
|
180
|
+
// retry loop) forever; the deadline settles it as a failure.
|
|
181
|
+
this.#prazo = setTimeout(() => {
|
|
182
|
+
this.#prazo = null;
|
|
183
|
+
if (this.#ws !== ws)
|
|
184
|
+
return;
|
|
185
|
+
try {
|
|
186
|
+
ws.close(4000, "sem resposta");
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
/* it had already dropped */
|
|
190
|
+
}
|
|
191
|
+
concluir(new Error("o gateway não respondeu ao `identify`"));
|
|
192
|
+
}, SEM_RESPOSTA_MS);
|
|
193
|
+
this.#prazo.unref?.();
|
|
194
|
+
ws.addEventListener("error", () => {
|
|
195
|
+
if (this.#ws !== ws)
|
|
196
|
+
return;
|
|
197
|
+
concluir(new Error("não consegui abrir o gateway"));
|
|
198
|
+
});
|
|
84
199
|
ws.addEventListener("message", (evento) => {
|
|
200
|
+
if (this.#ws !== ws)
|
|
201
|
+
return;
|
|
85
202
|
const envelope = this.#ler(evento);
|
|
86
203
|
if (!envelope)
|
|
87
204
|
return;
|
|
@@ -91,17 +208,24 @@ export class Gateway {
|
|
|
91
208
|
this.#identificar(ws, sessao);
|
|
92
209
|
return;
|
|
93
210
|
}
|
|
94
|
-
this.#receber(envelope, () =>
|
|
95
|
-
if (concluido)
|
|
96
|
-
return;
|
|
97
|
-
concluido = true;
|
|
98
|
-
resolver();
|
|
99
|
-
});
|
|
211
|
+
this.#receber(envelope, () => concluir());
|
|
100
212
|
});
|
|
101
213
|
ws.addEventListener("close", (evento) => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
214
|
+
// A close from a socket that is no longer the current one is residue
|
|
215
|
+
// from a previous attempt: it must not touch the live connection.
|
|
216
|
+
if (this.#ws !== ws)
|
|
217
|
+
return;
|
|
218
|
+
const estavaPronto = this.#estado === "pronto";
|
|
219
|
+
const definitivo = this.#aoFechar(evento.code, evento.reason);
|
|
220
|
+
concluir(new Error(this.#estado === "encerrado"
|
|
221
|
+
? "gateway encerrado"
|
|
222
|
+
: `gateway ${definitivo ? "recusado" : "caiu"} (${evento.code})`));
|
|
223
|
+
// After `ready` there is no attempt left to fail — the loop already
|
|
224
|
+
// returned — so a drop has to start a new cycle.
|
|
225
|
+
if (!definitivo && estavaPronto) {
|
|
226
|
+
this.#corrida = null;
|
|
227
|
+
void this.#iniciarCiclo().catch(() => { });
|
|
228
|
+
}
|
|
105
229
|
});
|
|
106
230
|
});
|
|
107
231
|
}
|
|
@@ -187,13 +311,16 @@ export class Gateway {
|
|
|
187
311
|
fechar(codigo = 1000, motivo = "pedido do bot") {
|
|
188
312
|
this.#encerrado = true;
|
|
189
313
|
this.#limpar();
|
|
314
|
+
// Nothing else to wait for: wake a `conectar()` that is sleeping in backoff.
|
|
315
|
+
this.#acordar?.();
|
|
190
316
|
try {
|
|
191
317
|
this.#ws?.close(codigo, motivo);
|
|
192
318
|
}
|
|
193
319
|
catch {
|
|
194
320
|
/* it was already closing */
|
|
195
321
|
}
|
|
196
|
-
|
|
322
|
+
// `#ws` is cleared by the close handler: it has to settle the attempt in
|
|
323
|
+
// progress, otherwise a `conectar()` waiting on it would never return.
|
|
197
324
|
this.#mudar("encerrado");
|
|
198
325
|
}
|
|
199
326
|
/**
|
|
@@ -246,54 +373,59 @@ export class Gateway {
|
|
|
246
373
|
this.#vigia.unref?.();
|
|
247
374
|
}
|
|
248
375
|
/**
|
|
249
|
-
*
|
|
376
|
+
* Applies the close policy: stop for good or let the caller reconnect.
|
|
250
377
|
*
|
|
251
378
|
* @param codigo WebSocket close code.
|
|
252
379
|
* @param motivo Close reason, used in the log and in the state detail.
|
|
380
|
+
* @returns `true` when the bot must stop; `false` when a retry makes sense.
|
|
253
381
|
*/
|
|
254
382
|
#aoFechar(codigo, motivo) {
|
|
255
383
|
this.#limpar();
|
|
256
384
|
this.#ws = null;
|
|
257
385
|
if (this.#encerrado)
|
|
258
|
-
return;
|
|
386
|
+
return true;
|
|
259
387
|
if (DEFINITIVOS.has(codigo)) {
|
|
260
388
|
this.#mudar("recusado", `${codigo}: ${motivo}`);
|
|
261
389
|
this.#encerrado = true;
|
|
262
|
-
return;
|
|
390
|
+
return true;
|
|
263
391
|
}
|
|
264
392
|
if (codigo === OUTRA_CONEXAO) {
|
|
265
393
|
this.#mudar("recusado", "outra conexão assumiu este bot");
|
|
266
394
|
this.#encerrado = true;
|
|
267
|
-
return;
|
|
395
|
+
return true;
|
|
268
396
|
}
|
|
269
397
|
if (codigo === SESSAO_ENCERRADA) {
|
|
270
398
|
this.#mudar("recusado", "a sessão foi encerrada (token girado ou bot desativado)");
|
|
271
399
|
this.#encerrado = true;
|
|
272
|
-
return;
|
|
400
|
+
return true;
|
|
273
401
|
}
|
|
274
402
|
// 4002 (expired session) and network drops: renew the session and come back.
|
|
275
|
-
|
|
276
|
-
const espera = Math.min(30_000, 500 * 2 ** Math.min(this.#tentativa, 6));
|
|
277
|
-
this.#mudar("reconectando", `${codigo || "sem código"}: volta em ${espera} ms (tentativa ${this.#tentativa})`);
|
|
278
|
-
this.#recuo = setTimeout(() => {
|
|
279
|
-
if (this.#encerrado)
|
|
280
|
-
return;
|
|
281
|
-
// On an expired session, the client's `sessao()` already asks for another one.
|
|
282
|
-
this.#abrir().catch((erro) => this.#mudar("reconectando", `falhou: ${erro.message}`));
|
|
283
|
-
}, espera);
|
|
284
|
-
this.#recuo.unref?.();
|
|
403
|
+
return false;
|
|
285
404
|
}
|
|
286
|
-
/**
|
|
405
|
+
/**
|
|
406
|
+
* Clears the timers of a live connection (heartbeat, silence watch, attempt
|
|
407
|
+
* deadline), so a closed gateway leaves no handles behind.
|
|
408
|
+
*
|
|
409
|
+
* The backoff timer is not touched here: it belongs to {@link #esperarRecuo},
|
|
410
|
+
* which is woken by {@link fechar}.
|
|
411
|
+
*/
|
|
287
412
|
#limpar() {
|
|
288
413
|
if (this.#batida)
|
|
289
414
|
clearInterval(this.#batida);
|
|
290
415
|
if (this.#vigia)
|
|
291
416
|
clearTimeout(this.#vigia);
|
|
292
|
-
if (this.#
|
|
293
|
-
clearTimeout(this.#
|
|
417
|
+
if (this.#prazo)
|
|
418
|
+
clearTimeout(this.#prazo);
|
|
294
419
|
this.#batida = null;
|
|
295
420
|
this.#vigia = null;
|
|
296
|
-
this.#
|
|
421
|
+
this.#prazo = null;
|
|
297
422
|
}
|
|
298
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* Turns any thrown value into a printable message.
|
|
426
|
+
*
|
|
427
|
+
* @param erro Value thrown or rejected.
|
|
428
|
+
* @returns `erro.message` for `Error`s, `String(erro)` otherwise.
|
|
429
|
+
*/
|
|
430
|
+
const mensagemDe = (erro) => erro instanceof Error ? erro.message : String(erro);
|
|
299
431
|
//# sourceMappingURL=gateway.js.map
|
package/dist/src/gateway.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../src/gateway.ts"],"names":[],"mappings":"AAOA,iDAAiD;AACjD,MAAM,MAAM,GAAG,CAAC,CAAC;AACjB,+EAA+E;AAC/E,MAAM,YAAY,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../src/gateway.ts"],"names":[],"mappings":"AAOA,iDAAiD;AACjD,MAAM,MAAM,GAAG,CAAC,CAAC;AACjB,+EAA+E;AAC/E,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,2FAA2F;AAC3F,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,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,MAAM;YAAE,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3C,IAAI,IAAI,CAAC,MAAM;YAAE,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC3C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,GAAG,CAAC,IAAa,EAAU,EAAE,CAC3C,IAAI,YAAY,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openvertice/bot-sdk",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "SDK para escrever bots do Vértice: gateway, mensagens e
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "SDK para escrever bots do Vértice: gateway, mensagens e (em breve) voz",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|
|
7
7
|
"types": "./dist/src/index.d.ts",
|
|
@@ -9,12 +9,10 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/src/index.d.ts",
|
|
11
11
|
"import": "./dist/src/index.js"
|
|
12
|
-
}
|
|
13
|
-
"./package.json": "./package.json"
|
|
12
|
+
}
|
|
14
13
|
},
|
|
15
14
|
"files": [
|
|
16
15
|
"dist/src",
|
|
17
|
-
"src",
|
|
18
16
|
"README.md"
|
|
19
17
|
],
|
|
20
18
|
"engines": {
|
|
@@ -22,7 +20,6 @@
|
|
|
22
20
|
},
|
|
23
21
|
"scripts": {
|
|
24
22
|
"build": "tsc -p tsconfig.json",
|
|
25
|
-
"prepack": "npm run build",
|
|
26
23
|
"eco": "node dist/exemplos/eco.js",
|
|
27
24
|
"radio": "node dist/exemplos/radio.js",
|
|
28
25
|
"recado": "node dist/exemplos/recado.js"
|
|
@@ -35,27 +32,14 @@
|
|
|
35
32
|
"@types/node": "^22.10.0",
|
|
36
33
|
"typescript": "^5.6.0"
|
|
37
34
|
},
|
|
38
|
-
"
|
|
39
|
-
"type": "git",
|
|
40
|
-
"url": "git+https://github.com/Vortex-SA/vertice-bot-sdk.git"
|
|
41
|
-
},
|
|
42
|
-
"homepage": "https://github.com/Vortex-SA/vertice-bot-sdk#readme",
|
|
43
|
-
"bugs": {
|
|
44
|
-
"url": "https://github.com/Vortex-SA/vertice-bot-sdk/issues"
|
|
45
|
-
},
|
|
46
|
-
"author": "OpenVertice",
|
|
47
|
-
"license": "UNLICENSED",
|
|
35
|
+
"license": "MIT",
|
|
48
36
|
"publishConfig": {
|
|
49
37
|
"access": "public"
|
|
50
38
|
},
|
|
51
39
|
"keywords": [
|
|
52
40
|
"vertice",
|
|
53
|
-
"openvertice",
|
|
54
41
|
"bot",
|
|
55
|
-
"sdk",
|
|
56
|
-
"gateway",
|
|
57
|
-
"websocket",
|
|
58
42
|
"webrtc",
|
|
59
|
-
"
|
|
43
|
+
"sdk"
|
|
60
44
|
]
|
|
61
45
|
}
|
package/src/audio.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// What the bot plays: a pure tone, with no file and no dependency.
|
|
2
|
-
//
|
|
3
|
-
// The source comes from the transport (`RTCAudioSource` in wrtc): it receives
|
|
4
|
-
// 10 ms blocks — 480 samples at 48 kHz, the only frame size wrtc accepts. This
|
|
5
|
-
// is the shortest possible "real audio" example; reading a file is just feeding
|
|
6
|
-
// the same source from somewhere else.
|
|
7
|
-
import type { FonteDeAudio } from "./voz.js";
|
|
8
|
-
|
|
9
|
-
/** Audio source that accepts raw PCM blocks (the shape `RTCAudioSource` has). */
|
|
10
|
-
interface FonteComDados extends FonteDeAudio {
|
|
11
|
-
/** Pushes one PCM block into the source. */
|
|
12
|
-
onData(dados: {
|
|
13
|
-
/** Interleaved signed 16-bit samples. */
|
|
14
|
-
samples: Int16Array;
|
|
15
|
-
/** Sample rate in Hz (48 kHz for wrtc). */
|
|
16
|
-
sampleRate: number;
|
|
17
|
-
/** Bits per sample (16). */
|
|
18
|
-
bitsPerSample: number;
|
|
19
|
-
/** Number of channels (1 = mono). */
|
|
20
|
-
channelCount: number;
|
|
21
|
-
/** Frames in this block (480 at 48 kHz, i.e. 10 ms). */
|
|
22
|
-
numberOfFrames: number;
|
|
23
|
-
}): void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Everything `tocarTom` needs in order to publish a sine wave. */
|
|
27
|
-
export interface OpcoesDoTom {
|
|
28
|
-
/** The transport source (`transporte.criarFonteDeAudio()`). */
|
|
29
|
-
fonte: FonteDeAudio;
|
|
30
|
-
/** Frequency in Hz. 440 is concert A. */
|
|
31
|
-
frequencia?: number;
|
|
32
|
-
/** 0…1. Anything above 0.5 starts to clip and distort. */
|
|
33
|
-
amplitude?: number;
|
|
34
|
-
/** 48 kHz: wrtc requires blocks of 480 samples. */
|
|
35
|
-
sampleRate?: number;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Starts playing the tone on the given source.
|
|
40
|
-
*
|
|
41
|
-
* Keep the returned stop function for as long as the bot stays in the room:
|
|
42
|
-
* stopping mid-flight leaves the peer with silence, not with an error — which
|
|
43
|
-
* is exactly what a bot that stops speaking should do.
|
|
44
|
-
*
|
|
45
|
-
* @param options Tone parameters; every field has a sensible default.
|
|
46
|
-
* @returns A function that stops the tone and clears its timer.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```ts
|
|
50
|
-
* const fonte = transporte.criarFonteDeAudio();
|
|
51
|
-
* const parar = tocarTom({ fonte, frequencia: 440, amplitude: 0.15 });
|
|
52
|
-
* // …later, on shutdown:
|
|
53
|
-
* parar();
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export function tocarTom({
|
|
57
|
-
fonte,
|
|
58
|
-
frequencia = 440,
|
|
59
|
-
amplitude = 0.2,
|
|
60
|
-
sampleRate = 48_000,
|
|
61
|
-
}: OpcoesDoTom): () => void {
|
|
62
|
-
const comDados = fonte as FonteComDados;
|
|
63
|
-
// 10 ms per block: it is the frame size of wrtc's RTCAudioSource.
|
|
64
|
-
const quadros = Math.round(sampleRate / 100);
|
|
65
|
-
const passo = (2 * Math.PI * frequencia) / sampleRate;
|
|
66
|
-
const limite = Math.max(0, Math.min(1, amplitude)) * 0x7fff;
|
|
67
|
-
let fase = 0;
|
|
68
|
-
|
|
69
|
-
const timer = setInterval(() => {
|
|
70
|
-
const amostras = new Int16Array(quadros);
|
|
71
|
-
for (let i = 0; i < quadros; i += 1) {
|
|
72
|
-
amostras[i] = Math.round(Math.sin(fase) * limite);
|
|
73
|
-
fase += passo;
|
|
74
|
-
if (fase > 2 * Math.PI) fase -= 2 * Math.PI;
|
|
75
|
-
}
|
|
76
|
-
comDados.onData({
|
|
77
|
-
samples: amostras,
|
|
78
|
-
sampleRate,
|
|
79
|
-
bitsPerSample: 16,
|
|
80
|
-
channelCount: 1,
|
|
81
|
-
numberOfFrames: quadros,
|
|
82
|
-
});
|
|
83
|
-
}, 10);
|
|
84
|
-
// Without `unref` the process would not exit while the tone plays — and the
|
|
85
|
-
// bot must be able to leave the room and still shut down cleanly.
|
|
86
|
-
timer.unref?.();
|
|
87
|
-
return () => clearInterval(timer);
|
|
88
|
-
}
|