setup client to make calls to servers api for webrtc data management
This commit is contained in:
@@ -32,7 +32,7 @@ public partial class MainPage : ContentPage
|
||||
}
|
||||
|
||||
_wsc = new WebSocket("ws://localhost:1337/");
|
||||
|
||||
|
||||
_wsc.OnMessage += WscOnMessage;
|
||||
_wsc.Connect();
|
||||
|
||||
@@ -42,6 +42,7 @@ public partial class MainPage : ContentPage
|
||||
_wsc.Send("GET_CHANNELS");
|
||||
|
||||
hybridWebView.SetInvokeJavaScriptTarget(this);
|
||||
ServerAPI.setupClient();
|
||||
|
||||
}
|
||||
|
||||
@@ -353,21 +354,58 @@ public partial class MainPage : ContentPage
|
||||
}
|
||||
}
|
||||
|
||||
public void JoinRtcChannel()
|
||||
public async Task<bool> JoinRtcChannel()
|
||||
{
|
||||
//TODO: get bool value for if channel ID has an active call
|
||||
//TODO: Join RTC using current channel ID
|
||||
hybridWebView.SendRawMessage($"Attempting to join RTC Channel {_currentChannelName}");
|
||||
bool active = await ServerAPI.GetIsChannelActiveAsync(_currentChannelId);
|
||||
hybridWebView.SendRawMessage($"Rtc Channel {_currentChannelName} is active: {active}");
|
||||
return active;
|
||||
//await hybridWebView.EvaluateJavaScriptAsync($"window.channelCallJoin({active})");
|
||||
|
||||
}
|
||||
public async void WriteRtcOffer(string json)
|
||||
{
|
||||
try
|
||||
{
|
||||
RtcDescription? description = JsonSerializer.Deserialize<RtcDescription>(json);
|
||||
DBOffer offer = new DBOffer
|
||||
{
|
||||
ChannelId = _currentChannelId,
|
||||
Username = _username,
|
||||
SessionDescription = description
|
||||
};
|
||||
await ServerAPI.PostOfferAsync(offer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
hybridWebView.SendRawMessage(ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
public async Task<string> GetRtcOffer()
|
||||
{
|
||||
RtcDescription? offer = await ServerAPI.GetOffersForChannelAsync(_currentChannelId);
|
||||
return JsonSerializer.Serialize(offer);
|
||||
}
|
||||
public async void WriteRtcAnswer(string json)
|
||||
{
|
||||
RtcDescription? description = JsonSerializer.Deserialize<RtcDescription>(json);
|
||||
DBOffer answer = new DBOffer
|
||||
{
|
||||
ChannelId = _currentChannelId,
|
||||
Username = _username,
|
||||
SessionDescription = description
|
||||
};
|
||||
await ServerAPI.PostAnswerAsync(answer);
|
||||
}
|
||||
|
||||
public void WriteRtcOffer(string json)
|
||||
public async void AnswerCallback(RtcDescription answer)
|
||||
{
|
||||
RTCOffer? offer = JsonSerializer.Deserialize<RTCOffer>(json);
|
||||
}
|
||||
private class RTCOffer
|
||||
{
|
||||
private string type { get; set; }
|
||||
private string sdp { get; set; }
|
||||
await hybridWebView.EvaluateJavaScriptAsync($"window.AnswerCallback({answer})");
|
||||
}
|
||||
|
||||
private void OnSendMessageButtonClicked(object sender, EventArgs e)
|
||||
{
|
||||
hybridWebView.SendRawMessage($"Hello from C#!");
|
||||
|
||||
Reference in New Issue
Block a user