| 12345678910111213141516171819202122232425262728293031323334353637 |
- // wrt + socket + contrl
- const io = require("socket.io-client")
- const PWM = require('./Pwm')
- const HOST = 'ws://10.10.3.196:7896'
- class CarServer {
- constructor(HOST) {
- this.webRTC = null
- this.mediaStream = null
- this.videoSource = null
- this.socket = io(HOST, {
- auth: {
- roomID: "feiCar",
- name: 'car'
- }
- });
- this.socket.on('connect', () => {
- console.log(`连接成功`)
- })
- this.socket.on('leaved', user => {
- console.log(`${user.name}离开${user.roomID}房间`)
- })
- this.socket.on('joined', user => {
- console.log(`${user.name}加入${user.roomID}房间`)
- })
- this.socket.on('msg', data => {
- console.log('用户信息', data.type);
- if (data.type === 'conctrl') {
- PWM.changPWM(data.conctrl)
- }
- })
- this.socket.on('connect_error', err => {
- console.log('连接错误', err)
- })
- }
- }
- new CarServer(HOST)
|