Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maximum trasmit time for PTT #2312

Merged
merged 2 commits into from
Apr 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/webrtc/groupCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export class GroupCall extends EventEmitter {
public activeSpeakerInterval = 1000;
public retryCallInterval = 5000;
public participantTimeout = 1000 * 15;
public pttMaxTransmitTime = 1000 * 20;

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

constructor(
private client: MatrixClient,
Expand Down Expand Up @@ -325,17 +327,32 @@ export class GroupCall extends EventEmitter {
this.retryCallCounts.clear();
clearTimeout(this.retryCallLoopTimeout);

if (this.transmitTimer !== null) {
clearTimeout(this.transmitTimer);
this.transmitTimer = null;
}

this.client.removeListener("Call.incoming", this.onIncomingCall);
}

public leave() {
if (this.transmitTimer !== null) {
clearTimeout(this.transmitTimer);
this.transmitTimer = null;
}

this.dispose();
this.setState(GroupCallState.LocalCallFeedUninitialized);
}

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

if (this.transmitTimer !== null) {
clearTimeout(this.transmitTimer);
this.transmitTimer = null;
}

this.participants = [];
this.client.removeListener(
"RoomState.members",
Expand Down Expand Up @@ -389,6 +406,18 @@ export class GroupCall extends EventEmitter {
return false;
}

// set a timer for the maximum transmit time on PTT calls
if (this.isPtt) {
if (!muted && this.isMicrophoneMuted()) {
this.transmitTimer = setTimeout(() => {
this.setMicrophoneMuted(true);
}, this.pttMaxTransmitTime);
} else if (muted && !this.isMicrophoneMuted()) {
clearTimeout(this.transmitTimer);
this.transmitTimer = null;
}
}

if (this.localCallFeed) {
logger.log(`groupCall ${this.groupCallId} setMicrophoneMuted stream ${
this.localCallFeed.stream.id} muted ${muted}`);
Expand Down