From 087713afbf4aae7c50c139871eae6ecabc16956c Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Thu, 16 Nov 2023 15:59:30 +0800 Subject: [PATCH] feat: add action inviteCall in livekit --- .../services/livekit.service.ts | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/server/plugins/com.msgbyte.livekit/services/livekit.service.ts b/server/plugins/com.msgbyte.livekit/services/livekit.service.ts index 6b0abbe57f7..bad24c83f9a 100644 --- a/server/plugins/com.msgbyte.livekit/services/livekit.service.ts +++ b/server/plugins/com.msgbyte.livekit/services/livekit.service.ts @@ -1,5 +1,5 @@ import type { TcContext } from 'tailchat-server-sdk'; -import { TcService, TcDbService } from 'tailchat-server-sdk'; +import { TcService, TcDbService, call } from 'tailchat-server-sdk'; import type { LivekitDocument, LivekitModel } from '../models/livekit'; import { AccessToken, @@ -72,6 +72,12 @@ class LivekitService extends TcService { roomName: 'string', }, }); + this.registerAction('inviteCall', this.inviteCall, { + params: { + roomName: 'string', + targetUserIds: { type: 'array', items: 'string' }, + }, + }); this.registerAction('webhook', this.webhook); } @@ -126,6 +132,28 @@ class LivekitService extends TcService { } } + /** + * 邀请加入会话 + */ + async inviteCall( + ctx: TcContext<{ roomName: string; targetUserIds: string[] }> + ) { + const { roomName, targetUserIds } = ctx.params; + const senderUserId = ctx.meta.userId; + + const isOnlineList = await call(ctx).isUserOnline(targetUserIds); + + await this.listcastNotify(ctx, targetUserIds, 'inviteCall', { + senderUserId, + roomName, + }); + + return { + online: targetUserIds.filter((_, i) => isOnlineList[i]), + offline: targetUserIds.filter((_, i) => !isOnlineList[i]), + }; + } + async webhook(ctx: TcContext) { const payload = ctx.params as WebhookEvent;