diff --git a/.env.dist b/.env.dist new file mode 100644 index 0000000..3e64fa1 --- /dev/null +++ b/.env.dist @@ -0,0 +1,2 @@ +VIR="http://192.168.64.101" +CILJ="rtp://localhost:8004" diff --git a/.gitignore b/.gitignore index fb5f48f..e3b7dc1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ settings.js +.env diff --git a/0_vidi.sh b/0_vidi.sh index fa655f8..076f6c9 100755 --- a/0_vidi.sh +++ b/0_vidi.sh @@ -1,4 +1,5 @@ #!/bin/bash -VIR="http://192.168.64.104:81" -ffplay $VIR +source .env + +ffplay $VIR:81 diff --git a/1_mjpeg2rtp.sh b/1_mjpeg2rtp.sh index 552cbd8..60d5632 100755 --- a/1_mjpeg2rtp.sh +++ b/1_mjpeg2rtp.sh @@ -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 diff --git a/2_vent_vklop.sh b/2_vent_vklop.sh new file mode 100755 index 0000000..53b8fed --- /dev/null +++ b/2_vent_vklop.sh @@ -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" diff --git a/index.html b/index.html index e1f397e..19046b5 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,7 @@ + diff --git a/propeliraj.js b/propeliraj.js new file mode 100644 index 0000000..521b229 --- /dev/null +++ b/propeliraj.js @@ -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(); +} diff --git a/streaming.js b/streaming.js index e7ebc68..2ad3a7d 100644 --- a/streaming.js +++ b/streaming.js @@ -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); +}