@node-webrtc-rust/bindings 0.2.1 → 0.4.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 (4) hide show
  1. package/README.md +6 -6
  2. package/index.d.ts +158 -4
  3. package/index.js +46 -40
  4. package/package.json +7 -7
package/README.md CHANGED
@@ -77,12 +77,12 @@ Each platform package is a thin wrapper: its `"main"` field points directly at t
77
77
 
78
78
  **When the binary might be missing after install:**
79
79
 
80
- | Situation | Result |
81
- | --- | --- |
82
- | Normal install on a supported platform | Matching optional package is present |
83
- | `npm install --omit=optional` | No platform package — runtime fails unless a local `.node` exists |
84
- | Unsupported OS/arch | No matching optional package |
85
- | Publish/version mismatch for the optional pkg | Install may succeed; `require()` fails at runtime |
80
+ | Situation | Result |
81
+ | --------------------------------------------- | ----------------------------------------------------------------- |
82
+ | Normal install on a supported platform | Matching optional package is present |
83
+ | `npm install --omit=optional` | No platform package — runtime fails unless a local `.node` exists |
84
+ | Unsupported OS/arch | No matching optional package |
85
+ | Publish/version mismatch for the optional pkg | Install may succeed; `require()` fails at runtime |
86
86
 
87
87
  ### At runtime (`require('@node-webrtc-rust/bindings')`)
88
88
 
package/index.d.ts CHANGED
@@ -72,6 +72,17 @@ export interface JsRtcConfiguration {
72
72
  iceTransportPolicy?: string
73
73
  debug?: boolean
74
74
  }
75
+ /** Offer options (W3C `RTCOfferOptions` subset). */
76
+ export interface JsRtcOfferOptions {
77
+ iceRestart?: boolean
78
+ voiceActivityDetection?: boolean
79
+ offerToReceiveAudio?: boolean
80
+ offerToReceiveVideo?: boolean
81
+ }
82
+ /** Answer options (W3C `RTCAnswerOptions` subset). */
83
+ export interface JsRtcAnswerOptions {
84
+ voiceActivityDetection?: boolean
85
+ }
75
86
  /** Session description exposed to JavaScript. */
