index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. // wrt + socket + contrl
  2. const io = require("socket.io-client")
  3. const PWM = require('./Pwm')
  4. const HOST = 'ws://10.10.3.196:7896'
  5. class CarServer {
  6. constructor(HOST) {
  7. this.webRTC = null
  8. this.mediaStream = null
  9. this.videoSource = null
  10. this.socket = io(HOST, {
  11. auth: {
  12. roomID: "feiCar",
  13. name: 'car'
  14. }
  15. });
  16. this.socket.on('connect', () => {
  17. console.log(`连接成功`)
  18. })
  19. this.socket.on('leaved', user => {
  20. console.log(`${user.name}离开${user.roomID}房间`)
  21. })
  22. this.socket.on('joined', user => {
  23. console.log(`${user.name}加入${user.roomID}房间`)
  24. })
  25. this.socket.on('msg', data => {
  26. console.log('用户信息', data.type);
  27. if (data.type === 'conctrl') {
  28. PWM.changPWM(data.conctrl)
  29. }
  30. })
  31. this.socket.on('connect_error', err => {
  32. console.log('连接错误', err)
  33. })
  34. }
  35. }
  36. new CarServer(HOST)