refactor SDK to stateful architecture and implement reactive websocket handling
This commit is contained in:
51
Services/BroadcastChannelService.cs
Normal file
51
Services/BroadcastChannelService.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user