69 lines
2.8 KiB
C#
69 lines
2.8 KiB
C#
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<StartNewFileTransferResp> 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<StartNewFileTransferResp> StartNew(string targetUserId, string fileName, long fileSize)
|
|
{
|
|
var body = new { userid = _userId, targetId = targetUserId, name = fileName, size = fileSize };
|
|
return await _apiClient.PostAsync<object, StartNewFileTransferResp>("v2/chat/dm/startNewFileTransfer", body);
|
|
}
|
|
|
|
public async Task Accept(string transferId)
|
|
{
|
|
var body = new { userid = _userId, transferId = transferId };
|
|
await _apiClient.PostAsync<object, object>("v2/chat/dm/acceptFileTransfer", body);
|
|
}
|
|
|
|
public async Task Decline(string transferId)
|
|
{
|
|
var body = new { userid = _userId, transferId = transferId };
|
|
await _apiClient.PostAsync<object, object>("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<object, object>("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<object, object>("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<object, object>("v2/chat/dm/sendRtcICEFileTransfer", body);
|
|
}
|
|
}
|
|
}
|