Propeliranje, env fajl za IP, popravki, WIP webrtc data xfer

sbc
Jurij Podgoršek 2023-03-20 02:34:49 +01:00
parent cbc1770d43
commit 0d74389113
8 changed files with 166 additions and 83 deletions

2
.env.dist 100644
View File

@ -0,0 +1,2 @@
VIR="http://192.168.64.101"
CILJ="rtp://localhost:8004"

1
.gitignore vendored
View File

@ -1 +1,2 @@
settings.js
.env

View File

@ -1,4 +1,5 @@
#!/bin/bash
VIR="http://192.168.64.104:81"
ffplay $VIR
source .env
ffplay $VIR:81

View File

@ -1,8 +1,7 @@
#!/bin/bash
source .env
# Pretvori MJPEG v VP8 RTP stream
VIR="http://192.168.64.104:81"
CILJ="rtp://localhost:8004"
#ffmpeg -re -stream_loop -1 -i $VIR -c:v libx264 -tune zerolatency -profile:v baseline -b:v 1M -an -f rtp $CILJ
ffmpeg -re -stream_loop -1 -i $VIR -c:v libvpx -b:v 1M -an -f rtp $CILJ
ffmpeg -re -stream_loop -1 -i "$VIR:81" -c:v libvpx -b:v 1M -an -f rtp $CILJ

16
2_vent_vklop.sh 100755
View File

@ -0,0 +1,16 @@
#!/bin/bash
source .env
ventilator=$1
if [[ ! $ventilator ]]; then
echo "Izberi ventilator (1 ali 2 kot parameter)"
exit 0
fi
url="$VIR/?m=1&o=$ventilator"
curl "$url"
sleep 2
curl "$url"

View File

@ -11,6 +11,7 @@
<script type="text/javascript" src="webrtc-adapter.min.js" ></script>
<script type="text/javascript" src="settings.js" ></script>
<script type="text/javascript" src="janus.js" ></script>
<script type="text/javascript" src="propeliraj.js"></script>
<script type="text/javascript" src="streaming.js"></script>
<link rel="stylesheet" href="stil.css" type="text/css"/>

54
propeliraj.js 100644
View File

@ -0,0 +1,54 @@
var BOT="http://192.168.1.101/";
// Koliko milisekund se naj vrtijo propelerji?
var DOLZINA=10000;
function xhttp() {
return new XMLHttpRequest();
}
function cors(xh) {
xh.setRequestHeader('Content-Type', 'application/x-www-form-urlencode');
xh.withCredentials = true;
return xh;
}
function preklopiA() {
var xh = xhttp();
xh.open('GET', BOT + "?m=1&o=1");
return xh;
}
function preklopiB() {
var xh = xhttp();
xh.open('GET', BOT + "?m=1&o=2");
return xh;
}
window.peljiLevo = function () {
var rb = preklopiB();
console.log('lev?', rb);
rb.send();
console.log(streaming);
setTimeout(function () {
var rb = preklopiB();
rb.send();
}, DOLZINA);
}
window.peljiDesno = function () {
var ra = preklopiA();
ra.send();
setTimeout(function () {
var ra = preklopiA();
ra.send();
}, DOLZINA);
}
window.peljiRavno = function () {
window.peljiLevo();
window.peljiDesno();
}

View File

