refactor SDK to stateful architecture and implement reactive websocket handling

This commit is contained in:
2026-05-03 20:30:29 +02:00
parent 6d7151ebe6
commit e7e8f6b1a9
3 changed files with 73 additions and 1 deletions

View File

@@ -0,0 +1,51 @@
using System;
using System.Threading.Tasks;
using Chtn.CSharp.SDK.Core;
using Chtn.CSharp.SDK.Models.Call;
using Chtn.CSharpSDK.Core;
namespace Chtn.CSharp.SDK.Services
{
public interface IBroadcastService
{
Task<StreamRegistry> GetData(GetRtmpDataReq req);
Task CreateService(CreateServerReq req);
Task JoinWebSocketRoom(BroadcastJoinWsRoomReq req);
}
public class BroadcastServiceProvider : IBroadcastService
{
private readonly ApiClient _apiClient;
private readonly string _channelId;
private readonly string _categoryId;
private readonly string _networkId;
private readonly string _userId;
private string _connId;
public BroadcastServiceProvider(
ApiClient apiClient,
string channelId,
string categoryId,
string networkId,
string userId)
{
_apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient));
_channelId = channelId;
_categoryId = categoryId;
_networkId = networkId;
_userId = userId;
var ws = WebSocketHandler.GetInstance();
this._connId = ws.ConnId;
ws.OnNewConnectionId += (newConnId) => this._connId = newConnId;
}
public async Task<StreamRegistry> GetData(GetRtmpDataReq req) =>
await _apiClient.PostAsync<GetRtmpDataReq, StreamRegistry>("network/channel/rtmpData", req);
public async Task CreateService(CreateServerReq req) =>
await _apiClient.PostAsync<CreateServerReq, object>("network/channel/createServer", req);
public async Task JoinWebSocketRoom(BroadcastJoinWsRoomReq req) =>
await _apiClient.PostAsync<BroadcastJoinWsRoomReq, object>("v2/network/channel/joinWebSocketRoom", req);
}
}