cleanup prep and leave call prep
This commit is contained in:
@@ -249,6 +249,7 @@ public partial class MainPage : ContentPage
|
|||||||
case "rtc_call_left":
|
case "rtc_call_left":
|
||||||
{
|
{
|
||||||
SafeSendRawToWebView("RTC call left notification received.");
|
SafeSendRawToWebView("RTC call left notification received.");
|
||||||
|
RtcLeaveCallback();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,6 +417,7 @@ public partial class MainPage : ContentPage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region RTC Functions
|
||||||
public async Task<bool> JoinRtcChannel()
|
public async Task<bool> JoinRtcChannel()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(_currentChannelId))
|
if (string.IsNullOrWhiteSpace(_currentChannelId))
|
||||||
@@ -531,22 +533,35 @@ public partial class MainPage : ContentPage
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSendMessageButtonClicked(object sender, EventArgs e)
|
public async void RtcLeaveCallback()
|
||||||
{
|
{
|
||||||
SafeSendRawToWebView($"Hello from C#!");
|
try
|
||||||
}
|
|
||||||
|
|
||||||
private async void OnHybridWebViewRawMessageReceived(object sender, HybridWebViewRawMessageReceivedEventArgs e)
|
|
||||||
{
|
|
||||||
if (e.Message == "rtc_page_ready")
|
|
||||||
{
|
{
|
||||||
await PushRtcContextToJsAsync();
|
await hybridWebView.InvokeJavaScriptAsync("RtcLeaveCall", [], []);
|
||||||
return;
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
SafeSendRawToWebView("RtcLeaveCallback failed: " + ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
await DisplayAlertAsync("Raw Message Received", e.Message, "OK");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task SendRtcSignalToJsAsync(string rawJson)
|
||||||
|
{
|
||||||
|
var jsArg = JsonSerializer.Serialize(rawJson);
|
||||||
|
await hybridWebView.EvaluateJavaScriptAsync($"window.handleRtcSignal({jsArg})");
|
||||||
|
} //Remove?
|
||||||
|
|
||||||
|
private async Task PushRtcContextToJsAsync()
|
||||||
|
{
|
||||||
|
var usernameJson = JsonSerializer.Serialize(_username);
|
||||||
|
var channelIdJson = JsonSerializer.Serialize(_currentChannelId);
|
||||||
|
|
||||||
|
await hybridWebView.EvaluateJavaScriptAsync($"window.setUsername({usernameJson})");
|
||||||
|
await hybridWebView.EvaluateJavaScriptAsync($"window.setChannelId({channelIdJson})");
|
||||||
|
|
||||||
|
Console.WriteLine($"[{_username}] pushed RTC context into HybridWebView.");
|
||||||
|
} //Remove?
|
||||||
|
|
||||||
public void SendRtcSignal(string json)
|
public void SendRtcSignal(string json)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(_serverPublicKey))
|
if (string.IsNullOrWhiteSpace(_serverPublicKey))
|
||||||
@@ -584,23 +599,24 @@ public partial class MainPage : ContentPage
|
|||||||
|
|
||||||
_wsc.Send(JsonSerializer.Serialize(payload));
|
_wsc.Send(JsonSerializer.Serialize(payload));
|
||||||
Console.WriteLine($"[{_username}] sent RTC signal: {rtcSignal.Type} -> {rtcSignal.ChannelId}");
|
Console.WriteLine($"[{_username}] sent RTC signal: {rtcSignal.Type} -> {rtcSignal.ChannelId}");
|
||||||
|
} //Remove?
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
private void OnSendMessageButtonClicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SafeSendRawToWebView($"Hello from C#!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task SendRtcSignalToJsAsync(string rawJson)
|
private async void OnHybridWebViewRawMessageReceived(object sender, HybridWebViewRawMessageReceivedEventArgs e)
|
||||||
{
|
{
|
||||||
var jsArg = JsonSerializer.Serialize(rawJson);
|
if (e.Message == "rtc_page_ready")
|
||||||
await hybridWebView.EvaluateJavaScriptAsync($"window.handleRtcSignal({jsArg})");
|
{
|
||||||
}
|
await PushRtcContextToJsAsync();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
private async Task PushRtcContextToJsAsync()
|
await DisplayAlertAsync("Raw Message Received", e.Message, "OK");
|
||||||
{
|
|
||||||
var usernameJson = JsonSerializer.Serialize(_username);
|
|
||||||
var channelIdJson = JsonSerializer.Serialize(_currentChannelId);
|
|
||||||
|
|
||||||
await hybridWebView.EvaluateJavaScriptAsync($"window.setUsername({usernameJson})");
|
|
||||||
await hybridWebView.EvaluateJavaScriptAsync($"window.setChannelId({channelIdJson})");
|
|
||||||
|
|
||||||
Console.WriteLine($"[{_username}] pushed RTC context into HybridWebView.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SafeSendRawToWebView(string message)
|
private void SafeSendRawToWebView(string message)
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ window.setChannelId = function(channelId) {
|
|||||||
currentChannelId = channelId;
|
currentChannelId = channelId;
|
||||||
LogMessage("Channel set to: " + currentChannelId);
|
LogMessage("Channel set to: " + currentChannelId);
|
||||||
};
|
};
|
||||||
// let userMedia = getUserMedia()
|
|
||||||
function LogMessage(msg) {
|
function LogMessage(msg) {
|
||||||
const messageLog = document.getElementById("messageLog");
|
const messageLog = document.getElementById("messageLog");
|
||||||
messageLog.value += '\r\n' + msg;
|
messageLog.value += '\r\n' + msg;
|
||||||
@@ -96,7 +95,7 @@ async function ensurePeerConnection() {
|
|||||||
peerConnection.onicegatheringstatechange = () => {
|
peerConnection.onicegatheringstatechange = () => {
|
||||||
LogMessage("ICE gathering state: " + peerConnection.iceGatheringState);
|
LogMessage("ICE gathering state: " + peerConnection.iceGatheringState);
|
||||||
};
|
};
|
||||||
}
|
} //Remove?
|
||||||
async function ensureLocalMedia(forceReload = false) {
|
async function ensureLocalMedia(forceReload = false) {
|
||||||
const localMediaStatus = document.getElementById("localMediaStatus");
|
const localMediaStatus = document.getElementById("localMediaStatus");
|
||||||
const localVideoStatus = document.getElementById("localVideoStatus");
|
const localVideoStatus = document.getElementById("localVideoStatus");
|
||||||
@@ -239,7 +238,7 @@ async function joinChannelCall() {
|
|||||||
// } catch (err) {
|
// } catch (err) {
|
||||||
// LogMessage("joinChannelCall failed: " + err);
|
// LogMessage("joinChannelCall failed: " + err);
|
||||||
// }
|
// }
|
||||||
}
|
} //Combine with channelCallJoin
|
||||||
|
|
||||||
async function ensurePeerConnection2()
|
async function ensurePeerConnection2()
|
||||||
{
|
{
|
||||||
@@ -353,6 +352,9 @@ async function IceCandidateAdded(candidate)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function RtcLeaveCall()
|
||||||
|
{}
|
||||||
async function handleRtcSignal(rawJson) {
|
async function handleRtcSignal(rawJson) {
|
||||||
try {
|
try {
|
||||||
const msg = typeof rawJson === "string" ? JSON.parse(rawJson) : rawJson;
|
const msg = typeof rawJson === "string" ? JSON.parse(rawJson) : rawJson;
|
||||||
@@ -442,7 +444,7 @@ async function handleRtcSignal(rawJson) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
LogMessage("handleRtcSignal failed: " + err);
|
LogMessage("handleRtcSignal failed: " + err);
|
||||||
}
|
}
|
||||||
}
|
} //Remove?
|
||||||
|
|
||||||
async function loadDevices() {
|
async function loadDevices() {
|
||||||
try {
|
try {
|
||||||
@@ -526,7 +528,7 @@ async function waitForIceGatheringComplete(pc) {
|
|||||||
|
|
||||||
pc.addEventListener("icegatheringstatechange", checkState);
|
pc.addEventListener("icegatheringstatechange", checkState);
|
||||||
});
|
});
|
||||||
}
|
} //Remove?
|
||||||
|
|
||||||
window.handleRtcSignal = handleRtcSignal;
|
window.handleRtcSignal = handleRtcSignal;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user