Skip to content

Commit

Permalink
feat: add action inviteCall in livekit
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Nov 16, 2023
1 parent 72a68d3 commit 087713a
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion server/plugins/com.msgbyte.livekit/services/livekit.service.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 087713a

Please sign in to comment.