using System; using System.Net.Http.Headers; using System.Threading.Tasks; using Chtn.CSharp.SDK.Core; using Chtn.CSharp.SDK.Models.Media; namespace Chtn.CSharp.SDK.Services { public interface IFileTransferService { Task StartNew(string targetUserId, string fileName, long fileSize); Task Accept(string transferId); Task Decline(string transferId); Task SendRtcOffer(string transferId, object offer); Task SendRtcAnswer(string transferId, object answer); Task SendRtcIce(string transferId, object ice); } public class FileTransferService : IFileTransferService { private readonly ApiClient _apiClient; private readonly string _userId; private readonly object _webSocket; public FileTransferService(ApiClient apiClient, string userId, object webSocket) { _apiClient = apiClient ?? throw new ArgumentNullException(nameof(ApiClient)); _userId = userId; _webSocket = webSocket ?? throw new ArgumentNullException(nameof(webSocket)); } public async Task StartNew(string targetUserId, string fileName, long fileSize) { var body = new { userid = _userId, targetId = targetUserId, name = fileName, size = fileSize }; return await _apiClient.PostAsync("v2/chat/dm/startNewFileTransfer", body); } public async Task Accept(string transferId) { var body = new { userid = _userId, transferId = transferId }; await _apiClient.PostAsync("v2/chat/dm/acceptFileTransfer", body); } public async Task Decline(string transferId) { var body = new { userid = _userId, transferId = transferId }; await _apiClient.PostAsync("v2/chat/dm/declineFileTransfer", body); } public async Task SendRtcOffer(string transferId, object offer) { var body = new { userid = _userId, transferId = transferId, offer = offer }; await _apiClient.PostAsync("v2/chat/dm/sendRtcOfferFileTransfer", body); } public async Task SendRtcAnswer(string transferId, object answer) { var body = new { userid = _userId, transferId = transferId, answer = answer }; await _apiClient.PostAsync("v2/chat/dm/sendRtcAnswerFileTransfer", body); } public async Task SendRtcIce(string transferId, object ice) { var body = new { userid = _userId, transferId = transferId, ice = ice }; await _apiClient.PostAsync("v2/chat/dm/sendRtcICEFileTransfer", body); } } }