Group calling: Peek into a group call
This commit is contained in:
parent
af6ec26225
commit
6d53cb1740
15 changed files with 858 additions and 111 deletions
69
ts/util/LatestQueue.ts
Normal file
69
ts/util/LatestQueue.ts
Normal file
|
@ -0,0 +1,69 @@
|
|||
// Copyright 2020 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
/**
|
||||
* This class tries to enforce a state machine that looks something like this:
|
||||
*
|
||||
* .--------------------. called .-----------. called .---------------------.
|
||||
* | | --------> | | -------> | |
|
||||
* | Nothing is running | | 1 running | | 1 running, 1 queued |
|
||||
* | | <-------- | | <------- | |
|
||||
* '--------------------' done '-----------' done '---------------------'
|
||||
* | ^
|
||||
* '-----------'
|
||||
* called
|
||||
*
|
||||
* Most notably, if something is queued and the function is called again, we discard the
|
||||
* previously queued task completely.
|
||||
*/
|
||||
export class LatestQueue {
|
||||
private isRunning: boolean;
|
||||
|
||||
private queuedTask?: () => Promise<void>;
|
||||
|
||||
private onceEmptyCallbacks: Array<() => unknown>;
|
||||
|
||||
constructor() {
|
||||
this.isRunning = false;
|
||||
this.onceEmptyCallbacks = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Does one of the following:
|
||||
*
|
||||
* 1. Runs the task immediately.
|
||||
* 2. Enqueues the task, destroying any previously-enqueued task. In other words, 0 or 1
|
||||
* tasks will be enqueued at a time.
|
||||
*/
|
||||
add(task: () => Promise<void>): void {
|
||||
if (this.isRunning) {
|
||||
this.queuedTask = task;
|
||||
} else {
|
||||
this.isRunning = true;
|
||||
task().finally(() => {
|
||||
this.isRunning = false;
|
||||
|
||||
const { queuedTask } = this;
|
||||
if (queuedTask) {
|
||||
this.queuedTask = undefined;
|
||||
this.add(queuedTask);
|
||||
} else {
|
||||
try {
|
||||
this.onceEmptyCallbacks.forEach(callback => {
|
||||
callback();
|
||||
});
|
||||
} finally {
|
||||
this.onceEmptyCallbacks = [];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a callback to be called the first time the queue goes from "running" to "empty".
|
||||
*/
|
||||
onceEmpty(callback: () => unknown): void {
|
||||
this.onceEmptyCallbacks.push(callback);
|
||||
}
|
||||
}
|
|
@ -14728,7 +14728,7 @@
|
|||
"rule": "React-createRef",
|
||||
"path": "ts/components/conversation/ConversationHeader.js",
|
||||
"line": " this.menuTriggerRef = react_1.default.createRef();",
|
||||
"lineNumber": 28,
|
||||
"lineNumber": 29,
|
||||
"reasonCategory": "usageTrusted",
|
||||
"updated": "2020-08-28T16:12:19.904Z",
|
||||
"reasonDetail": "Used to reference popup menu"
|
||||
|
@ -14737,7 +14737,7 @@
|
|||
"rule": "React-createRef",
|
||||
"path": "ts/components/conversation/ConversationHeader.tsx",
|
||||
"line": " this.menuTriggerRef = React.createRef();",
|
||||
"lineNumber": 100,
|
||||
"lineNumber": 101,
|
||||
"reasonCategory": "usageTrusted",
|
||||
"updated": "2020-05-20T20:10:43.540Z",
|
||||
"reasonDetail": "Used to reference popup menu"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue