@dtelecom/server-sdk-node 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/README.md ADDED
@@ -0,0 +1,131 @@
1
+ # @dtelecom/server-sdk-node
2
+
3
+ Node.js RTC SDK for dTelecom — join rooms as a WebRTC participant for AI bots.
4
+
5
+ ## Features
6
+
7
+ - **WebRTC participant** — join dTelecom rooms as a bot
8
+ - **Audio receive** — subscribe to remote audio as PCM16 streams (16kHz for STT)
9
+ - **Audio send** — publish PCM16 audio as Opus (from TTS or any source)
10
+ - **Data channels** — send/receive messages via reliable or lossy channels
11
+ - **Pure TypeScript WebRTC** — uses [werift](https://github.com/nicejs/werift-webrtc) (no native WebRTC deps)
12
+ - **Opus codec** — uses [@discordjs/opus](https://github.com/discordjs/opus) (native libopus bindings)
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install @dtelecom/server-sdk-node @discordjs/opus
18
+ ```
19
+
20
+ ## Quick Start: Echo Bot
21
+
22
+ ```typescript
23
+ import { Room, AudioSource, AudioStream, AudioFrame, LocalAudioTrack } from '@dtelecom/server-sdk-node';
24
+
25
+ const room = new Room();
26
+ await room.connect('wss://my.dtelecom.org', token);
27
+
28
+ // Create audio output
29
+ const source = new AudioSource(16000, 1);
30
+ const track = LocalAudioTrack.createAudioTrack('echo', source);
31
+ await room.localParticipant.publishTrack(track);
32
+
33
+ // Echo received audio back
34
+ room.on('trackSubscribed', async (remoteTrack, pub, participant) => {
35
+ const stream = remoteTrack.createStream(16000, 1);
36
+ for await (const frame of stream) {
37
+ await source.captureFrame(frame); // echo back
38
+ }
39
+ });
40
+ ```
41
+
42
+ ## Architecture
43
+
44
+ ```
45
+ @dtelecom/server-sdk-node
46
+ ├── SignalClient WebSocket + protobuf to SFU
47
+ ├── RTCEngine 2 PeerConnections (publisher + subscriber)
48
+ ├── Room participant management, events
49
+ ├── LocalParticipant publish tracks + data
50
+ ├── RemoteParticipant subscribed tracks
51
+ ├── AudioSource PCM16 → Opus → RTP → publish
52
+ ├── AudioStream subscribe → RTP → Opus → PCM16
53
+ └── DataChannel reliable + lossy messaging
54
+ ```
55
+
56
+ ## API
57
+
58
+ ### Room
59
+
60
+ ```typescript
61
+ const room = new Room();
62
+ await room.connect(url, token, { autoSubscribe: true });
63
+
64
+ room.on('participantConnected', (participant) => { });
65
+ room.on('trackSubscribed', (track, publication, participant) => { });
66
+ room.on('dataReceived', (data, participant, kind, topic) => { });
67
+ room.on('disconnected', (reason) => { });
68
+
69
+ await room.disconnect();
70
+ ```
71
+
72
+ ### Audio
73
+
74
+ ```typescript
75
+ // Publish audio
76
+ const source = new AudioSource(16000, 1);
77
+ const track = LocalAudioTrack.createAudioTrack('bot-audio', source);
78
+ await room.localParticipant.publishTrack(track);
79
+
80
+ const frame = new AudioFrame(pcm16Data, 16000, 1, samplesPerChannel);
81
+ await source.captureFrame(frame);
82
+
83
+ // Receive audio
84
+ room.on('trackSubscribed', async (remoteTrack) => {
85
+ const stream = remoteTrack.createStream(16000, 1);
86
+ for await (const frame of stream) {
87
+ // frame.data = Int16Array (PCM16, 16kHz, mono)
88
+ }
89
+ });
90
+ ```
91
+
92
+ ### Data Channels
93
+
94
+ ```typescript
95
+ import { DataPacket_Kind } from '@dtelecom/server-sdk-node';
96
+
97
+ await room.localParticipant.publishData(
98
+ new TextEncoder().encode('hello'),
99
+ { kind: DataPacket_Kind.RELIABLE, topic: 'chat' }
100
+ );
101
+
102
+ room.on('dataReceived', (data, participant, kind, topic) => {
103
+ console.log(new TextDecoder().decode(data));
104
+ });
105
+ ```
106
+
107
+ ## Examples
108
+
109
+ ```bash
110
+ # Echo bot — echoes received audio back
111
+ npx tsx examples/echo-bot.ts --room test
112
+
113
+ # Record audio — saves remote audio to PCM file
114
+ npx tsx examples/receive-audio.ts --room test --output recording.pcm
115
+
116
+ # Play audio — sends PCM file into room
117
+ npx tsx examples/send-audio.ts --room test --input hello.pcm
118
+ ```
119
+
120
+ ## Dependencies
121
+
122
+ | Package | Purpose | Native? |
123
+ |---|---|---|
124
+ | `werift` | WebRTC (ICE, DTLS, SRTP) | No (pure TS) |
125
+ | `@discordjs/opus` | Opus encode/decode | Yes (libopus) |
126
+ | `ws` | WebSocket client | No |
127
+ | `protobufjs` | Protobuf encode/decode | No |
128
+
129
+ ## License
130
+
131
+ Apache-2.0