@raucheacho/phono-web 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +41 -2
- package/assets/goul-audio.wasm +0 -0
- package/assets/goul-ptt-worklets.js +256 -0
- package/dist/announcements.d.ts +23 -0
- package/dist/audio.d.ts +79 -0
- package/dist/client.d.ts +265 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1204 -0
- package/dist/phone.d.ts +110 -0
- package/dist/react.d.ts +13 -0
- package/dist/react.js +18 -0
- package/dist/realtime.d.ts +39 -0
- package/dist/talkie.d.ts +85 -0
- package/dist/tones.d.ts +14 -0
- package/dist/types.d.ts +284 -0
- package/dist/types.js +0 -0
- package/package.json +53 -4
- package/src/announcements.ts +57 -0
- package/src/audio.ts +313 -0
- package/src/client.ts +433 -0
- package/src/index.ts +13 -0
- package/src/phone.ts +340 -0
- package/src/react.ts +34 -0
- package/src/realtime.ts +174 -0
- package/src/talkie.ts +342 -0
- package/src/tones.ts +58 -0
- package/src/types.ts +339 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rauche Acho
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @raucheacho/phono-web
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Un téléphone Phono dans le navigateur — sonner, appeler, décrocher, parler —
|
|
4
|
+
et le client de l'API (messages, conversations, temps réel). Le dashboard
|
|
5
|
+
Phono est construit dessus.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { Phono } from "@raucheacho/phono-web";
|
|
9
|
+
|
|
10
|
+
const phono = new Phono({
|
|
11
|
+
baseUrl: "https://phonoapi.raucheacho.com",
|
|
12
|
+
token: () => fetch("/api/phono-token", { method: "POST" }).then((r) => r.text()),
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const phone = phono.phone();
|
|
16
|
+
phone.subscribe((s) => render(s));
|
|
17
|
+
await phone.start();
|
|
18
|
+
button.onclick = () => phone.dial("jean.acme");
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Avec React : `import { usePhone, usePhonoEvent } from "@raucheacho/phono-web/react"`.
|
|
22
|
+
|
|
23
|
+
## Le cœur audio
|
|
24
|
+
|
|
25
|
+
`assets/goul-ptt-worklets.js` et `assets/goul-audio.wasm` sont à servir avec la
|
|
26
|
+
page — par défaut à la racine (`/goul-ptt-worklets.js`, `/goul-audio.wasm`),
|
|
27
|
+
sinon `new Phono({ …, audio: { workletUrl, wasmUrl } })`. Ils sont construits
|
|
28
|
+
par [raucheacho/goul](https://github.com/raucheacho/goul) et livrés par la
|
|
29
|
+
dépendance `@raucheacho/goul-audio-web`, d'où `bun run goul-assets` les copie
|
|
30
|
+
(lancé seul avant `build` et `pack`).
|
|
31
|
+
|
|
32
|
+
## Tests
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
bun test # le client
|
|
36
|
+
PHONO_URL=http://localhost:8089 PHONO_SERVER_KEY=phs_… bun test test/e2e.test.ts
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Le second crée deux identités avec la clé serveur, leur délivre des jetons
|
|
40
|
+
clients, et les fait s'écrire et s'appeler contre une vraie API.
|
|
41
|
+
|
|
42
|
+
Documentation : `apps/doc-site/content/sdks/web.mdx`.
|
|
Binary file
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Les deux bouts de la chaîne audio, sur le fil du temps réel.
|
|
3
|
+
*
|
|
4
|
+
* An AudioWorklet runs on the audio rendering thread, which is the only clock
|
|
5
|
+
* that matters here: `process()` is called every 128 samples whatever the main
|
|
6
|
+
* thread is doing. Both the encoder and the play-out buffer live on this side
|
|
7
|
+
* for that reason — a jitter buffer pulled from `setInterval` would drift
|
|
8
|
+
* exactly when the page is busy, which is when it matters most.
|
|
9
|
+
*
|
|
10
|
+
* The WebAssembly module arrives as **bytes**, and is compiled here.
|
|
11
|
+
*
|
|
12
|
+
* Not as a compiled `WebAssembly.Module`, which would save the compile: a
|
|
13
|
+
* Module is serializable only within one agent cluster, and a worklet is its
|
|
14
|
+
* own. Posting one across is dropped silently — no exception on the sending
|
|
15
|
+
* side, no `messageerror`, just a message that never arrives. Sending the
|
|
16
|
+
* bytes costs a few milliseconds of compile per worklet and cannot fail that
|
|
17
|
+
* way.
|
|
18
|
+
*
|
|
19
|
+
* `fetch` does not exist in an AudioWorkletGlobalScope, which is why the bytes
|
|
20
|
+
* come from the page rather than being loaded here.
|
|
21
|
+
*
|
|
22
|
+
* A note on arithmetic that shapes everything below: a render quantum is 128
|
|
23
|
+
* samples and an Opus frame is 960. They do not divide, so both processors
|
|
24
|
+
* bridge the mismatch with a small reservoir rather than pretending the two
|
|
25
|
+
* clocks line up.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const FRAME_SAMPLES = 960;
|
|
29
|
+
|
|
30
|
+
/** Int16 full scale. Kept explicit — the asymmetry of two's complement is why
|
|
31
|
+
* clamping uses 32767 on the way up and 32768 on the way down. */
|
|
32
|
+
const INT16_MAX = 32767;
|
|
33
|
+
const INT16_MIN = -32768;
|
|
34
|
+
|
|
35
|
+
function floatToInt16(sample) {
|
|
36
|
+
const scaled = sample * 32768;
|
|
37
|
+
return scaled > INT16_MAX ? INT16_MAX : scaled < INT16_MIN ? INT16_MIN : scaled | 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Capture : microphone → trames prêtes à envoyer.
|
|
42
|
+
*
|
|
43
|
+
* Encoding happens here rather than on the main thread so that what crosses
|
|
44
|
+
* the thread boundary is a ~57-byte frame instead of 1920 bytes of raw PCM,
|
|
45
|
+
* fifty times a second.
|
|
46
|
+
*/
|
|
47
|
+
class GoulCaptureProcessor extends AudioWorkletProcessor {
|
|
48
|
+
constructor() {
|
|
49
|
+
super();
|
|
50
|
+
|
|
51
|
+
this.wasm = null;
|
|
52
|
+
this.sending = false;
|
|
53
|
+
|
|
54
|
+
// One frame's worth of microphone, filled 128 samples at a time.
|
|
55
|
+
this.pending = new Int16Array(FRAME_SAMPLES);
|
|
56
|
+
this.pendingCount = 0;
|
|
57
|
+
|
|
58
|
+
this.port.onmessage = ({ data }) => this.handle(data);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
handle(message) {
|
|
62
|
+
if (message.type === "init") {
|
|
63
|
+
this.instantiate(message.bytes);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!this.wasm) return;
|
|
68
|
+
|
|
69
|
+
if (message.type === "start") {
|
|
70
|
+
// A fresh stream must not inherit half a frame from the previous press.
|
|
71
|
+
this.pendingCount = 0;
|
|
72
|
+
const code = this.wasm.goul_send_open(message.streamId >>> 0, message.bitrate);
|
|
73
|
+
this.sending = code === 0;
|
|
74
|
+
if (!this.sending) this.port.postMessage({ type: "error", code });
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (message.type === "stop") {
|
|
79
|
+
this.sending = false;
|
|
80
|
+
this.wasm.goul_send_close();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Compilation is asynchronous; `ready` is what says the module is usable. */
|
|
85
|
+
instantiate(bytes) {
|
|
86
|
+
WebAssembly.instantiate(bytes, {}).then(
|
|
87
|
+
({ instance }) => {
|
|
88
|
+
instance.exports._initialize();
|
|
89
|
+
this.wasm = instance.exports;
|
|
90
|
+
this.port.postMessage({ type: "ready" });
|
|
91
|
+
},
|
|
92
|
+
(error) => this.port.postMessage({ type: "error", message: String(error) })
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
process(inputs) {
|
|
97
|
+
const channel = inputs[0]?.[0];
|
|
98
|
+
|
|
99
|
+
// No input yet, or nothing to do: keep the node alive either way. Returning
|
|
100
|
+
// false would end this processor for good, and the button can be pressed
|
|
101
|
+
// again.
|
|
102
|
+
if (!this.sending || !channel) return true;
|
|
103
|
+
|
|
104
|
+
for (let i = 0; i < channel.length; i++) {
|
|
105
|
+
this.pending[this.pendingCount++] = floatToInt16(channel[i]);
|
|
106
|
+
|
|
107
|
+
if (this.pendingCount === FRAME_SAMPLES) {
|
|
108
|
+
this.pendingCount = 0;
|
|
109
|
+
this.emitFrame();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
emitFrame() {
|
|
117
|
+
const w = this.wasm;
|
|
118
|
+
const pcmPtr = w.goul_pcm_buffer();
|
|
119
|
+
const framePtr = w.goul_frame_buffer();
|
|
120
|
+
|
|
121
|
+
new Int16Array(w.memory.buffer, pcmPtr, FRAME_SAMPLES).set(this.pending);
|
|
122
|
+
|
|
123
|
+
const written = w.goul_send_push(
|
|
124
|
+
pcmPtr,
|
|
125
|
+
FRAME_SAMPLES,
|
|
126
|
+
framePtr,
|
|
127
|
+
w.goul_frame_buffer_cap()
|
|
128
|
+
);
|
|
129
|
+
if (written <= 0) {
|
|
130
|
+
this.port.postMessage({ type: "error", code: written });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Copied, because the module reuses this buffer for the next frame and
|
|
135
|
+
// postMessage is asynchronous.
|
|
136
|
+
const frame = new Uint8Array(written);
|
|
137
|
+
frame.set(new Uint8Array(w.memory.buffer, framePtr, written));
|
|
138
|
+
|
|
139
|
+
this.port.postMessage({ type: "frame", frame }, [frame.buffer]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Lecture : trames reçues → haut-parleur.
|
|
145
|
+
*
|
|
146
|
+
* The play-out buffer lives inside the WebAssembly module; this processor only
|
|
147
|
+
* turns its 960-sample answers into 128-sample render quanta.
|
|
148
|
+
*/
|
|
149
|
+
class GoulPlaybackProcessor extends AudioWorkletProcessor {
|
|
150
|
+
constructor() {
|
|
151
|
+
super();
|
|
152
|
+
|
|
153
|
+
this.wasm = null;
|
|
154
|
+
this.open = false;
|
|
155
|
+
|
|
156
|
+
// Decoded audio waiting to be handed out 128 samples at a time.
|
|
157
|
+
this.reservoir = new Int16Array(FRAME_SAMPLES);
|
|
158
|
+
this.reservoirLength = 0;
|
|
159
|
+
this.reservoirRead = 0;
|
|
160
|
+
|
|
161
|
+
this.port.onmessage = ({ data }) => this.handle(data);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
handle(message) {
|
|
165
|
+
if (message.type === "init") {
|
|
166
|
+
this.instantiate(message.bytes);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (!this.wasm) return;
|
|
171
|
+
|
|
172
|
+
switch (message.type) {
|
|
173
|
+
case "open": {
|
|
174
|
+
const code = this.wasm.goul_recv_open(message.targetMs, message.maxMs);
|
|
175
|
+
this.open = code === 0;
|
|
176
|
+
if (!this.open) this.port.postMessage({ type: "error", code });
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
case "frame": {
|
|
181
|
+
if (!this.open) break;
|
|
182
|
+
const w = this.wasm;
|
|
183
|
+
const ptr = w.goul_frame_buffer();
|
|
184
|
+
const frame = message.frame;
|
|
185
|
+
new Uint8Array(w.memory.buffer, ptr, w.goul_frame_buffer_cap()).set(frame);
|
|
186
|
+
w.goul_recv_push(ptr, frame.length);
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
case "end":
|
|
191
|
+
this.wasm.goul_recv_end_stream();
|
|
192
|
+
break;
|
|
193
|
+
|
|
194
|
+
case "stats": {
|
|
195
|
+
const ptr = this.wasm.goul_stats_buffer();
|
|
196
|
+
if (this.wasm.goul_recv_stats(ptr, 6) === 6) {
|
|
197
|
+
const values = new Uint32Array(this.wasm.memory.buffer, ptr, 6);
|
|
198
|
+
this.port.postMessage({ type: "stats", values: Array.from(values) });
|
|
199
|
+
}
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
case "close":
|
|
204
|
+
this.open = false;
|
|
205
|
+
this.wasm.goul_recv_close();
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
instantiate(bytes) {
|
|
211
|
+
WebAssembly.instantiate(bytes, {}).then(
|
|
212
|
+
({ instance }) => {
|
|
213
|
+
instance.exports._initialize();
|
|
214
|
+
this.wasm = instance.exports;
|
|
215
|
+
this.port.postMessage({ type: "ready" });
|
|
216
|
+
},
|
|
217
|
+
(error) => this.port.postMessage({ type: "error", message: String(error) })
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
process(_inputs, outputs) {
|
|
222
|
+
const out = outputs[0]?.[0];
|
|
223
|
+
if (!out) return true;
|
|
224
|
+
|
|
225
|
+
for (let i = 0; i < out.length; i++) {
|
|
226
|
+
if (this.reservoirRead >= this.reservoirLength && !this.refill()) {
|
|
227
|
+
// Silence for the rest of this quantum: the buffer is filling, or the
|
|
228
|
+
// transmission is over.
|
|
229
|
+
out.fill(0, i);
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
out[i] = this.reservoir[this.reservoirRead++] / 32768;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Asks the play-out buffer for the next 20 ms. False means silence. */
|
|
240
|
+
refill() {
|
|
241
|
+
if (!this.open) return false;
|
|
242
|
+
|
|
243
|
+
const w = this.wasm;
|
|
244
|
+
const ptr = w.goul_pcm_buffer();
|
|
245
|
+
const samples = w.goul_recv_pull(ptr, FRAME_SAMPLES);
|
|
246
|
+
if (samples <= 0) return false;
|
|
247
|
+
|
|
248
|
+
this.reservoir.set(new Int16Array(w.memory.buffer, ptr, samples));
|
|
249
|
+
this.reservoirLength = samples;
|
|
250
|
+
this.reservoirRead = 0;
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
registerProcessor("goul-capture", GoulCaptureProcessor);
|
|
256
|
+
registerProcessor("goul-playback", GoulPlaybackProcessor);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Les annonces d'opérateur : « votre correspondant est actuellement en
|
|
3
|
+
* ligne », « … n'est pas disponible », « l'identifiant Phono que vous avez
|
|
4
|
+
* demandé n'est pas attribué ».
|
|
5
|
+
*
|
|
6
|
+
* Ce sont des fichiers : ceux de Phono, ceux que votre organisation a déposés
|
|
7
|
+
* dans le dashboard, ou les vôtres (`new Phone(phono, { announcements: { busy: "/occupe.mp3" } })`).
|
|
8
|
+
*/
|
|
9
|
+
import type { AnnouncementCode, Call } from "./types";
|
|
10
|
+
/** Vos fichiers, par code : une URL que le navigateur sait lire. */
|
|
11
|
+
export type AnnouncementFiles = Partial<Record<AnnouncementCode, string>>;
|
|
12
|
+
/** L'annonce d'un appel qui s'est terminé sans avoir eu lieu, ou null. */
|
|
13
|
+
export declare function announcementForEnd(call: Call): AnnouncementCode | null;
|
|
14
|
+
/** L'annonce d'une erreur de `calls.create`, ou null. */
|
|
15
|
+
export declare function announcementForError(code: string): AnnouncementCode | null;
|
|
16
|
+
/**
|
|
17
|
+
* Joue un fichier une fois. `done` se résout à la fin, ou à l'arrêt ; un
|
|
18
|
+
* navigateur qui refuse de jouer (pas de geste, format illisible) se tait.
|
|
19
|
+
*/
|
|
20
|
+
export declare function playAnnouncement(url: string): {
|
|
21
|
+
done: Promise<void>;
|
|
22
|
+
stop: () => void;
|
|
23
|
+
};
|
package/dist/audio.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L'audio d'un appel Phono, dans le navigateur.
|
|
3
|
+
*
|
|
4
|
+
* Le même fil que les téléphones et le SDK Go : des trames goul-audio (Opus,
|
|
5
|
+
* 20 ms) sur un sujet Konet en mode multiplex. Capture, encodage, tampon et
|
|
6
|
+
* lecture vivent dans les worklets de `goul-ptt-worklets.js`, sur le fil
|
|
7
|
+
* audio. Ce fichier n'orchestre que le reste — le micro, le sujet, et l'état
|
|
8
|
+
* qu'une interface affiche.
|
|
9
|
+
*
|
|
10
|
+
* Deux façons de parler :
|
|
11
|
+
* - « ptt » : appuyer pour parler (barre d'espace), comme dans Goul. Chaque
|
|
12
|
+
* pression est un nouveau flux ; celui d'en face jette le retard du
|
|
13
|
+
* précédent.
|
|
14
|
+
* - « open » : micro ouvert, comme un téléphone.
|
|
15
|
+
*
|
|
16
|
+
* Contrairement au push-to-talk de Goul, il n'y a pas de floor : en multiplex,
|
|
17
|
+
* les deux côtés peuvent parler en même temps. L'écho est l'affaire de
|
|
18
|
+
* l'annulation d'écho du navigateur (`echoCancellation: true`).
|
|
19
|
+
*/
|
|
20
|
+
import type { AudioAssets } from "./client";
|
|
21
|
+
import type { AudioCredentials } from "./types";
|
|
22
|
+
export type TalkMode = "ptt" | "open";
|
|
23
|
+
export interface CallAudioSnapshot {
|
|
24
|
+
state: "idle" | "connecting" | "connected" | "denied" | "error";
|
|
25
|
+
mode: TalkMode;
|
|
26
|
+
/** Le micro part en ce moment. */
|
|
27
|
+
talking: boolean;
|
|
28
|
+
/** Micro coupé, en mode ouvert. */
|
|
29
|
+
muted: boolean;
|
|
30
|
+
/** L'autre parle (des trames arrivent). */
|
|
31
|
+
remoteSpeaking: boolean;
|
|
32
|
+
micReady: boolean;
|
|
33
|
+
error: string | null;
|
|
34
|
+
}
|
|
35
|
+
type Listener = (s: CallAudioSnapshot) => void;
|
|
36
|
+
export declare class CallAudio {
|
|
37
|
+
private readonly creds;
|
|
38
|
+
private readonly assets;
|
|
39
|
+
private listeners;
|
|
40
|
+
private snapshot;
|
|
41
|
+
private client;
|
|
42
|
+
private channel;
|
|
43
|
+
private context;
|
|
44
|
+
private micStream;
|
|
45
|
+
private capture;
|
|
46
|
+
private playback;
|
|
47
|
+
private wasmBytes;
|
|
48
|
+
private speakingTimer;
|
|
49
|
+
private stopped;
|
|
50
|
+
constructor(creds: AudioCredentials, mode?: TalkMode, assets?: AudioAssets);
|
|
51
|
+
subscribe(listener: Listener): () => void;
|
|
52
|
+
get state(): CallAudioSnapshot;
|
|
53
|
+
/**
|
|
54
|
+
* Rejoint l'audio et commence à écouter. Doit être appelé depuis un geste
|
|
55
|
+
* (le clic qui décroche ou qui appelle) : c'est ce qui autorise le
|
|
56
|
+
* navigateur à démarrer le son et à demander le micro.
|
|
57
|
+
*/
|
|
58
|
+
start(): Promise<void>;
|
|
59
|
+
/** Appuyer pour parler : début. */
|
|
60
|
+
press(): void;
|
|
61
|
+
/** Appuyer pour parler : fin. */
|
|
62
|
+
release(): void;
|
|
63
|
+
setMode(mode: TalkMode): void;
|
|
64
|
+
/** Couper le micro, en mode ouvert. */
|
|
65
|
+
setMuted(muted: boolean): void;
|
|
66
|
+
stop(): void;
|
|
67
|
+
private startTalking;
|
|
68
|
+
private stopTalking;
|
|
69
|
+
private markRemoteSpeaking;
|
|
70
|
+
/** Tout ce qu'il faut pour entendre. Aucune permission. */
|
|
71
|
+
private buildPlayback;
|
|
72
|
+
/** Tout ce qu'il faut pour parler. Le seul endroit où le micro est demandé. */
|
|
73
|
+
private ensureCapture;
|
|
74
|
+
private initWorklet;
|
|
75
|
+
private isPermissionDenied;
|
|
76
|
+
private describe;
|
|
77
|
+
private emit;
|
|
78
|
+
}
|
|
79
|
+
export {};
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { Phone, type PhoneOptions } from "./phone";
|
|
2
|
+
import { Realtime } from "./realtime";
|
|
3
|
+
import { Talkie } from "./talkie";
|
|
4
|
+
import type { Activity, Announcement, Announcements, Group, SearchHit, Transfer, AudioCredentials, Call, CallEnvelope, ContactRequest, ContactRequests, Contacts, Conversation, LookedUpHandle, Me, Message, PublicHandle, Relation, Channel, Transmission } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* D'où vient le jeton : une chaîne, ou une fonction qui en demande un à votre
|
|
7
|
+
* backend (`POST /v1/identities/{ref}/tokens`, côté serveur). La fonction est
|
|
8
|
+
* rappelée avant l'expiration du jeton, et après un refus.
|
|
9
|
+
*/
|
|
10
|
+
export type TokenSource = string | (() => string | Promise<string>);
|
|
11
|
+
export interface PhonoOptions {
|
|
12
|
+
/** L'URL de l'API Phono, sans /v1. */
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
/** Un jeton client `pht_…` (ou toute clé Phono). */
|
|
15
|
+
token?: TokenSource;
|
|
16
|
+
/** En-têtes ajoutés à chaque requête. */
|
|
17
|
+
headers?: Record<string, string>;
|
|
18
|
+
/** `include` pour une session par cookie plutôt qu'un jeton. */
|
|
19
|
+
credentials?: RequestCredentials;
|
|
20
|
+
/** Où le navigateur trouve le cœur audio : voir le README. */
|
|
21
|
+
audio?: AudioAssets;
|
|
22
|
+
fetch?: typeof fetch;
|
|
23
|
+
}
|
|
24
|
+
export interface AudioAssets {
|
|
25
|
+
/** `goul-ptt-worklets.js`. Par défaut `/goul-ptt-worklets.js`. */
|
|
26
|
+
workletUrl?: string;
|
|
27
|
+
/** `goul-audio.wasm`. Par défaut `/goul-audio.wasm`. */
|
|
28
|
+
wasmUrl?: string;
|
|
29
|
+
}
|
|
30
|
+
/** Une erreur de l'API : `code` est stable (voir la référence des erreurs). */
|
|
31
|
+
export declare class PhonoError extends Error {
|
|
32
|
+
readonly status: number;
|
|
33
|
+
readonly code: string;
|
|
34
|
+
/** Un appel qui n'aboutit pas : l'annonce d'opérateur à jouer. */
|
|
35
|
+
readonly announcement?: Announcement | undefined;
|
|
36
|
+
constructor(status: number, code: string, message: string,
|
|
37
|
+
/** Un appel qui n'aboutit pas : l'annonce d'opérateur à jouer. */
|
|
38
|
+
announcement?: Announcement | undefined);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Le client Phono : l'API `/v1` au nom d'une identité.
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* const phono = new Phono({
|
|
45
|
+
* baseUrl: "https://phonoapi.raucheacho.com",
|
|
46
|
+
* token: () => fetch("/api/phono-token").then((r) => r.text()),
|
|
47
|
+
* });
|
|
48
|
+
* await phono.messages.send({ to: "jean.acme", text: "Bonjour" });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare class Phono {
|
|
52
|
+
readonly options: PhonoOptions;
|
|
53
|
+
private token;
|
|
54
|
+
private tokenExpiry;
|
|
55
|
+
private pendingToken;
|
|
56
|
+
private realtimeInstance;
|
|
57
|
+
constructor(options: PhonoOptions);
|
|
58
|
+
/** Une requête à l'API, authentifiée. `path` commence par `/`. */
|
|
59
|
+
request<T>(path: string, init?: RequestInit): Promise<T>;
|
|
60
|
+
private send;
|
|
61
|
+
private currentToken;
|
|
62
|
+
/** L'identité au nom de laquelle ce client agit. */
|
|
63
|
+
me(): Promise<Me>;
|
|
64
|
+
/**
|
|
65
|
+
* Les annonces d'opérateur à jouer quand un appel n'aboutit pas : celles de
|
|
66
|
+
* votre organisation, sinon celles de Phono. `lang` : `fr`, `en`…
|
|
67
|
+
*/
|
|
68
|
+
announcements(lang?: string): Promise<Announcements>;
|
|
69
|
+
/** Une identité, par son identifiant (`jean.acme`). */
|
|
70
|
+
lookup(handle: string): Promise<LookedUpHandle>;
|
|
71
|
+
contacts(): Promise<Contacts>;
|
|
72
|
+
/**
|
|
73
|
+
* Les demandes de contact et le blocage. Hors de votre organisation, écrire
|
|
74
|
+
* ou appeler exige un contact établi : sinon l'API répond `contact_required`.
|
|
75
|
+
*/
|
|
76
|
+
readonly contactRequests: {
|
|
77
|
+
list: () => Promise<ContactRequests>;
|
|
78
|
+
/** Demander à joindre `to`. Rend `outgoing`, ou `contact` s'il vous avait déjà demandé. */
|
|
79
|
+
send: (input: {
|
|
80
|
+
to: string;
|
|
81
|
+
note?: string;
|
|
82
|
+
}) => Promise<{
|
|
83
|
+
handle: PublicHandle;
|
|
84
|
+
relation: Relation;
|
|
85
|
+
}>;
|
|
86
|
+
accept: (handle: string) => Promise<{
|
|
87
|
+
handle: PublicHandle;
|
|
88
|
+
relation: Relation;
|
|
89
|
+
}>;
|
|
90
|
+
/** Refuser : l'autre n'en est pas prévenu. */
|
|
91
|
+
decline: (handle: string) => Promise<void>;
|
|
92
|
+
};
|
|
93
|
+
/** Retirer un contact, ou annuler sa demande. */
|
|
94
|
+
removeContact(handle: string): Promise<void>;
|
|
95
|
+
readonly blocks: {
|
|
96
|
+
list: () => Promise<ContactRequest[]>;
|
|
97
|
+
/** Plus rien de `handle` : ni message, ni appel, ni demande. Il n'en sait rien. */
|
|
98
|
+
add: (handle: string) => Promise<void>;
|
|
99
|
+
remove: (handle: string) => Promise<void>;
|
|
100
|
+
};
|
|
101
|
+
readonly messages: {
|
|
102
|
+
/** Un texte, à `to` ou dans un `group` ; `reply_to` pour répondre à un message précis. */
|
|
103
|
+
/** `urgent` : passe la sourdine et le mode Concentration — dans l'organisation seulement. */
|
|
104
|
+
send: (input: {
|
|
105
|
+
to?: string;
|
|
106
|
+
group?: string;
|
|
107
|
+
text: string;
|
|
108
|
+
reply_to?: string;
|
|
109
|
+
urgent?: boolean;
|
|
110
|
+
}) => Promise<Message>;
|
|
111
|
+
/**
|
|
112
|
+
* Un vocal : Ogg Opus tel quel, ou ce que produit le navigateur
|
|
113
|
+
* (MediaRecorder : WebM, MP4) — Phono le convertit.
|
|
114
|
+
*/
|
|
115
|
+
sendVoice: (input: {
|
|
116
|
+
to?: string;
|
|
117
|
+
group?: string;
|
|
118
|
+
audio: Blob;
|
|
119
|
+
reply_to?: string;
|
|
120
|
+
}) => Promise<Message>;
|
|
121
|
+
/** Une photo (affichée dans le fil) ou un document, 25 Mo au plus. */
|
|
122
|
+
sendFile: (input: {
|
|
123
|
+
to?: string;
|
|
124
|
+
group?: string;
|
|
125
|
+
file: Blob;
|
|
126
|
+
filename: string;
|
|
127
|
+
caption?: string;
|
|
128
|
+
reply_to?: string;
|
|
129
|
+
width?: number;
|
|
130
|
+
height?: number;
|
|
131
|
+
}) => Promise<Message>;
|
|
132
|
+
/** Une position, une fois — pas un suivi. */
|
|
133
|
+
sendLocation: (input: {
|
|
134
|
+
to?: string;
|
|
135
|
+
group?: string;
|
|
136
|
+
lat: number;
|
|
137
|
+
lng: number;
|
|
138
|
+
label?: string;
|
|
139
|
+
reply_to?: string;
|
|
140
|
+
}) => Promise<Message>;
|
|
141
|
+
/** Corrige l'un de vos textes, dans les 15 minutes. */
|
|
142
|
+
edit: (messageId: string, text: string) => Promise<Message>;
|
|
143
|
+
/** Supprime l'un de vos messages pour tout le monde. */
|
|
144
|
+
remove: (messageId: string) => Promise<Message>;
|
|
145
|
+
/** Cherche dans vos conversations (textes et transcriptions). */
|
|
146
|
+
search: (q: string, limit?: number) => Promise<SearchHit[]>;
|
|
147
|
+
/** Le fil d'un groupe. */
|
|
148
|
+
group: (groupId: string, input?: {
|
|
149
|
+
before?: string;
|
|
150
|
+
limit?: number;
|
|
151
|
+
}) => Promise<{
|
|
152
|
+
conversation_id: string;
|
|
153
|
+
messages: Message[];
|
|
154
|
+
}>;
|
|
155
|
+
/** La conversation avec `with`, la plus récente d'abord. */
|
|
156
|
+
list: (input: {
|
|
157
|
+
with: string;
|
|
158
|
+
before?: string;
|
|
159
|
+
limit?: number;
|
|
160
|
+
}) => Promise<{
|
|
161
|
+
conversation_id: string;
|
|
162
|
+
messages: Message[];
|
|
163
|
+
}>;
|
|
164
|
+
/** Pose (ou remplace) ma réaction — un emoji — sur un message. */
|
|
165
|
+
react: (messageId: string, emoji: string) => Promise<Message>;
|
|
166
|
+
unreact: (messageId: string) => Promise<Message>;
|
|
167
|
+
/** « J'écris », « j'enregistre un vocal », « j'ai fini » : à répéter toutes les 3 s tant que ça dure. */
|
|
168
|
+
activity: (input: {
|
|
169
|
+
to?: string;
|
|
170
|
+
group?: string;
|
|
171
|
+
state: Activity;
|
|
172
|
+
}) => Promise<void>;
|
|
173
|
+
};
|
|
174
|
+
readonly conversations: {
|
|
175
|
+
list: (input?: {
|
|
176
|
+
limit?: number;
|
|
177
|
+
archived?: boolean;
|
|
178
|
+
}) => Promise<Conversation[]>;
|
|
179
|
+
markRead: (conversationId: string) => Promise<{
|
|
180
|
+
marked: number;
|
|
181
|
+
}>;
|
|
182
|
+
/** Vous avez reçu les messages (✓✓ chez l'auteur). */
|
|
183
|
+
delivered: (conversationId: string) => Promise<{
|
|
184
|
+
delivered: number;
|
|
185
|
+
}>;
|
|
186
|
+
mute: (conversationId: string, until?: string) => Promise<void>;
|
|
187
|
+
unmute: (conversationId: string) => Promise<void>;
|
|
188
|
+
archive: (conversationId: string, archived?: boolean) => Promise<void>;
|
|
189
|
+
/** Passe votre conversation avec `with` à `to`, de votre organisation. */
|
|
190
|
+
transfer: (input: {
|
|
191
|
+
with: string;
|
|
192
|
+
to: string;
|
|
193
|
+
note?: string;
|
|
194
|
+
}) => Promise<Transfer>;
|
|
195
|
+
transfers: (withHandle: string) => Promise<Transfer[]>;
|
|
196
|
+
transferHistory: (id: string) => Promise<{
|
|
197
|
+
messages: Message[];
|
|
198
|
+
}>;
|
|
199
|
+
};
|
|
200
|
+
/** Les petits groupes fermés : 12 membres au plus, joignables par vous. */
|
|
201
|
+
readonly groups: {
|
|
202
|
+
create: (input: {
|
|
203
|
+
title: string;
|
|
204
|
+
members: string[];
|
|
205
|
+
}) => Promise<Group>;
|
|
206
|
+
get: (groupId: string) => Promise<Group>;
|
|
207
|
+
rename: (groupId: string, title: string) => Promise<Group>;
|
|
208
|
+
add: (groupId: string, handle: string) => Promise<Group>;
|
|
209
|
+
remove: (groupId: string, handle: string) => Promise<void>;
|
|
210
|
+
};
|
|
211
|
+
readonly calls: {
|
|
212
|
+
/** Faire sonner `to`. Pour l'audio dans le navigateur, préférez `phone().dial()`. */
|
|
213
|
+
create: (input: {
|
|
214
|
+
to: string;
|
|
215
|
+
} | {
|
|
216
|
+
connect: [string, string];
|
|
217
|
+
}) => Promise<CallEnvelope>;
|
|
218
|
+
get: (callId: string) => Promise<Call>;
|
|
219
|
+
list: (input?: {
|
|
220
|
+
limit?: number;
|
|
221
|
+
}) => Promise<Call[]>;
|
|
222
|
+
answer: (callId: string) => Promise<CallEnvelope>;
|
|
223
|
+
reject: (callId: string) => Promise<CallEnvelope>;
|
|
224
|
+
hangup: (callId: string) => Promise<CallEnvelope>;
|
|
225
|
+
/** De nouveaux identifiants audio pour un appel en cours (reconnexion). */
|
|
226
|
+
audio: (callId: string) => Promise<AudioCredentials>;
|
|
227
|
+
};
|
|
228
|
+
/** Une URL lisible par un `<audio>` pour un vocal ou un enregistrement. */
|
|
229
|
+
mediaUrl(mediaId: string, speed?: 1.5 | 2): Promise<string>;
|
|
230
|
+
/** Les événements de cette identité, en direct. Une seule connexion par client. */
|
|
231
|
+
realtime(): Realtime;
|
|
232
|
+
/** Un téléphone : sonner, appeler, décrocher, parler. */
|
|
233
|
+
phone(options?: PhoneOptions): Phone;
|
|
234
|
+
/** Le talkie d'un canal : écouter, appuyer pour parler. */
|
|
235
|
+
talkie(channelId: string): Talkie;
|
|
236
|
+
/** Les canaux de talkie : fermés, dans l'organisation, une voix à la fois. */
|
|
237
|
+
readonly channels: {
|
|
238
|
+
list: () => Promise<Channel[]>;
|
|
239
|
+
get: (id: string) => Promise<Channel>;
|
|
240
|
+
create: (input: {
|
|
241
|
+
name: string;
|
|
242
|
+
members: string[];
|
|
243
|
+
record?: boolean;
|
|
244
|
+
}) => Promise<Channel>;
|
|
245
|
+
update: (id: string, input: {
|
|
246
|
+
name?: string;
|
|
247
|
+
record?: boolean;
|
|
248
|
+
}) => Promise<Channel>;
|
|
249
|
+
add: (id: string, handle: string) => Promise<Channel>;
|
|
250
|
+
/** Retire un membre ; avec son propre identifiant, on part. */
|
|
251
|
+
remove: (id: string, handle: string) => Promise<Channel | undefined>;
|
|
252
|
+
delete: (id: string) => Promise<void>;
|
|
253
|
+
/** Accepter l'invitation à un canal (`channel.invited`) : on l'entend désormais. */
|
|
254
|
+
accept: (id: string) => Promise<Channel>;
|
|
255
|
+
/** Refuser l'invitation. */
|
|
256
|
+
decline: (id: string) => Promise<void>;
|
|
257
|
+
/** Les prises de parole, la plus récente d'abord. */
|
|
258
|
+
transmissions: (id: string, options?: {
|
|
259
|
+
limit?: number;
|
|
260
|
+
before?: string;
|
|
261
|
+
}) => Promise<Transmission[]>;
|
|
262
|
+
};
|
|
263
|
+
/** Coupe le temps réel. */
|
|
264
|
+
close(): void;
|
|
265
|
+
}
|