From 71b1785e687c474ad584ec71792f284aeff68051 Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Wed, 28 Feb 2024 22:55:23 +0530 Subject: [PATCH 1/5] get and set the layout with REST APIs --- MediaPushPlugin/build/composite_layout.html | 88 ++++++++++--------- .../io/antmedia/plugin/MediaPushPlugin.java | 12 +-- 2 files changed, 53 insertions(+), 47 deletions(-) diff --git a/MediaPushPlugin/build/composite_layout.html b/MediaPushPlugin/build/composite_layout.html index e5d6cac7..5f09b29c 100644 --- a/MediaPushPlugin/build/composite_layout.html +++ b/MediaPushPlugin/build/composite_layout.html @@ -33,14 +33,13 @@ let fps = 10; let loopRunning = false; - let layoutList = []; + var layoutList = []; let effectCanvas = null; let canvasStream = null; let ctx = null; - + window.a="1"; let cycle = 0; - function start(canvasWidth, canvasHeight, firstTime) { if (loopRunning) @@ -104,7 +103,8 @@ ctx.drawImage(image, layout.region.xPos, layout.region.yPos, layout.region.width, layout.region.height); } else { let video = document.getElementById("remoteVideo" + layout.streamId); - ctx.drawImage(video, layout.region.xPos, layout.region.yPos, layout.region.width, layout.region.height); + if(video) + ctx.drawImage(video, layout.region.xPos, layout.region.yPos, layout.region.width, layout.region.height); } } ctx.restore(); @@ -125,39 +125,38 @@ webRTCAdaptorPlay.enableTrack(streamNameBox.value, trackId, true); } + function playVideo(obj) { - var room = roomId; - console.log("new stream available with id: " - + obj.streamId + "on the room:" + room); - var index; - if(obj.track.kind == "video") { - index = obj.track.id.replace("ARDAMSv", ""); - } - else if(obj.track.kind == "audio") { - index = obj.track.id.replace("ARDAMSa", ""); - } + //In multitrack conferencing the stream is same, tracks are being and remove from the stream - if(index == room) { + console.log("new track available with id: " + + obj.trackId + " and kind: " + obj.track.kind + " on the room:" + roomId); + + //trackId is ARDAMSv+STREAM_ID or ARDAMSa+STREAM_ID + var incomingTrackId = obj.trackId.substring("ARDAMSx".length); + + if (incomingTrackId == roomId || incomingTrackId == publisherId) { return; } - var video = document.getElementById("remoteVideo"+index); + var video = document.getElementById("remoteVideo" + incomingTrackId); if (video == null) { - createRemoteVideo(index); - video = document.getElementById("remoteVideo"+index); + createRemoteVideo(incomingTrackId); + video = document.getElementById("remoteVideo" + incomingTrackId); video.srcObject = new MediaStream(); } video.srcObject.addTrack(obj.track) - obj.track.onended = event => { - video.srcObject.removeTrack(event.currentTarget); - if(video.srcObject.getTracks().length == 0) { - removeRemoteVideo(index); - } - }; + obj.stream.onremovetrack = event => { + console.log("track is removed with id: " + event.track.id) + console.log(event); + var removedTrackId = event.track.id.substring("ARDAMSx".length); + removeRemoteVideo(removedTrackId); + } + } function createRemoteVideo(streamId) { @@ -260,21 +259,6 @@ console.log("iceConnectionState Changed: ",JSON.stringify(obj)); } else if (info == "data_received") { - var messageObject = JSON.parse(obj.data); - var layoutOptions = messageObject.layoutOptions; - var canvasOptions = layoutOptions.canvas; - var layout = layoutOptions.layout; - effectCanvas.width = canvasOptions.width; - effectCanvas.height = canvasOptions.height; - let localVideoElement = document.getElementById("localVideo"); - //localVideoElement.width = canvasOptions.width; - //localVideoElement.height = canvasOptions.height; - loopRunning = false; - start(canvasOptions.width, canvasOptions.height, false); - layout.forEach(function(item) { - createImage(item.streamId+"IMG", item.placeholderImageUrl); - }); - layoutList = layout; } else if (info == "bitrateMeasurement") { } @@ -315,9 +299,11 @@ console.log("Connecton closed: " + JSON.stringify(obj)); } - } else if (info == "newStreamAvailable") { + } + else if (info == "newTrackAvailable") { playVideo(obj); - } else if (info == "data_received") { + } + else if (info == "data_received") { var notificationEvent = JSON.parse(obj.data); if(notificationEvent != null && typeof(notificationEvent) == "object") { var eventStreamId = notificationEvent.streamId; @@ -389,6 +375,26 @@ }, false ); + window.setLayout = (layout)=> { + var messageObject = JSON.parse(layout); + var canvasOptions = messageObject.canvas; + var layout = messageObject.layout; + effectCanvas.width = canvasOptions.width; + effectCanvas.height = canvasOptions.height; + let localVideoElement = document.getElementById("localVideo"); + //localVideoElement.width = canvasOptions.width; + //localVideoElement.height = canvasOptions.height; + loopRunning = false; + start(canvasOptions.width, canvasOptions.height, false); + layout.forEach(function(item) { + createImage(item.streamId+"IMG", item.placeholderImageUrl); + }); + layoutList = layout; + } + window.getLayout = ()=>{ + return layoutList; + } + diff --git a/MediaPushPlugin/src/main/java/io/antmedia/plugin/MediaPushPlugin.java b/MediaPushPlugin/src/main/java/io/antmedia/plugin/MediaPushPlugin.java index d2ee022f..30b9560a 100644 --- a/MediaPushPlugin/src/main/java/io/antmedia/plugin/MediaPushPlugin.java +++ b/MediaPushPlugin/src/main/java/io/antmedia/plugin/MediaPushPlugin.java @@ -9,10 +9,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.time.Duration; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Level; @@ -172,8 +169,11 @@ public Result sendCommand(String streamId, String command) { try { WebDriver driver = getDrivers().get(streamId); JavascriptExecutor js = (JavascriptExecutor) driver; - js.executeScript(command); - return new Result(true, streamId, "Command executed"); + Object response = js.executeScript(command); + Result result = new Result(true, streamId, "Command executed"); + if(response != null) + result.setDataId(response.toString()); + return result; } catch (Exception e) { logger.error("Command cannot be executed: {} " , e.getMessage()); return new Result(false, "Command cannot be executed."); From d0fcd571bd96b260a015b3b100f2d7dceda75b02 Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Wed, 28 Feb 2024 23:15:37 +0530 Subject: [PATCH 2/5] test cases added --- .../io/antmedia/plugin/MediaPushPluginUnitTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/MediaPushPlugin/src/test/java/io/antmedia/plugin/MediaPushPluginUnitTest.java b/MediaPushPlugin/src/test/java/io/antmedia/plugin/MediaPushPluginUnitTest.java index 280c20f9..a6db3a4f 100644 --- a/MediaPushPlugin/src/test/java/io/antmedia/plugin/MediaPushPluginUnitTest.java +++ b/MediaPushPlugin/src/test/java/io/antmedia/plugin/MediaPushPluginUnitTest.java @@ -5,9 +5,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import java.io.IOException; import java.net.MalformedURLException; @@ -61,7 +59,7 @@ protected void finished(Description description) { @BeforeClass public static void beforeClass() { - WebDriverManager.chromedriver().setup(); + //WebDriverManager.chromedriver().setup(); } @Test @@ -120,10 +118,14 @@ public void testSendCommand_WhenDriverExists_ShouldExecuteCommand() { String command = "someCommand"; Result expectedResult = new Result(true, streamId, "Command executed"); + Object obj = "test"; when(plugin.getDrivers()).thenReturn(drivers); when(drivers.containsKey(streamId)).thenReturn(true); when(drivers.get(streamId)).thenReturn(driver); - when(js.executeScript(command)).thenReturn(null); + expectedResult.setDataId(obj.toString()); + when(driver.executeScript(command)).thenReturn(obj); + + // Act Result result = plugin.sendCommand(streamId, command); From b8bff81b288f612b64b8b03e083877bc7608d4a0 Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Wed, 28 Feb 2024 23:49:54 +0530 Subject: [PATCH 3/5] minor changes --- MediaPushPlugin/build/composite_layout.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/MediaPushPlugin/build/composite_layout.html b/MediaPushPlugin/build/composite_layout.html index 5f09b29c..16c371b6 100644 --- a/MediaPushPlugin/build/composite_layout.html +++ b/MediaPushPlugin/build/composite_layout.html @@ -127,9 +127,6 @@ function playVideo(obj) { - - //In multitrack conferencing the stream is same, tracks are being and remove from the stream - console.log("new track available with id: " + obj.trackId + " and kind: " + obj.track.kind + " on the room:" + roomId); @@ -173,7 +170,7 @@ function removeRemoteVideo(streamId) { var video = document.getElementById("remoteVideo"+streamId); if (video != null) { - var player = document.getElementById("player" + streamId); + var player = document.getElementById("remoteVideo" + streamId); video.srcObject = null; document.getElementById("players").removeChild(player); } @@ -259,6 +256,9 @@ console.log("iceConnectionState Changed: ",JSON.stringify(obj)); } else if (info == "data_received") { + document.write("fasdfasdfasdfasdfsfasdfasf "+window.layoutList) + +// setLayout(obj.data) } else if (info == "bitrateMeasurement") { } From af9df6a1f8223e62973c714ebee6625dcecd1e1a Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Wed, 28 Feb 2024 23:55:55 +0530 Subject: [PATCH 4/5] minor changes --- MediaPushPlugin/build/composite_layout.html | 1 - 1 file changed, 1 deletion(-) diff --git a/MediaPushPlugin/build/composite_layout.html b/MediaPushPlugin/build/composite_layout.html index 16c371b6..c13e8a00 100644 --- a/MediaPushPlugin/build/composite_layout.html +++ b/MediaPushPlugin/build/composite_layout.html @@ -38,7 +38,6 @@ let effectCanvas = null; let canvasStream = null; let ctx = null; - window.a="1"; let cycle = 0; function start(canvasWidth, canvasHeight, firstTime) { From 971d2a3612e6beba0e6431f9deac30498cbda644 Mon Sep 17 00:00:00 2001 From: USAMAWIZARD Date: Thu, 29 Feb 2024 02:20:43 +0530 Subject: [PATCH 5/5] minor changes --- .../src/main/java/io/antmedia/plugin/MediaPushPlugin.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/MediaPushPlugin/src/main/java/io/antmedia/plugin/MediaPushPlugin.java b/MediaPushPlugin/src/main/java/io/antmedia/plugin/MediaPushPlugin.java index 30b9560a..27bcff60 100644 --- a/MediaPushPlugin/src/main/java/io/antmedia/plugin/MediaPushPlugin.java +++ b/MediaPushPlugin/src/main/java/io/antmedia/plugin/MediaPushPlugin.java @@ -171,8 +171,9 @@ public Result sendCommand(String streamId, String command) { JavascriptExecutor js = (JavascriptExecutor) driver; Object response = js.executeScript(command); Result result = new Result(true, streamId, "Command executed"); - if(response != null) + if(response != null) { result.setDataId(response.toString()); + } return result; } catch (Exception e) { logger.error("Command cannot be executed: {} " , e.getMessage());