@ -33,12 +33,12 @@ window.addEventListener('DOMContentLoaded', function () {
Janus.init({debug: "all", callback: function() {
// Make sure the browser supports WebRTC
if(!Janus.isWebrtcSupported()) {
bootbox.alert("No WebRTC support... ");
console.log("ERROR cannot start; no WebRTC support... ");
return;
}
// Create session
janus = new Janus({
server: server,
server: server,
iceServers: iceServers,
// Should the Janus API require authentication, you can specify either the API secret or user token here too
// token: "mytoken",
@ -79,6 +79,7 @@ window.addEventListener('DOMContentLoaded', function () {
// Gumbi levo in desno
gLevo.addEventListener('click', function () {
console.log('GREMO LEVO!');
window.peljiLevo();
vsiGumbi.forEach(function (gEl) {
gEl.toggleAttribute('disabled', true);
});
@ -91,6 +92,7 @@ window.addEventListener('DOMContentLoaded', function () {
});
gDesno.addEventListener('click', function () {
console.log('GREMO DESNO!');
window.peljiDesno();
vsiGumbi.forEach(function (gEl) {
gEl.toggleAttribute('disabled', true);
});
@ -103,6 +105,7 @@ window.addEventListener('DOMContentLoaded', function () {
});
gRavno.addEventListener('click', function () {
console.log('GREMO RAVNO!');
window.peljiRavno();
vsiGumbi.forEach(function (gEl) {
gEl.toggleAttribute('disabled', true);
});
@ -181,84 +184,86 @@ window.addEventListener('DOMContentLoaded', function () {
Janus.error("WebRTC error:", error);
}
});
}
},
onremotetrack: function(track, mid, on, metadata) {
Janus.debug("Remote track (mid=" + mid + ") " + (on ? "added" : "removed") +
(metadata ? " (" + metadata.reason + ") ": "") + ":", track
);
var mstreamId = "mstream"+mid;
if(streamsList[selectedStream] && streamsList[selectedStream].legacy) {
mstreamId = "mstream0";
}
console.log('dodam?', on);
if(true) {
// If we're here, a new track was added
var stream = null;
// New video track: create a stream out of it
stream = new MediaStream([track]);
console.log('MOJ PRETOK!', stream, track);
remoteTracks[mid] = stream;
Janus.log("Created remote video stream:", stream);
var vidEl = document.querySelector('#videofeed');
/* bitrate in resolucija
if(!bitrateTimer[mid]) {
bitrateTimer[mid] = setInterval(function() {
// Display updated bitrate, if supported
var bitrate = streaming.getBitrate(mid);
console.log('bitrate:', bitrate);
// Check if the resolution changed too
var width = vidEl.videoWidth;
var height = vidEl.videoHeight;
if (width > 0 && height > 0) console.log('resolucija', width+'x'+height);
}, 1000);
}
*/
console.log('dodajam pretok', vidEl, stream);
Janus.attachMediaStream(vidEl, stream);
},
onremotetrack: function(track, mid, on, metadata) {
Janus.debug("Remote track (mid=" + mid + ") " + (on ? "added" : "removed") +
(metadata ? " (" + metadata.reason + ") ": "") + ":", track
);
var mstreamId = "mstream"+mid;
if(streamsList[selectedStream] && streamsList[selectedStream].legacy) {
mstreamId = "mstream0";
}
console.log('dodam?', on);
if(true) {
// If we're here, a new track was added
var stream = null;
// New video track: create a stream out of it
stream = new MediaStream([track]);
console.log('MOJ PRETOK!', stream, track);
remoteTracks[mid] = stream;
Janus.log("Created remote video stream:", stream);
var vidEl = document.querySelector('#videofeed');
/* bitrate in resolucija
if(!bitrateTimer[mid]) {
bitrateTimer[mid] = setInterval(function() {
// Display updated bitrate, if supported
var bitrate = streaming.getBitrate(mid);
console.log('bitrate:', bitrate);
// Check if the resolution changed too
var width = vidEl.videoWidth;
var height = vidEl.videoHeight;
if (width > 0 && height > 0) console.log('resolucija', width+'x'+height);
}, 1000);
}
*/
console.log('dodajam pretok', vidEl, stream);
Janus.attachMediaStream(vidEl, stream);
// Moramo kliknit za predvajanje :/
predvajaj.style.display = 'block';
predvajaj.addEventListener('click', function () {
predvajaj.style.display = 'none';
vidEl.play();
});
vidEl.addEventListener('play', function () {
glavno.classList.add('predvajam');
predvajaj.style.display = 'none';
});
// Moramo kliknit za predvajanje :/
predvajaj.style.display = 'block';
predvajaj.addEventListener('click', function () {
predvajaj.style.display = 'none';
vidEl.play();
});
vidEl.addEventListener('play', function () {
glavno.classList.add('predvajam');
predvajaj.style.display = 'none';
});
vidEl.play();
}
},
ondataopen: function(data) {
Janus.log("The DataChannel is available!");
window.dataKanal = data;
},
ondata: function(data) {
Janus.debug("We got data from the DataChannel!", data);
console.log('DUBU DATA', data);
obdelajData(data);
},
oncleanup: function() {
Janus.log(" ::: Got a cleanup notification :::");
for(var i in bitrateTimer)
clearInterval(bitrateTimer[i]);
bitrateTimer = {};
remoteTracks = {};
dataMid = null;
}
},
ondataopen: function(data) {
Janus.log("The DataChannel is available!");
},
ondata: function(data) {
Janus.debug("We got data from the DataChannel!", data);
console.log('DUBU DATA', data);
},
oncleanup: function() {
Janus.log(" ::: Got a cleanup notification :::");
for(var i in bitrateTimer)
clearInterval(bitrateTimer[i]);
bitrateTimer = {};
remoteTracks = {};
dataMid = null;
}
});
},
error: function(error) {
Janus.error(error);
},
destroyed: function() {
});
},
error: function(error) {
Janus.error(error);
},
destroyed: function() {
window.location.reload();
}
});
@ -353,3 +358,7 @@ function stopStream() {
streaming.send({ message: body });
streaming.hangup();
}
function obdelajData(data) {
console.log('obdelam webrtc podatke', data);
}