Finished implementing CallService

This commit is contained in:
2026-04-04 21:14:36 +02:00
parent cf9fee5186
commit 24285c3972
5 changed files with 101 additions and 1 deletions

View File

@@ -0,0 +1,17 @@
export interface InviteToCallReq {
userid: string
chatid: string
targetId: string
}
export interface GetRTCAccessReq {
roomId: string
roomType: string
userid: string
networkId: string
}
export interface GetRTCAccessResp {
rtcConfig: RTCConfiguration
liveKitToken: string
}

View File

@@ -0,0 +1,10 @@
import {http, HttpResponse} from "msw";
import {GetRTCAccessResp} from "../../domain/callService.schema";
export const callHandlers = [
http.post('*/v2/chat/getRTCAccess', () => {
return HttpResponse.json(<GetRTCAccessResp>{
liveKitToken: "liveKitToken",
})
}),
]

View File

@@ -1,9 +1,11 @@
import {networkHandlers} from "./handlers/auth.http";
import {authHandlers} from "./handlers/network.http";
import {pictureHandlers} from "./handlers/picture.http";
import {callHandlers} from "./handlers/call.http";
export const allHandlers = [
...authHandlers,
...networkHandlers,
...pictureHandlers
...pictureHandlers,
...callHandlers
]

View File

@@ -0,0 +1,11 @@
import {describe, expect, it} from "vitest";
import {CallService} from "./callService";
describe("CallService", () => {
const handler = new CallService("", "")
it('should get RTC access', async () => {
const access = await handler.getRTCAccess("", "", "", null)
expect(access.liveKitToken).toBe("liveKitToken");
});
})

View File

@@ -0,0 +1,60 @@
import {getClient} from "../core/http";
import {OtpPleCodeSendTestingResp, OtpSendCodeReq} from "../domain/authService.schema";
import {isAxiosError} from "axios";
import {GenericErrorBody} from "../domain/http.schema";
import {GetRTCAccessReq, GetRTCAccessResp, InviteToCallReq} from "../domain/callService.schema";
export class CallService {
userid: string;
token: string;
constructor(token: string, userid: string) {
this.token = token;
this.userid = userid;
}
/**
* Calls your chat partner (WebSocket + Apple VoIP PUSH)
* @param targetId
* @param chatid
*/
async inviteToCall(targetId: string, chatid: string): Promise<void> {
try {
await getClient(false).post("v2/chat/rtcInvite", <InviteToCallReq>{
userid: this.userid,
chatid: chatid,
targetId: targetId
});
return
} catch (e) {
if (isAxiosError<GenericErrorBody>(e)) {
throw e;
}
throw new Error("Unexpected error")
}
}
/**
* Provides access to liveKit and a WebRTC configuration
* @param targetId
* @param roomId
* @param roomType
* @param networkId
*/
async getRTCAccess(targetId: string, roomId: string, roomType: string, networkId: string|null): Promise<GetRTCAccessResp> {
try {
const resp = await getClient(false).post("v2/chat/getRTCAccess", <GetRTCAccessReq>{
userid: targetId,
networkId: networkId,
roomId: roomId,
roomType: roomType,
});
return resp.data
} catch (e) {
if (isAxiosError<GenericErrorBody>(e)) {
throw e;
}
throw new Error("Unexpected error")
}
}
}