Skip to content

Commit 13c266c

Browse files
authored
Fix toggling microphone on/off. (#548)
1 parent a48ee7f commit 13c266c

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

js/hang-demo/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default defineConfig({
66
plugins: [tailwindcss()],
77
build: {
88
target: "esnext",
9+
sourcemap: process.env.NODE_ENV === "production" ? false : "inline",
910
rollupOptions: {
1011
input: {
1112
watch: "index.html",

js/hang/src/publish/audio/index.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ export class Audio {
7474
#gain = new Signal<GainNode | undefined>(undefined);
7575
readonly root: Getter<AudioNode | undefined> = this.#gain;
7676

77+
#track = new Moq.TrackProducer("audio", 1);
7778
#group?: Moq.GroupProducer;
7879
#groupTimestamp = 0;
7980

80-
#id = 0;
8181
#signals = new Effect();
8282

8383
constructor(broadcast: Moq.BroadcastProducer, props?: AudioProps) {
@@ -165,11 +165,10 @@ export class Audio {
165165
const worklet = effect.get(this.#worklet);
166166
if (!worklet) return;
167167

168-
const track = new Moq.TrackProducer(`audio-${this.#id++}`, 1);
169-
effect.cleanup(() => track.close());
170-
171-
this.broadcast.insertTrack(track.consume());
172-
effect.cleanup(() => this.broadcast.removeTrack(track.name));
168+
this.broadcast.insertTrack(this.#track.consume());
169+
effect.cleanup(() => {
170+
this.broadcast.removeTrack(this.#track.name);
171+
});
173172

174173
const settings = media.getSettings() as AudioTrackSettings;
175174

@@ -178,8 +177,8 @@ export class Audio {
178177

179178
const catalog: Catalog.Audio = {
180179
track: {
181-
name: track.name,
182-
priority: u8(track.priority),
180+
name: this.#track.name,
181+
priority: u8(this.#track.priority),
183182
},
184183
config: {
185184
// TODO get codec and description from decoderConfig
@@ -203,7 +202,7 @@ export class Audio {
203202

204203
if (!this.#group || frame.timestamp - this.#groupTimestamp >= 1000 * this.maxLatency) {
205204
this.#group?.close();
206-
this.#group = track.appendGroup();
205+
this.#group = this.#track.appendGroup();
207206
this.#groupTimestamp = frame.timestamp;
208207
}
209208

@@ -214,11 +213,17 @@ export class Audio {
214213
this.#group?.abort(err);
215214
this.#group = undefined;
216215

217-
track.abort(err);
216+
this.#track.abort(err);
218217
},
219218
});
220219
effect.cleanup(() => encoder.close());
221220

221+
effect.cleanup(() => {
222+
this.#group?.close();
223+
this.#group = undefined;
224+
this.#groupTimestamp = 0;
225+
});
226+
222227
const config = catalog.config;
223228

224229
encoder.configure({
@@ -256,5 +261,6 @@ export class Audio {
256261
close() {
257262
this.#signals.close();
258263
this.captions.close();
264+
this.#track.close();
259265
}
260266
}

0 commit comments

Comments
 (0)