@marianmeres/webrtc 1.2.5 → 1.2.6
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 +48 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -105,6 +105,54 @@ const dc = manager.getDataChannel(label)
|
|
|
105
105
|
manager.sendData(label, data) // Returns boolean
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
+
### Working with External Audio Streams
|
|
109
|
+
|
|
110
|
+
You might want to keep `enableMicrophone: false` even when your application uses audio. Common scenarios include:
|
|
111
|
+
|
|
112
|
+
- **Pre-acquired stream**: You may have obtained the audio stream earlier in the application flow (e.g., during a permissions check, in a lobby/waiting room, or for local audio preview before joining)
|
|
113
|
+
- **Custom audio processing**: You want to apply audio effects, noise suppression, or other processing via Web Audio API before transmitting
|
|
114
|
+
- **Multiple sources**: You need to mix audio from multiple sources (microphone + system audio, multiple microphones, background music, etc.)
|
|
115
|
+
- **Fine-grained privacy control**: You want explicit control over exactly when the microphone activates
|
|
116
|
+
- **Testing**: You want to inject synthetic audio (e.g., oscillator tones) for automated testing
|
|
117
|
+
|
|
118
|
+
To use your own audio stream, access the `peerConnection` directly and add tracks after initialization:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
const manager = new WebRtcManager(factory, {
|
|
122
|
+
peerConfig: { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] },
|
|
123
|
+
enableMicrophone: false, // We'll handle the audio stream ourselves
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// Your pre-acquired or processed audio stream
|
|
127
|
+
const myAudioStream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
128
|
+
|
|
129
|
+
// Or a processed stream via Web Audio API
|
|
130
|
+
const audioCtx = new AudioContext();
|
|
131
|
+
const source = audioCtx.createMediaStreamSource(myAudioStream);
|
|
132
|
+
const gainNode = audioCtx.createGain();
|
|
133
|
+
gainNode.gain.value = 0.8;
|
|
134
|
+
source.connect(gainNode);
|
|
135
|
+
const destination = audioCtx.createMediaStreamDestination();
|
|
136
|
+
gainNode.connect(destination);
|
|
137
|
+
const processedStream = destination.stream;
|
|
138
|
+
|
|
139
|
+
// Initialize the manager
|
|
140
|
+
await manager.initialize();
|
|
141
|
+
|
|
142
|
+
// Add your audio track to the peer connection
|
|
143
|
+
const pc = manager.peerConnection;
|
|
144
|
+
if (pc) {
|
|
145
|
+
processedStream.getAudioTracks().forEach((track) => {
|
|
146
|
+
pc.addTrack(track, processedStream);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Continue with normal connection flow
|
|
151
|
+
await manager.connect();
|
|
152
|
+
const offer = await manager.createOffer();
|
|
153
|
+
// ...
|
|
154
|
+
```
|
|
155
|
+
|
|
108
156
|
### Event Subscription
|
|
109
157
|
|
|
110
158
|
```typescript
|