Skip to content

Commit cdd3913

Browse files
authored
Add maximum trasmit time for PTT (#2312)
on sender side by muting mic after the max transmit time has elapsed.
1 parent 998ac56 commit cdd3913

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/webrtc/groupCall.ts

+29
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export class GroupCall extends EventEmitter {
112112
public activeSpeakerInterval = 1000;
113113
public retryCallInterval = 5000;
114114
public participantTimeout = 1000 * 15;
115+
public pttMaxTransmitTime = 1000 * 20;
115116

116117
public state = GroupCallState.LocalCallFeedUninitialized;
117118
public activeSpeaker?: string; // userId
@@ -129,6 +130,7 @@ export class GroupCall extends EventEmitter {
129130
private retryCallLoopTimeout?: number;
130131
private retryCallCounts: Map<string, number> = new Map();
131132
private reEmitter: ReEmitter;
133+
private transmitTimer: number | null = null;
132134

133135
constructor(
134136
private client: MatrixClient,
@@ -325,17 +327,32 @@ export class GroupCall extends EventEmitter {
325327
this.retryCallCounts.clear();
326328
clearTimeout(this.retryCallLoopTimeout);
327329

330+
if (this.transmitTimer !== null) {
331+
clearTimeout(this.transmitTimer);
332+
this.transmitTimer = null;
333+
}
334+
328335
this.client.removeListener("Call.incoming", this.onIncomingCall);
329336
}
330337

331338
public leave() {
339+
if (this.transmitTimer !== null) {
340+
clearTimeout(this.transmitTimer);
341+
this.transmitTimer = null;
342+
}
343+
332344
this.dispose();
333345
this.setState(GroupCallState.LocalCallFeedUninitialized);
334346
}
335347

336348
public async terminate(emitStateEvent = true) {
337349
this.dispose();
338350

351+
if (this.transmitTimer !== null) {
352+
clearTimeout(this.transmitTimer);
353+
this.transmitTimer = null;
354+
}
355+
339356
this.participants = [];
340357
this.client.removeListener(
341358
"RoomState.members",
@@ -389,6 +406,18 @@ export class GroupCall extends EventEmitter {
389406
return false;
390407
}
391408

409+
// set a timer for the maximum transmit time on PTT calls
410+
if (this.isPtt) {
411+
if (!muted && this.isMicrophoneMuted()) {
412+
this.transmitTimer = setTimeout(() => {
413+
this.setMicrophoneMuted(true);
414+
}, this.pttMaxTransmitTime);
415+
} else if (muted && !this.isMicrophoneMuted()) {
416+
clearTimeout(this.transmitTimer);
417+
this.transmitTimer = null;
418+
}
419+
}
420+
392421
if (this.localCallFeed) {
393422
logger.log(`groupCall ${this.groupCallId} setMicrophoneMuted stream ${
394423
this.localCallFeed.stream.id} muted ${muted}`);

0 commit comments

Comments
 (0)