浏览代码

Added experimental UPnP auto renew function

Toby Chui 3 年之前
父节点
当前提交
eba6eca6e7
共有 6 个文件被更改,包括 22 次插入83 次删除
  1. 1 1
      Makefile
  2. 16 0
      mod/network/upnp/upnp.go
  3. 5 0
      network.go
  4. 二进制
      web/Recorder/img/baseline_mic_black_48dp.png
  5. 二进制
      web/Recorder/img/mic-black-48dp.zip
  6. 0 82
      web/Screen Recorder/PoC.html

+ 1 - 1
Makefile

@@ -65,4 +65,4 @@ web.tar.gz:
 
 arozos_file_checksum.sha1:
 	@echo "Generating the checksum, if sha1sum installed"
-	-sha1sum ./dist/arozos_*_* web.tar.gz > arozos_file_checksum.sha1
+	-sha1sum ./dist/arozos_*_* web.tar.gz > ./dist/arozos_file_checksum.sha1

+ 16 - 0
mod/network/upnp/upnp.go

@@ -4,6 +4,7 @@ import (
 	"errors"
 	"log"
 	"sync"
+	"time"
 
 	"gitlab.com/NebulousLabs/go-upnp"
 )
@@ -104,6 +105,21 @@ func (u *UPnPClient) ClosePort(portNumber int) error {
 	return nil
 }
 
+//Renew forward rules, prevent router lease time from flushing the Upnp config
+func (u *UPnPClient) RenewForwardRules() {
+	portsToRenew := u.RequiredPorts
+	for _, thisPort := range portsToRenew {
+		ruleName, ok := u.PolicyNames.Load(thisPort)
+		if !ok {
+			continue
+		}
+		u.ClosePort(thisPort)
+		time.Sleep(100 * time.Millisecond)
+		u.ForwardPort(thisPort, ruleName.(string))
+	}
+	log.Println("UPnP Port Forward rule renew completed")
+}
+
 func (u *UPnPClient) Close() {
 	//Shutdown the default UPnP Object
 	if u != nil {

+ 5 - 0
network.go

@@ -165,6 +165,11 @@ func StartNetworkServices() {
 
 			UPNP = u
 
+			//Register nightly listener for upnp renew
+			nightlyManager.RegisterNightlyTask(func() {
+				UPNP.RenewForwardRules()
+			})
+
 			//Show a tip for success port forward
 			connectionEndpoint := UPNP.ExternalIP + ":" + strconv.Itoa(*listen_port)
 			obip, err := network.GetOutboundIP()

二进制
web/Recorder/img/baseline_mic_black_48dp.png


二进制
web/Recorder/img/mic-black-48dp.zip


+ 0 - 82
web/Screen Recorder/PoC.html

@@ -1,82 +0,0 @@
-<button id="btn-start-recording">Start</button>
-<button id="btn-stop-recording" disabled>Stop</button>
-
-<script src="https://www.WebRTC-Experiment.com/RecordRTC.js"></script>
-<script>
-    var wsUri = getWebSocketEndpoint() + "/system/file_system/lowmemUpload?filename=" + encodeURIComponent(new Date().toLocaleString().replaceAll(" ","").replaceAll("/","").replaceAll(":","").replaceAll(",","")) + ".webm&path=user%3A%2F";
-var video = document.querySelector('video');
-var websocket;
-
-function getWebSocketEndpoint(){
-        let protocol = "wss://";
-        if (location.protocol !== 'https:') {
-            protocol = "ws://";
-        }
-        let port = window.location.port;
-        if (window.location.port == ""){
-            if (location.protocol !== 'https:') {
-                port = "80";
-            }else{
-                port = "443";
-            }
-            
-        }
-        let wsept = (protocol + window.location.hostname + ":" + port);
-        return wsept;
-    }
-
-function captureCamera(callback) {
-    navigator.mediaDevices.getDisplayMedia({
-            displaySurface: 'monitor',
-            logicalSurface: true,
-            cursor: 'always'
-        }).then(function(camera) {
-        callback(camera);
-    }).catch(function(error) {
-        alert('Unable to capture your camera. Please check console logs.');
-        console.error(error);
-    });
-}
-
-function stopRecordingCallback() {
-    recorder.camera.stop();
-    recorder = null;
-}
-
-var recorder; 
-
-document.getElementById('btn-start-recording').onclick = function() {
-    this.disabled = true;
-    websocket = new WebSocket(wsUri);
-    //websocket.binaryType = 'blob';
-
-    captureCamera(function(camera) {
-
-        recorder = RecordRTC(camera, {
-            recorderType: MediaStreamRecorder,
-            mimeType: 'video/webm',
-            timeSlice: 100, // pass this parameter
-            getNativeBlob: true,
-            ondataavailable: function(blob) {
-                websocket.send(blob);
-            }
-        });
-
-        recorder.startRecording();
-
-        // release camera on stopRecording
-        recorder.camera = camera;
-
-        document.getElementById('btn-stop-recording').disabled = false;
-    });
-};
-
-document.getElementById('btn-stop-recording').onclick = function() {
-    this.disabled = true;
-    recorder.stopRecording(stopRecordingCallback);
-    websocket.send("done");
-};
-</script>
-
-<footer style="margin-top: 20px;"><small id="send-message"></small></footer>
-<script src="https://www.webrtc-experiment.com/common.js"></script>