Browse Source

增加node依赖,增加一键安装脚本
Signed-off-by: caner <5658514@qq.com>

caner 3 years ago
parent
commit
1bf8488d79
4 changed files with 123 additions and 8 deletions
  1. 5 7
      index.js
  2. 74 1
      install.sh
  3. BIN
      lib/node
  4. 44 0
      lib/npm

+ 5 - 7
index.js

@@ -2,18 +2,19 @@
 // wrt + socket + contrl
 const io = require("socket.io-client")
 const PWM = require('./lib/Pwm')
-const { PeerConnection, Video, RtcpReceivingSession } = require('node-datachannel');
+const { PeerConnection, Video } = require('node-datachannel');
 const { createSocket } = require('dgram')
 const { spawn } = require('child_process')
 
-
+// const url = 'ws://10.10.3.196:7896'
+const url = process.argv.splice(2);
 class CarServer {
     constructor() {
         this.Peer = null
         this.track = null
         this.child = null
         this.udp = null
-        this.socket = io('ws://10.10.3.196:7896', { auth: { roomID: "feiCar", name: 'car' } });
+        this.socket = io(url, { auth: { roomID: "feiCar", name: 'car' } });
         this.socket.on('connect', this.connected.bind(this))
         this.socket.on('msg', this.onMsg.bind(this))
         this.socket.on('leaved', this.onLeved.bind(this))
@@ -76,7 +77,6 @@ class CarServer {
             this.udp.bind(port)
 
             // video push
-
             const args = [
                 "libcamerasrc",
                 "video/x-raw,width=640,height=480",
@@ -92,8 +92,6 @@ class CarServer {
             // listen UDP
             this.udp.on("message", (data) => {
                 if (!this.track.isOpen()) return
-                console.log(data);
-                this.track.setMediaHandler(new RtcpReceivingSession())
                 this.track.sendMessageBinary(data)
             });
 
@@ -102,4 +100,4 @@ class CarServer {
         }
     }
 }
-new CarServer()
+new CarServer(url[0])

+ 74 - 1
install.sh

@@ -1 +1,74 @@
-sudo apt-get install libx264-dev libjpeg-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-ugly gstreamer1.0-tools gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-pulseaudio -y
+echo '清除缓存...'
+sudo rm /tmp/car.tar.gz
+sudo rm -rf /root/car
+sudo rm /usr/bin/node
+echo ''
+
+echo "下载安装包..."
+if wget -O /tmp/car.tar.gz https://git.caner.top/Pip-Telecar/Car/archive/car.tar.gz; then
+    echo '下载成功'
+else
+    echo '下载失败,请重试!'
+    exit 1
+echo ''
+echo '开始解压...'
+if tar -zxf /tmp/car.tar.gz -C /root/;then
+    echo '解压成功'
+else
+    echo '解压失败,请重试!'
+    exit 1
+echo ''
+echo '开始安装gstreamer 依赖...'
+if sudo apt-get install libx264-dev libjpeg-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-ugly gstreamer1.0-tools gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-pulseaudio -y;then
+    echo 'gstreamer 安装成功'
+else
+    echo 'gstreamer 安装失败,请重试!'
+    exit 1
+echo ''
+echo '安装 node 服务'
+if ln -s /root/car/lib/node /usr/bin/node;then
+    echo 'node安装成功'
+else
+    echo 'node安装失败,请重试!'
+    exit 1
+echo ''
+
+read -p "输入车端socket地址(ws://ip:port):" wsUrl
+wsUrl=${wsUrl}
+if "";then
+    echo "遥控端地址:$wsUrl"
+else
+    echo '地址不能为空!'
+    exit 1
+
+echo '安装 systemctl 开机启动服务'
+echo "[Unit]
+Description=Car-server
+After=network.target
+
+[Service]
+Type=simple
+User=root
+ExecStart=/usr/bin/node /root/car/index.js $wsUrl &
+Restart=always
+RestartSec=3s
+
+[Install]
+WantedBy=multi-user.target" | sudo tee /etc/systemd/system/car.service
+echo 'systmctl 服务安装成功'
+echo ''
+echo '添加开机启动..'
+sudo systemctl daemon-reload
+if sudo systemctl enable car.service;then
+    echo '开机添加成功'
+else
+    echo '开机添加失败,请重试!'
+    exit 1
+echo ''
+if sudo systemctl start car.service;then
+    echo '车端服务启动成功!'
+else
+    echo '车端服务启动失败,请重试!'
+    exit 1
+echo ''
+exit

BIN
lib/node


+ 44 - 0
lib/npm

@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+(set -o igncr) 2>/dev/null && set -o igncr; # cygwin encoding fix
+
+basedir=`dirname "$0"`
+
+case `uname` in
+  *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
+esac
+
+NODE_EXE="$basedir/node.exe"
+if ! [ -x "$NODE_EXE" ]; then
+  NODE_EXE="$basedir/node"
+fi
+if ! [ -x "$NODE_EXE" ]; then
+  NODE_EXE=node
+fi
+
+# this path is passed to node.exe, so it needs to match whatever
+# kind of paths Node.js thinks it's using, typically win32 paths.
+CLI_BASEDIR="$("$NODE_EXE" -p 'require("path").dirname(process.execPath)')"
+NPM_CLI_JS="$CLI_BASEDIR/node_modules/npm/bin/npm-cli.js"
+
+NPM_PREFIX=`"$NODE_EXE" "$NPM_CLI_JS" prefix -g`
+if [ $? -ne 0 ]; then
+  # if this didn't work, then everything else below will fail
+  echo "Could not determine Node.js install directory" >&2
+  exit 1
+fi
+NPM_PREFIX_NPM_CLI_JS="$NPM_PREFIX/node_modules/npm/bin/npm-cli.js"
+
+# a path that will fail -f test on any posix bash
+NPM_WSL_PATH="/.."
+
+# WSL can run Windows binaries, so we have to give it the win32 path
+# however, WSL bash tests against posix paths, so we need to construct that
+# to know if npm is installed globally.
+if [ `uname` = 'Linux' ] && type wslpath &>/dev/null ; then
+  NPM_WSL_PATH=`wslpath "$NPM_PREFIX_NPM_CLI_JS"`
+fi
+if [ -f "$NPM_PREFIX_NPM_CLI_JS" ] || [ -f "$NPM_WSL_PATH" ]; then
+  NPM_CLI_JS="$NPM_PREFIX_NPM_CLI_JS"
+fi
+
+"$NODE_EXE" "$NPM_CLI_JS" "$@"