76
87
  export interface JsRtcSessionDescription {
77
88
  type: string
@@ -92,6 +103,94 @@ export interface JsRtcDataChannelInit {
92
103
  protocol?: string
93
104
  negotiated?: number
94
105
  }
106
+ /** Init options for {@link RTCPeerConnection.addTransceiver}. */
107
+ export interface JsRtcRtpTransceiverInit {
108
+ direction?: string
109
+ }
110
+ export const enum JsEventDeliveryMode {
111
+ Callback = 'callback',
112
+ Stream = 'stream',
113
+ Both = 'both'
114
+ }
115
+ export interface JsEventsConfig {
116
+ mode?: JsEventDeliveryMode
117
+ }
118
+ export interface JsBargeInConfig {
119
+ enabled?: boolean
120
+ useVad?: boolean
121
+ flushTts?: boolean
122
+ requireSttPartial?: boolean
123
+ minSttPartialChars?: number
124
+ agentPlaybackGuardMs?: number
125
+ }
126
+ export const enum JsVadSampleRate {
127
+ Hz8000 = '8000',
128
+ Hz16000 = '16000'
129
+ }
130
+ export interface JsVadConfig {
131
+ enabled?: boolean
132
+ provider?: string
133
+ threshold?: number
134
+ minSpeechDurationMs?: number
135
+ minSilenceDurationMs?: number
136
+ speechPadMs?: number
137
+ sampleRate?: JsVadSampleRate
138
+ bargeIn?: JsBargeInConfig
139
+ gateStt?: boolean
140
+ gateSttOpenOnPending?: boolean
141
+ sttGateHoldMs?: number
142
+ }
143
+ export const enum JsSttVendor {
144
+ Openai = 'openai',
145
+ Deepgram = 'deepgram',
146
+ Google = 'google',
147
+ Assemblyai = 'assemblyai',
148
+ LocalSherpa = 'local-sherpa',
149
+ Mock = 'mock'
150
+ }
151
+ export const enum JsTtsVendor {
152
+ Openai = 'openai',
153
+ Elevenlabs = 'elevenlabs',
154
+ Google = 'google',
155
+ Cartesia = 'cartesia',
156
+ LocalSherpa = 'local-sherpa',
157
+ Mock = 'mock'
158
+ }
159
+ export interface JsSttConfig {
160
+ provider: JsSttVendor
161
+ model?: string
162
+ modelPath?: string
163
+ language?: string
164
+ apiKey?: string
165
+ }
166
+ export interface JsTtsConfig {
167
+ provider: JsTtsVendor
168
+ model?: string
169
+ modelPath?: string
170
+ voice?: string
171
+ apiKey?: string
172
+ }
173
+ export interface JsVoiceAgentConfig {
174
+ vad?: JsVadConfig
175
+ events?: JsEventsConfig
176
+ stt?: JsSttConfig
177
+ tts?: JsTtsConfig
178
+ }
179
+ export const enum JsSpeechEventType {
180
+ UserSpeakingStart = 'user_speaking_start',
181
+ UserSpeakingEnd = 'user_speaking_end',
182
+ UserSpeechPartial = 'user_speech_partial',
183
+ UserSpeechFinal = 'user_speech_final',
184
+ AgentSpeakingStart = 'agent_speaking_start',
185
+ AgentSpeakingEnd = 'agent_speaking_end',
186
+ BargeIn = 'barge_in',
187
+ Error = 'error'
188
+ }
189
+ export interface JsSpeechEvent {
190
+ eventType: JsSpeechEventType
191
+ text?: string
192
+ error?: string
193
+ }
95
194
  export declare function version(): string
96
195
  /** One conference room with participant and mixing controls. */
97
196
  export declare class JsConferenceRoom {
@@ -146,18 +245,22 @@ export declare class JsRtcDataChannel {
146
245
  bufferedAmount(): Promise<number>
147
246
  send(data: string | Buffer): Promise<void>
148
247
  close(): Promise<void>
248
+ setBufferedAmountLowThreshold(threshold: number): void
249
+ setOnBufferedAmountLow(callback: (...args: any[]) => any): void
149
250
  setOnOpen(callback: (...args: any[]) => any): void
150
251
  setOnMessage(callback: (...args: any[]) => any): void
151
252
  setOnClose(callback: (...args: any[]) => any): void
152
253
  setOnError(callback: (...args: any[]) => any): void
153
254
  }
154
- /** Media stream track exposed to JavaScript (stub). */
255
+ /** Media stream track exposed to JavaScript. */
155
256
  export declare class JsMediaStreamTrack {
156
257
  get id(): string
157
258
  get kind(): string
158
259
  get streamId(): string
159
260
  get enabled(): boolean
160
261
  set enabled(enabled: boolean)
262
+ /** Decodes the next inbound Opus RTP packet to stereo PCM (remote audio only). */
263
+ readSample(): Promise<Buffer>
161
264
  }
162
265
  /** Media stream exposed to JavaScript (stub). */
163
266
  export declare class JsMediaStream {
@@ -182,15 +285,24 @@ export declare class JsPeerConnection {
182
285
  get iceConnectionState(): string
183
286
  get iceGatheringState(): string
184
287
  get signalingState(): string
185
- createOffer(): Promise<JsRtcSessionDescription>
186
- createAnswer(): Promise<JsRtcSessionDescription>
288
+ createOffer(options?: JsRtcOfferOptions | undefined | null): Promise<JsRtcSessionDescription>
289
+ createAnswer(options?: JsRtcAnswerOptions | undefined | null): Promise<JsRtcSessionDescription>
187
290
  setLocalDescription(desc: JsRtcSessionDescription): Promise<void>
188
291
  setRemoteDescription(desc: JsRtcSessionDescription): Promise<void>
189
292
  addIceCandidate(candidate: JsRtcIceCandidate): Promise<void>
190
- addTrack(track: JsLocalAudioTrack): Promise<void>
293
+ addTrack(track: JsLocalAudioTrack): Promise<JsRtpSender>
294
+ removeTrack(sender: JsRtpSender): Promise<void>
295
+ addTransceiver(kind?: string | undefined | null, track?: JsLocalAudioTrack | undefined | null, init?: JsRTCRtpTransceiverInit | undefined | null): Promise<JsRtpTransceiver>
296
+ getTransceivers(): Promise<Array<JsRtpTransceiver>>
297
+ getSenders(): Promise<Array<JsRtpSender>>
298
+ getReceivers(): Promise<Array<JsRtpReceiver>>
191
299
  createDataChannel(label: string, options?: JsRtcDataChannelInit | undefined | null): Promise<JsRtcDataChannel>
192
300
  close(): Promise<void>
193
301
  gatheringComplete(): Promise<void>
302
+ setConfiguration(config: JsRtcConfiguration): Promise<void>
303
+ getConfiguration(): Promise<JsRtcConfiguration>
304
+ restartIce(): Promise<void>
305
+ getStats(): Promise<string>
194
306
  localDescription(): Promise<JsRtcSessionDescription | null>
195
307
  remoteDescription(): Promise<JsRtcSessionDescription | null>
196
308
  setOnIceCandidate(callback: (...args: any[]) => any): void
@@ -198,5 +310,47 @@ export declare class JsPeerConnection {
198
310
  setOnDataChannel(callback: (...args: any[]) => any): void
199
311
  setOnConnectionStateChange(callback: (...args: any[]) => any): void
200
312
  setOnIceConnectionStateChange(callback: (...args: any[]) => any): void
313
+ setOnIceGatheringStateChange(callback: (...args: any[]) => any): void
314
+ setOnSignalingStateChange(callback: (...args: any[]) => any): void
201
315
  setOnNegotiationNeeded(callback: (...args: any[]) => any): void
202
316
  }
317
+ /** RTP receiver leg of an {@link RTCRtpTransceiver}. */
318
+ export declare class JsRtpReceiver {
319
+ get id(): string
320
+ get kind(): string
321
+ }
322
+ /** RTP sender returned from {@link RTCPeerConnection.addTrack}. */
323
+ export declare class JsRtpSender {
324
+ get id(): string
325
+ /** Replaces the outbound audio track without renegotiation. */
326
+ replaceTrack(track?: JsLocalAudioTrack | undefined | null): Promise<void>
327
+ }
328
+ /** Unified Plan transceiver (sender + receiver pair). */
329
+ export declare class JsRtpTransceiver {
330
+ get mid(): string | null
331
+ get direction(): string
332
+ get currentDirection(): string | null
333
+ get kind(): string
334
+ get stopped(): boolean
335
+ get sender(): JsRtpSender
336
+ get receiver(): JsRtpReceiver
337
+ setDirection(direction: string): Promise<void>
338
+ stop(): Promise<void>
339
+ }
340
+ /** Voice agent with VAD, STT/TTS orchestration for one peer connection session. */
341
+ export declare class JsVoiceAgent {
342
+ constructor(config?: JsVoiceAgentConfig | undefined | null)
343
+ /** Attaches outbound local audio track for TTS injection. */
344
+ attach(outboundTrack: JsLocalAudioTrack): Promise<void>
345
+ start(): Promise<void>
346
+ stop(): Promise<void>
347
+ sendTextToTts(text: string): Promise<void>
348
+ flushTts(): Promise<void>
349
+ /** Wait until outbound TTS playback finishes (synthesis queue drained and agent not speaking). */
350
+ waitTtsPlaybackIdle(): Promise<void>
351
+ /** Pull the next speech event for async stream consumption. */
352
+ pullSpeechEvent(): Promise<JsSpeechEvent | null>
353
+ setOnSpeechEvent(callback: (...args: any[]) => any): void
354
+ /** Processes one inbound PCM frame (48 kHz stereo) through VAD/STT. */
355
+ processInboundPcm(data: Buffer, durationMs: number): Promise<void>
356
+ }
package/index.js CHANGED
@@ -62,9 +62,7 @@ switch (platform) {
62
62
  case 'win32':
63
63
  switch (arch) {
64
64
  case 'x64':
65
- localFileExisted = existsSync(
66
- join(__dirname, 'node-webrtc-rust.win32-x64-msvc.node')
67
- )
65
+ localFileExisted = existsSync(join(__dirname, 'node-webrtc-rust.win32-x64-msvc.node'))
68
66
  try {
69
67
  if (localFileExisted) {
70
68
  nativeBinding = require('./node-webrtc-rust.win32-x64-msvc.node')
@@ -76,9 +74,7 @@ switch (platform) {
76
74
  }
77
75
  break
78
76
  case 'ia32':
79
- localFileExisted = existsSync(
80
- join(__dirname, 'node-webrtc-rust.win32-ia32-msvc.node')
81
- )
77
+ localFileExisted = existsSync(join(__dirname, 'node-webrtc-rust.win32-ia32-msvc.node'))
82
78
  try {
83
79
  if (localFileExisted) {
84
80
  nativeBinding = require('./node-webrtc-rust.win32-ia32-msvc.node')
@@ -90,9 +86,7 @@ switch (platform) {
90
86
  }
91
87
  break
92
88
  case 'arm64':
93
- localFileExisted = existsSync(
94
- join(__dirname, 'node-webrtc-rust.win32-arm64-msvc.node')
95
- )
89
+ localFileExisted = existsSync(join(__dirname, 'node-webrtc-rust.win32-arm64-msvc.node'))
96
90
  try {
97
91
  if (localFileExisted) {
98
92
  nativeBinding = require('./node-webrtc-rust.win32-arm64-msvc.node')
@@ -131,9 +125,7 @@ switch (platform) {
131
125
  }
132
126
  break
133
127
  case 'arm64':
134
- localFileExisted = existsSync(
135
- join(__dirname, 'node-webrtc-rust.darwin-arm64.node')
136
- )
128
+ localFileExisted = existsSync(join(__dirname, 'node-webrtc-rust.darwin-arm64.node'))
137
129
  try {
138
130
  if (localFileExisted) {
139
131
  nativeBinding = require('./node-webrtc-rust.darwin-arm64.node')
@@ -167,9 +159,7 @@ switch (platform) {
167
159
  switch (arch) {
168
160
  case 'x64':
169
161
  if (isMusl()) {
170
- localFileExisted = existsSync(
171
- join(__dirname, 'node-webrtc-rust.linux-x64-musl.node')
172
- )
162
+ localFileExisted = existsSync(join(__dirname, 'node-webrtc-rust.linux-x64-musl.node'))
173
163
  try {
174
164
  if (localFileExisted) {
175
165
  nativeBinding = require('./node-webrtc-rust.linux-x64-musl.node')
@@ -180,9 +170,7 @@ switch (platform) {
180
170
  loadError = e
181
171
  }
182
172
  } else {
183
- localFileExisted = existsSync(
184
- join(__dirname, 'node-webrtc-rust.linux-x64-gnu.node')
185
- )
173
+ localFileExisted = existsSync(join(__dirname, 'node-webrtc-rust.linux-x64-gnu.node'))
186
174
  try {
187
175
  if (localFileExisted) {
188
176
  nativeBinding = require('./node-webrtc-rust.linux-x64-gnu.node')
@@ -196,9 +184,7 @@ switch (platform) {
196
184
  break
197
185
  case 'arm64':
198
186
  if (isMusl()) {
199
- localFileExisted = existsSync(
200
- join(__dirname, 'node-webrtc-rust.linux-arm64-musl.node')
201
- )
187
+ localFileExisted = existsSync(join(__dirname, 'node-webrtc-rust.linux-arm64-musl.node'))
202
188
  try {
203
189
  if (localFileExisted) {
204
190
  nativeBinding = require('./node-webrtc-rust.linux-arm64-musl.node')
@@ -209,9 +195,7 @@ switch (platform) {
209
195
  loadError = e
210
196
  }
211
197
  } else {
212
- localFileExisted = existsSync(
213
- join(__dirname, 'node-webrtc-rust.linux-arm64-gnu.node')
214
- )
198
+ localFileExisted = existsSync(join(__dirname, 'node-webrtc-rust.linux-arm64-gnu.node'))
215
199
  try {
216
200
  if (localFileExisted) {
217
201
  nativeBinding = require('./node-webrtc-rust.linux-arm64-gnu.node')
@@ -226,7 +210,7 @@ switch (platform) {
226
210
  case 'arm':
227
211
  if (isMusl()) {
228
212
  localFileExisted = existsSync(
229
- join(__dirname, 'node-webrtc-rust.linux-arm-musleabihf.node')
213
+ join(__dirname, 'node-webrtc-rust.linux-arm-musleabihf.node'),
230
214
  )
231
215
  try {
232
216
  if (localFileExisted) {
@@ -239,7 +223,7 @@ switch (platform) {
239
223
  }
240
224
  } else {
241
225
  localFileExisted = existsSync(
242
- join(__dirname, 'node-webrtc-rust.linux-arm-gnueabihf.node')
226
+ join(__dirname, 'node-webrtc-rust.linux-arm-gnueabihf.node'),
243
227
  )
244
228
  try {
245
229
  if (localFileExisted) {
@@ -254,9 +238,7 @@ switch (platform) {
254
238
  break
255
239
  case 'riscv64':
256
240
  if (isMusl()) {
257
- localFileExisted = existsSync(
258
- join(__dirname, 'node-webrtc-rust.linux-riscv64-musl.node')
259
- )
241
+ localFileExisted = existsSync(join(__dirname, 'node-webrtc-rust.linux-riscv64-musl.node'))
260
242
  try {
261
243
  if (localFileExisted) {
262
244
  nativeBinding = require('./node-webrtc-rust.linux-riscv64-musl.node')
@@ -267,9 +249,7 @@ switch (platform) {
267
249
  loadError = e
268
250
  }
269
251
  } else {
270
- localFileExisted = existsSync(
271
- join(__dirname, 'node-webrtc-rust.linux-riscv64-gnu.node')
272
- )
252
+ localFileExisted = existsSync(join(__dirname, 'node-webrtc-rust.linux-riscv64-gnu.node'))
273
253
  try {
274
254
  if (localFileExisted) {
275
255
  nativeBinding = require('./node-webrtc-rust.linux-riscv64-gnu.node')
@@ -282,9 +262,7 @@ switch (platform) {
282
262
  }
283
263
  break
284
264
  case 's390x':
285
- localFileExisted = existsSync(
286
- join(__dirname, 'node-webrtc-rust.linux-s390x-gnu.node')
287
- )
265
+ localFileExisted = existsSync(join(__dirname, 'node-webrtc-rust.linux-s390x-gnu.node'))
288
266
  try {
289
267
  if (localFileExisted) {
290
268
  nativeBinding = require('./node-webrtc-rust.linux-s390x-gnu.node')
@@ -310,14 +288,42 @@ if (!nativeBinding) {
310
288
  throw new Error(`Failed to load native binding`)
311
289
  }
312
290
 
313
- const { JsConferenceRoom, JsConferenceServer, JsMuteScope, JsRtcDataChannel, JsMediaStreamTrack, JsMediaStream, JsLocalAudioTrack, JsPeerConnection, version } = nativeBinding
291
+ const {
292
+ JsConferenceRoom,
293
+ JsConferenceServer,
294
+ JsEventDeliveryMode,
295
+ JsLocalAudioTrack,
296
+ JsMediaStream,
297
+ JsMediaStreamTrack,
298
+ JsMuteScope,
299
+ JsPeerConnection,
300
+ JsRtcDataChannel,
301
+ JsRtpReceiver,
302
+ JsRtpSender,
303
+ JsRtpTransceiver,
304
+ JsSpeechEventType,
305
+ JsSttVendor,
306
+ JsTtsVendor,
307
+ JsVadSampleRate,
308
+ JsVoiceAgent,
309
+ version,
310
+ } = nativeBinding
314
311
 
315
312
  module.exports.JsConferenceRoom = JsConferenceRoom
316
313
  module.exports.JsConferenceServer = JsConferenceServer
317
- module.exports.JsMuteScope = JsMuteScope
318
- module.exports.JsRtcDataChannel = JsRtcDataChannel
319
- module.exports.JsMediaStreamTrack = JsMediaStreamTrack
320
- module.exports.JsMediaStream = JsMediaStream
314
+ module.exports.JsEventDeliveryMode = JsEventDeliveryMode
321
315
  module.exports.JsLocalAudioTrack = JsLocalAudioTrack
316
+ module.exports.JsMediaStream = JsMediaStream
317
+ module.exports.JsMediaStreamTrack = JsMediaStreamTrack
318
+ module.exports.JsMuteScope = JsMuteScope
322
319
  module.exports.JsPeerConnection = JsPeerConnection
320
+ module.exports.JsRtcDataChannel = JsRtcDataChannel
321
+ module.exports.JsRtpReceiver = JsRtpReceiver
322
+ module.exports.JsRtpSender = JsRtpSender
323
+ module.exports.JsRtpTransceiver = JsRtpTransceiver
324
+ module.exports.JsSpeechEventType = JsSpeechEventType
325
+ module.exports.JsSttVendor = JsSttVendor
326
+ module.exports.JsTtsVendor = JsTtsVendor
327
+ module.exports.JsVadSampleRate = JsVadSampleRate
328
+ module.exports.JsVoiceAgent = JsVoiceAgent
323
329
  module.exports.version = version
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-webrtc-rust/bindings",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "NAPI-RS native bindings for node-webrtc-rust — WebRTC peer connections, data channels, and conference audio mixing",
5
5
  "keywords": [
6
6
  "webrtc",
@@ -58,12 +58,12 @@
58
58
  "@napi-rs/cli": "^2.18.0"
59
59
  },
60
60
  "optionalDependencies": {
61
- "@node-webrtc-rust/bindings-darwin-arm64": "0.2.1",
62
- "@node-webrtc-rust/bindings-darwin-x64": "0.2.1",
63
- "@node-webrtc-rust/bindings-linux-arm64-gnu": "0.2.1",
64
- "@node-webrtc-rust/bindings-linux-x64-gnu": "0.2.1",
65
- "@node-webrtc-rust/bindings-linux-x64-musl": "0.2.1",
66
- "@node-webrtc-rust/bindings-win32-x64-msvc": "0.2.1"
61
+ "@node-webrtc-rust/bindings-win32-x64-msvc": "0.4.0",
62
+ "@node-webrtc-rust/bindings-darwin-x64": "0.4.0",
63
+ "@node-webrtc-rust/bindings-linux-x64-gnu": "0.4.0",
64
+ "@node-webrtc-rust/bindings-darwin-arm64": "0.4.0",
65
+ "@node-webrtc-rust/bindings-linux-arm64-gnu": "0.4.0",
66
+ "@node-webrtc-rust/bindings-linux-x64-musl": "0.4.0"
67
67
  },
68
68
  "engines": {
69
69
  "node": ">=18"