From f01ca450d5377547f5a0599f8ce05c5788befd53 Mon Sep 17 00:00:00 2001 From: mekya Date: Sun, 13 Oct 2024 21:55:40 +0300 Subject: [PATCH] Support role in conference sample --- src/main/webapp/conference.html | 47 +++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/main/webapp/conference.html b/src/main/webapp/conference.html index f6ba55f5..27dd9122 100644 --- a/src/main/webapp/conference.html +++ b/src/main/webapp/conference.html @@ -244,15 +244,18 @@

WebRTC Multitrack Conference

var token = getUrlParameter("token"); var publishStreamId = getUrlParameter("streamId"); var playOnly = getUrlParameter("playOnly"); - var dcOnly = getUrlParameter("dcOnly"); - if (playOnly == null) { - playOnly = false; + playOnly = false; } - + + var dcOnly = getUrlParameter("dcOnly"); + if (dcOnly == null) { dcOnly = false; } + + var role = getUrlParameter("role"); + var roomId = getUrlParameter("roomId"); var streamName = getUrlParameter("streamName"); @@ -405,21 +408,32 @@

WebRTC Multitrack Conference

function sendData() { try { var iceState = webRTCAdaptor.iceConnectionState(publishStreamId); + var msg = $("#dataTextbox").val(); + var notEvent = { streamId: publishStreamId, eventType: "CHAT_MESSAGE", message: msg }; + if (iceState != null && iceState != "failed" && iceState != "disconnected") { - var msg = $("#dataTextbox").val(); - var notEvent = { streamId: publishStreamId, eventType: "CHAT_MESSAGE", message: msg }; + webRTCAdaptor.sendData(publishStreamId, JSON.stringify(notEvent)); $("#all-messages").append("Sent: " + msg + "
"); $("#dataTextbox").val(""); } else { - $.notify("WebRTC playing is not active. Please click Start Playing first", { - autoHideDelay: 5000, - className: 'error', - position: 'top center' - }); + iceState = webRTCAdaptor.iceConnectionState(roomNameBox.value); + if (iceState != null && iceState != "failed" && iceState != "disconnected") + { + webRTCAdaptor.sendData(roomNameBox.value, JSON.stringify(notEvent)); + $("#all-messages").append("Sent: " + msg + "
"); + $("#dataTextbox").val(""); + } + else { + $.notify("WebRTC playing is not active. Please click Start Playing first", { + autoHideDelay: 5000, + className: 'error', + position: 'top center' + }); + } } } catch (exception) { @@ -504,8 +518,10 @@

WebRTC Multitrack Conference

publishStreamId = generateRandomString(12); } - publish(publishStreamId, token); - webRTCAdaptor.play(roomNameBox.value, token, roomNameBox.value, [], subscriberId, subscriberCode); + if (!playOnly) { + publish(publishStreamId, token); + } + webRTCAdaptor.play(roomNameBox.value, token, roomNameBox.value, [], subscriberId, subscriberCode, null, role); } function leaveRoom() { @@ -526,7 +542,7 @@

WebRTC Multitrack Conference

if (streamName == null || streamName == 'undefined' || streamName == "") { streamName = streamId; } - webRTCAdaptor.publish(publishStreamId, token, subscriberId, subscriberCode, streamName, roomNameBox.value, JSON.stringify(metadata)); + webRTCAdaptor.publish(publishStreamId, token, subscriberId, subscriberCode, streamName, roomNameBox.value, JSON.stringify(metadata), role); } @@ -765,6 +781,9 @@

WebRTC Multitrack Conference

else if (info == "play_started") { isPlaying = true; isNoSreamExist = false; + join_publish_button.disabled = true; + stop_publish_button.disabled = false; + webRTCAdaptor.getBroadcastObject(roomNameBox.value); if (reconnecting) { playReconnected = true;