//Status constants
var SESSION_STATUS = Flashphoner.constants.SESSION_STATUS;
var STREAM_STATUS = Flashphoner.constants.STREAM_STATUS;
var session;
var PRELOADER_URL = "https://github.com/flashphoner/flashphoner_client/raw/wcs_api-2.0/examples/demo/dependencies/media/preloader.mp4";
//Init Flashphoner API on page load
function init_api() {
Flashphoner.init({});
//Connect to WCS server over websockets
session = Flashphoner.createSession({
urlServer: "wss://demo.flashphoner.com:8443"
}).on(SESSION_STATUS.ESTABLISHED, function (session) {
console.log("ESTABLISHED");
if (Browser.isSafari()) {
Flashphoner.playFirstVideo(document.getElementById("play"), true, PRELOADER_URL).then(function () {
playStream();
//getSnapshot();
//CHinh()
});
} else {
playStream();
//getSnapshot();
//CHinh()
}
//Auto end------------------------------------------
});
//Snapshot begin-----------------------------------------
getSnapshot();
}
//Detect browser
var Browser = {
isSafari: function () {
return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
},
}
function playClick() {
if (Browser.isSafari()) {
Flashphoner.playFirstVideo(document.getElementById("play"), true, PRELOADER_URL).then(function () {
playStream();
});
} else {
playStream();
}
}
//Playing stream camera IP số 1
function playStream() {
session.createStream({
transport: "TCP",
constraints: {
audio: true,
video: {
width: 640,
height: 360,
bitrate: 5000
}
},
name: "rtsp://admin:xxx@xx.xxx.xxx.xxx:555/Streaming/Channels/101/",
display: document.getElementById("play"),
}).play();
}
var Image = "";
function getSnapshot() {
fetchUrl = "http://demo.flashphoner.com:8081/rest-api/stream/snapshot";
const options = {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"streamName": "rtsp://admin:xxx@xx.xxx.xxx.xxx:555/Streaming/Channels/101/",
}),
}
fetch(fetchUrl, options)
.then(function (response) {
response.json().then(function (data) {
Image = document.getElementById("snapshotImg").src = "data:image/jpeg;base64," + data.data;
CHinh();
});
});
}
function CHinh() {
var nhomdung = "giamdinhcong";
var socont = "MSCU1111118";
$.ajax({
type: 'POST',
url: 'lane2IP.aspx/Lane2IPSave',
data: '{ "image" : "' + Image + '", "chuoi_cont": "' + socont + '", "nhom": "' + nhomdung + '"}',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function () {
//alert("OK");
},
error: function (jqXHR, exception) {
//var msg = 'error';
//if (jqXHR.status === 0) {
// msg = 'Not connect.\n Verify Network.';
//} else if (jqXHR.status == 404) {
// msg = 'Requested page not found. [404]';
//} else if (jqXHR.status == 500) {
// msg = 'Internal Server Error [500].';
//} else if (exception === 'parsererror') {
// msg = 'Requested JSON parse failed.';
//} else if (exception === 'timeout') {
// msg = 'Time out error.';
//} else if (exception === 'abort') {
// msg = 'Ajax request aborted.';
//} else {
// msg = 'Uncaught Error.\n' + jqXHR.responseText;
//}
//alert("error:" + msg);
}
});
}