Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
135 lines (111 sloc) 3.62 KB
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script src="js/webrtc_adaptor.js"></script>
<link href="css/player.css" rel="stylesheet">
<style>
video {
width: 100%;
max-width: 640px;
max-height: 400px;
}
</style>
</head>
<body>
<div id="video_info" >Stream will start playing automatically<br/>when it is live</div>
<video id="remoteVideo" autoplay controls playsinline style="display:none;"></video>
<img id="play_button" src="images/play.png" onclick="playVideo()" style="position:absolute;top:30px;left:30px;display:none;"/>
</body>
<script>
// document.getElementById("video_info").innerHTML="Stream will start playing automatically<br/>when it is live";
var streamId = "<%= request.getParameter("name") %>";
if (streamId == "null") {
alert("No stream specified. Please add ?name={STREAM_ID} to the url");
}
var token = "<%= request.getParameter("token") %>";
function playVideo() {
document.getElementById("remoteVideo").style.display = "block";
document.getElementById("remoteVideo").play().then(function(value){
//autoplay started
document.getElementById("play_button").style.display="none";
}).catch(function(error) {
//
document.getElementById("play_button").style.display="block";
console.log("User interaction needed to start playing");
});
}
function startPlaying() {
webRTCAdaptor.play(streamNameBox.value, token);
}
function stopPlaying() {
webRTCAdaptor.stop();
}
var pc_config = null;
var sdpConstraints = {
OfferToReceiveAudio : true,
OfferToReceiveVideo : true
};
var mediaConstraints = {
video : false,
audio : false
};
var appName = location.pathname.substring(0, location.pathname.lastIndexOf("/")+1);
var path = location.hostname + ":" + location.port + appName + "websocket";
var websocketURL = "ws://" + path;
if (location.protocol.startsWith("https")) {
websocketURL = "wss://" + path;
}
var webRTCAdaptor = new WebRTCAdaptor({
websocket_url : websocketURL,
mediaConstraints : mediaConstraints,
peerconnection_config : pc_config,
sdp_constraints : sdpConstraints,
remoteVideoId : "remoteVideo",
isPlayMode: true,
debug: true,
callback : function(info, description) {
if (info == "initialized") {
console.log("initialized");
webRTCAdaptor.getStreamInfo(streamId);
}
else if (info == "streamInformation") {
console.log("stream information");
webRTCAdaptor.play(streamId, token);
}
else if (info == "play_started") {
//joined the stream
console.log("play started");
document.getElementById("video_info").style.display = "none";
playVideo();
} else if (info == "play_finished") {
//leaved the stream
console.log("play finished");
//check that publish may start again
setTimeout(function(){
webRTCAdaptor.getStreamInfo(streamId);
}, 3000);
}
else if (info == "closed") {
//console.log("Connection closed");
if (typeof description != "undefined") {
console.log("Connecton closed: " + JSON.stringify(description));
}
}
},
callbackError : function(error) {
//some of the possible errors, NotFoundError, SecurityError,PermissionDeniedError
console.log("error callback: " + JSON.stringify(error));
if (error == "no_stream_exist") {
setTimeout(function(){
webRTCAdaptor.getStreamInfo(streamId);
}, 3000);
}
//alert(JSON.stringify(error));
}
});
</script>
</html>
You can’t perform that action at this time.