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

Return recording link on stop #100

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ public Result startMediaPush(String streamId, String websocketUrl,
* @return
*/
public Result stopMediaPush(String streamId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;

import io.antmedia.muxer.RecordMuxer;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
Expand Down Expand Up @@ -47,8 +48,6 @@
import io.antmedia.plugin.api.IStreamListener;
import io.antmedia.rest.model.Result;
import io.github.bonigarcia.wdm.WebDriverManager;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;


@Component(value=IMediaPushPlugin.BEAN_NAME)
Expand All @@ -65,6 +64,7 @@ public class MediaPushPlugin implements ApplicationContextAware, IStreamListener

private Map<String, RecordType> recordingMap = new ConcurrentHashMap<>();

public Map<String, String> recordingFileNameMap = new ConcurrentHashMap<>();

private boolean initialized = false;
private ApplicationContext applicationContext;
Expand Down Expand Up @@ -384,8 +384,11 @@ public Result stopMediaPush(String streamId) {
return result;
}

result.setDataId(recordingFileNameMap.get(streamId));

RemoteWebDriver driver = drivers.remove(streamId);
recordingMap.remove(streamId);
recordingFileNameMap.remove(streamId);

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(TIMEOUT_IN_SECONDS));

Expand All @@ -401,12 +404,13 @@ public Result stopMediaPush(String streamId) {
}
catch(TimeoutException e) {
logger.error(ExceptionUtils.getStackTrace(e));
result.setMessage("Timeoutexception occured in stopping the stream. Fortunately, it'll quit the session to stop completely. Error message is " + e.getMessage());
result.setMessage("Timeout exception occurred in stopping the stream. Fortunately, it'll quit the session to stop completely. Error message is " + e.getMessage());

}
finally {
driver.quit();
}

return result;
}

Expand Down Expand Up @@ -471,14 +475,16 @@ public void streamStarted(String streamId)
{
if (recordingMap.containsKey(streamId))
{
getApplication().getMuxAdaptor(streamId).startRecording(recordingMap.get(streamId), 0);
RecordMuxer recordMuxer = getApplication().getMuxAdaptor(streamId).startRecording(recordingMap.get(streamId), 0);
recordingFileNameMap.put(streamId,recordMuxer.getFileName());
}
}

@Override
public void streamFinished(String streamId) {
WebDriver driver = drivers.remove(streamId);
recordingMap.remove(streamId);
recordingFileNameMap.remove(streamId);
if (driver != null) {
driver.quit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public Result startMediaPush(@RequestBody Endpoint request, @Context HttpServlet
@Consumes(MediaType.APPLICATION_JSON)
public Result stopMediaPush(@PathParam("id") String id) {
MediaPushPlugin app = getPluginApp();

return app.stopMediaPush(id);
}

Expand Down
18 changes: 7 additions & 11 deletions MediaPushPlugin/src/main/js/src/media-push-publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ async function startBroadcasting(message) {
}

let token = "";
let width = 1280;
let height = 720;
let width = screen.width;
let height = screen.height;

if(message.token !== undefined) {
token = message.token;
Expand All @@ -27,14 +27,13 @@ async function startBroadcasting(message) {
height = message.height;
}


const stream = await navigator.mediaDevices.getDisplayMedia(
{
//min is not allowed in getDisplayMedia
video: {
frameRate: {
max: 30
}
width: {ideal: screen.width},
height: {ideal: screen.height},
frameRate: {ideal: 30},
},
audio: {
channelCount:2,
Expand All @@ -44,22 +43,20 @@ async function startBroadcasting(message) {
},
preferCurrentTab:true
})



const track = stream.getVideoTracks()[0];
console.log("video track settings: ", track.getSettings());

const audioTrack = stream.getAudioTracks()[0];
console.log("audio track settings: ", audioTrack.getSettings());

const constra = {
const constra = {
width: {
min: 640,
ideal: width
},
height: {
min: 360,
min: 480,
ideal: height
},
advanced: [{ width: width, height: height }, { aspectRatio: width/height }],
Expand All @@ -80,7 +77,6 @@ async function startBroadcasting(message) {
'urls' : 'stun:stun1.l.google.com:19302'
} ]
};



webRTCAdaptorMediaPush = new WebRTCAdaptor({
Expand Down
1 change: 1 addition & 0 deletions MediaPushPlugin/src/main/resources/e4e4da7454e7cf2e6ffa.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</style>
<script src="media-push-publisher.js"></script>
</head>
<body>
<body style="overflow:hidden">
<!-- We need to use this way because audio is not captured if there is another WebRTC conneciton in the same context -->
<iframe id="media-push-iframe" allow="autoplay"></iframe>
</body>
Expand Down
2 changes: 1 addition & 1 deletion MediaPushPlugin/src/main/resources/media-push-publisher.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions MediaPushPlugin/src/main/script/install_media-push-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
install_chrome_debian() {
sudo apt-get update -y
sudo apt-get install -y wget gnupg2
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
wget https://mirror.cs.uchicago.edu/google-chrome/pool/main/g/google-chrome-stable/google-chrome-stable_120.0.6099.199-1_amd64.deb
sudo dpkg -i google-chrome-stable_120.0.6099.199-1_amd64.deb
sudo apt-get install -f -y
rm google-chrome-stable_current_amd64.deb
rm google-chrome-stable_120.0.6099.199-1_amd64.deb
}

# Function to install Google Chrome on Red Hat-based systems
Expand Down