Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get and set custom layout #95

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 47 additions & 42 deletions MediaPushPlugin/build/composite_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@

let fps = 10;
let loopRunning = false;
let layoutList = [];
var layoutList = [];

let effectCanvas = null;
let canvasStream = null;
let ctx = null;

let cycle = 0;

function start(canvasWidth, canvasHeight, firstTime)
{
if (loopRunning)
Expand Down Expand Up @@ -104,7 +102,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();
Expand All @@ -125,39 +124,35 @@
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);
console.log("new track available with id: "
+ obj.trackId + " and kind: " + obj.track.kind + " on the room:" + roomId);

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", "");
}
//trackId is ARDAMSv+STREAM_ID or ARDAMSa+STREAM_ID
var incomingTrackId = obj.trackId.substring("ARDAMSx".length);

if(index == room) {
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) {
Expand All @@ -174,7 +169,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);
}
Expand Down Expand Up @@ -260,21 +255,9 @@
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;
document.write("fasdfasdfasdfasdfsfasdfasf "+window.layoutList)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to cleanup debug purposes logs, before creating pull request.


// setLayout(obj.data)
}
else if (info == "bitrateMeasurement") {
}
Expand Down Expand Up @@ -315,9 +298,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;
Expand Down Expand Up @@ -389,6 +374,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;
}


</script>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -172,8 +169,12 @@ 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,7 +59,7 @@ protected void finished(Description description) {
@BeforeClass
public static void beforeClass()
{
WebDriverManager.chromedriver().setup();
//WebDriverManager.chromedriver().setup();
}

@Test
Expand Down Expand Up @@ -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);
Expand Down