Timer
Updated: 2021-10-14 17:47:17
Feature Overview
- Countdown can only be initiated by the host role. Once initiated, all users with the guest or host role will receive the countdown message.
- When starting the countdown, you can set whether overtime is allowed. If overtime is allowed, the timer will continue counting up after the countdown ends.
Code Example
Note: Before proceeding with the following steps, global initialization settings must be completed. Please refer to the documentation.
Basic Flow
const app = new Timer();
// 订阅事件监听。
app
.on('start', () => {})
.on('stop', () => {})
.on('end', () => {})
.on('restart', () => {});
// 开始倒计时。操作成功后,'start' 事件会被触发。
app.start({ time: 30, enableTimeOut: true });
// 定时器每秒更新一次计时状态
let timer = 0;
function clearTimer() {
if (!timer) return;
clearTimeout(timer);
timer = 0;
}
async function updateStatus() {
app.getTimerStatus();
clearTimer();
timer = setTimeout(updateStatus, 1000);
}
updateStatus();
// 暂停倒计时。操作成功后,'stop' 事件会被触发。
app.stop();
// 重新开始倒计时。操作成功后,'restart' 事件会被触发。
app.restart();
// 结束倒计时。操作成功后,'end' 事件会被触发。
app.end();
