Browse Source

增加启动延迟
Signed-off-by: caner <5658514@qq.com>

caner 3 years ago
parent
commit
9d189bfddb
3 changed files with 8 additions and 15 deletions
  1. 3 4
      index.js
  2. 2 9
      install.sh
  3. 3 2
      start.sh

+ 3 - 4
index.js

@@ -6,8 +6,7 @@ const { PeerConnection, Video } = require('node-datachannel');
 const { createSocket } = require('dgram')
 const { createSocket } = require('dgram')
 const { spawn } = require('child_process')
 const { spawn } = require('child_process')
 
 
-// const url = 'ws://10.10.3.196:7896'
-const url = process.argv.splice(2);
+const url = 'ws://10.10.3.196:7896'
 class CarServer {
 class CarServer {
     constructor() {
     constructor() {
         this.Peer = null
         this.Peer = null
@@ -44,7 +43,7 @@ class CarServer {
             } else if (data.type === 'startRTC') {
             } else if (data.type === 'startRTC') {
                 this.startVideo()
                 this.startVideo()
             } if (data.type === 'conctrl') {
             } if (data.type === 'conctrl') {
-                const state = this.Peer.iceConnectionState;
+                const state = this.Peer.state();
                 if(state === 'connected') PWM.changPWM(data.conctrl);
                 if(state === 'connected') PWM.changPWM(data.conctrl);
             }
             }
         } catch (error) {
         } catch (error) {
@@ -106,4 +105,4 @@ class CarServer {
         }
         }
     }
     }
 }
 }
-new CarServer(url[0])
+new CarServer()

+ 2 - 9
install.sh

@@ -54,14 +54,7 @@ else
     exit
     exit
 fi
 fi
 
 
-read -p "输入车端socket地址(ws://ip:port):" URL
-URL=${URL:-URL}
-if  [ ! -n "$URL" ] ;then
-    echo "请输入车端socket地址"
-    exit
-else
-    echo "遥控端地址:$URL"
-fi
+chmod 777 /root/car/start.sh
 
 
 if echo "[Unit]
 if echo "[Unit]
 Description=Car-server
 Description=Car-server
@@ -70,7 +63,7 @@ After=network.target
 [Service]
 [Service]
 Type=simple
 Type=simple
 User=root
 User=root
-ExecStart=/root/car/lib/node /root/car/index.js $URL &
+ExecStart=/root/car/start.sh &
 Restart=always
 Restart=always
 RestartSec=3s
 RestartSec=3s
 
 

+ 3 - 2
start.sh

@@ -1,2 +1,3 @@
-sleep 30
-sudo /usr/bin/node /home/pi/car/index.js
+#!/bin/sh
+sleep 30s
+/usr/bin/node /home/pi/car/index.js