Implemented BroadcastChannelService and FileTransferService
All checks were successful
Setup testing environment and test the code / build (push) Successful in 1m17s

This commit is contained in:
2026-04-08 08:46:16 +02:00
parent e6798b4be8
commit a9322e3454
10 changed files with 428 additions and 3 deletions

View File

@@ -0,0 +1,93 @@
import {AxiosInstance, isAxiosError} from "axios";
import {getClient} from "../core/http";
import {MessageListener} from "../domain/websocket.schema";
import {WebSocketHandler} from "../core/webSocketHandler";
import {AcceptInviteReq} from "../domain/networkService.schema";
import {GenericErrorBody} from "../domain/http.schema";
import {
CreateServerReq,
GetRTMPDataReq,
JoinWebsocketRoomReq,
StreamRegistry
} from "../domain/broadcastChannelService.schema";
export class BroadcastChannelService {
userid: string
channelId: string
networkId: string
categoryId: string
client: AxiosInstance;
constructor(token: string, userid: string, networkId: string, categoryId: string, channelId: string, wsMessageListener: MessageListener) {
this.userid = userid;
this.channelId = channelId;
this.categoryId = categoryId;
this.networkId = networkId;
this.client = getClient(false).create({
headers: {
"Authorization": token,
"X-WS-ID": WebSocketHandler.getInstance().connId
}
})
WebSocketHandler.getInstance().registerService({
identifier: channelId,
onNewConnId: this.onNewConnId,
onNewMessage: wsMessageListener,
})
}
private onNewConnId(newConnId: string) {
console.log("NetworkService: New connection id")
this.client.defaults.headers["X-WS-ID"] = newConnId;
}
async getData(): Promise<StreamRegistry> {
try {
const resp = await this.client.get<StreamRegistry>(`network/channel/rtmpData?userid=${this.userid}&channelId=${this.channelId}&networkId=${this.networkId}&categoryId=${this.categoryId}`);
return resp.data
} catch (e) {
console.log(e)
if (isAxiosError<GenericErrorBody>(e)) {
throw e;
}
throw new Error("Unexpected error")
}
}
async createServer(): Promise<StreamRegistry> {
try {
const resp = await this.client.post<StreamRegistry>("network/channel/createServer", <CreateServerReq>{
userid: this.userid,
channelId: this.channelId,
networkId: this.networkId,
type: "rtmp",
categoryId: this.categoryId,
});
return resp.data
} catch (e) {
console.log(e)
if (isAxiosError<GenericErrorBody>(e)) {
throw e;
}
throw new Error("Unexpected error")
}
}
async joinWebSocketRoom(): Promise<void> {
try {
await this.client.post("v2/network/channel/joinWebSocketRoom", <JoinWebsocketRoomReq>{
userid: this.userid,
channelId: this.channelId,
networkId: this.networkId,
connId: WebSocketHandler.getInstance().connId,
categoryId: this.categoryId,
});
return
} catch (e) {
if (isAxiosError<GenericErrorBody>(e)) {
throw e;
}
throw new Error("Unexpected error")
}
}
}