21 lines
876 B
TypeScript
21 lines
876 B
TypeScript
import { MatrixEvent } from 'matrix-js-sdk';
|
|
import { IRTCNotificationContent } from 'matrix-js-sdk/lib/matrixrtc/types';
|
|
|
|
export const RTC_NOTIFICATION_DEFAULT_LIFETIME = 30_000;
|
|
|
|
export const getNotificationEventSendTs = (ev: MatrixEvent): number => {
|
|
const content = ev.getContent<IRTCNotificationContent>();
|
|
const sendTs = content.sender_ts;
|
|
const eventTs = ev.getTs();
|
|
if (sendTs && Math.abs(sendTs - eventTs) >= 15_000) return eventTs;
|
|
return sendTs ?? eventTs;
|
|
};
|
|
|
|
export const isRtcNotificationExpired = (ev: MatrixEvent, now = Date.now()): boolean => {
|
|
const content = ev.getContent<IRTCNotificationContent>();
|
|
const lifetime = content.lifetime ?? RTC_NOTIFICATION_DEFAULT_LIFETIME;
|
|
return now - getNotificationEventSendTs(ev) > lifetime;
|
|
};
|
|
|
|
export const getIncomingCallKey = (callId: string, roomId: string): string =>
|
|
`call_${callId}_${roomId}`;
|