|
|
@@ -2,7 +2,6 @@
|
|
|
// wrt + socket + contrl
|
|
|
const io = require("socket.io-client")
|
|
|
const RTCVideoSource = require('./lib/videoSource')
|
|
|
-const RTCAudioSource = require('./lib/audioSource')
|
|
|
//const PWM = require('./lib/Pwm')
|
|
|
const { RTCPeerConnection, MediaStream } = require("wrtc")
|
|
|
const HOST = 'ws://10.10.3.196:7896'
|
|
|
@@ -10,8 +9,7 @@ class CarServer {
|
|
|
constructor(HOST) {
|
|
|
this.webRTC = null
|
|
|
this.mediaStream = null
|
|
|
- this.videoSource = null
|
|
|
- this.audioSource = null
|
|
|
+ this.videoSource = null
|
|
|
this.socket = io(HOST, {
|
|
|
auth: {
|
|
|
roomID: "feiCar",
|
|
|
@@ -48,18 +46,12 @@ class CarServer {
|
|
|
// 初始化媒体源
|
|
|
this.mediaStream = new MediaStream()
|
|
|
this.videoSource = new RTCVideoSource()
|
|
|
- this.audioSource = new RTCAudioSource()
|
|
|
// 加入媒体源
|
|
|
const videoTrack = this.videoSource.createTrack()
|
|
|
this.mediaStream.addTrack(videoTrack)
|
|
|
this.webRTC.addTrack(videoTrack, this.mediaStream)
|
|
|
- // 加入音频源
|
|
|
- const audioTrack = this.audioSource.createTrack()
|
|
|
- this.mediaStream.addTrack(audioTrack)
|
|
|
- this.webRTC.addTrack(audioTrack, this.mediaStream)
|
|
|
- // 加入媒体
|
|
|
+ // 开始媒体
|
|
|
this.videoSource.start()
|
|
|
- this.audioSource.start()
|
|
|
// 监听ice
|
|
|
this.webRTC.onicecandidate = event => {
|
|
|
if (event.candidate) {
|
|
|
@@ -108,12 +100,10 @@ class CarServer {
|
|
|
|
|
|
destroyed() {
|
|
|
if (this.webRTC) this.webRTC.close()
|
|
|
- if (this.audioSource) this.audioSource.stop()
|
|
|
if (this.videoSource) this.videoSource.stop()
|
|
|
this.webRTC = null
|
|
|
this.mediaStream = null
|
|
|
- this.videoSource = null
|
|
|
- this.audioSource = null
|
|
|
+ this.videoSource = null
|
|
|
process.exit(1)
|
|
|
}
|
|
|
}
|