我正在使用peerJS进行视频通话功能,这是我的package.json
{
"name": "zoom-clone",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "concurrently \"node server.js\" \"peerjs --port 443\""
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"concurrently": "^5.3.0",
"ejs": "^3.1.3",
"express": "^4.17.1",
"peer": "^0.5.3",
"socket.io": "^2.3.0",
"uuid": "^8.1.0"
},
"devDependencies": {
"nodemon": "^2.0.4"
}
}
它们是2个服务器(express服务器和peerjs云服务器),所以我正在使用npm软件包调用concurrently
来组合2个启动命令
当它正在开发环境中时,它可以完美地工作,我可以接听并回答来自其他用户加入我房间的呼叫,但是当我将其部署在Heroku上时,我需要更改peerJS选项,这就是这种情况
const myPeer = new Peer(undefined, {
host: 'https://video-call-1205.herokuapp.com',
port: '443'
})
我将主机更改为我部署的网站和默认端口443(端口443用于https,然后我添加了secure: true
,但它没有任何变化,因此我将其删除了。)
部署后,它无法像在开发环境中一样显示新用户的视频流到我的房间,并且在我heroku logs --tails
时返回此视频:
Warning: heroku update available from 7.40.0 to 7.45.0.
2020-10-10T15:52:01.000000+00:00 app[api]: Build started by user dotam1236@gmail.com
2020-10-10T15:52:27.767123+00:00 app[api]: Deploy 9c027321 by user dotam1236@gmail.com
2020-10-10T15:52:27.767123+00:00 app[api]: Release v4 created by user dotam1236@gmail.com
2020-10-10T15:52:28.146771+00:00 heroku[web.1]: State changed from crashed to starting
2020-10-10T15:52:29.000000+00:00 app[api]: Build succeeded
2020-10-10T15:52:31.555135+00:00 heroku[web.1]: Starting process with command `npm start`
2020-10-10T15:52:34.461279+00:00 app[web.1]:
2020-10-10T15:52:34.461302+00:00 app[web.1]: > zoom-clone@1.0.0 start /app
2020-10-10T15:52:34.461303+00:00 app[web.1]: > concurrently "node server.js" "peerjs --port 443"
2020-10-10T15:52:34.461303+00:00 app[web.1]:
2020-10-10T15:52:35.108160+00:00 app[web.1]: [1] Error: Error: listen EACCES: permission denied 0.0.0.0:443
2020-10-10T15:52:35.113762+00:00 app[web.1]: [0] 38278 is listening
2020-10-10T15:52:35.827905+00:00 heroku[web.1]: State changed from starting to up
2020-10-10T15:52:42.950042+00:00 heroku[router]: at=info method=GET path="/" host=video-call-1205.herokuapp.com request_id=3c02adae-9714-4a72-8dca-fc8445bece47 fwd="123.24.189.206" dyno=web.1 connect=0ms service=26ms status=302 bytes=343 protocol=https
2020-10-10T15:52:43.197284+00:00 heroku[router]: at=info method=GET path="/0cfaf06f-de20-4e9c-8910-8e7b0e3a7190" host=video-call-1205.herokuapp.com request_id=05aa1b62-55cc-4dd9-bcc4-6d9be1517c92 fwd="123.24.189.206" dyno=web.1 connect=0ms service=10ms status=200 bytes=1056 protocol=https
2020-10-10T15:52:43.475339+00:00 heroku[router]: at=info method=GET path="/socket.io/socket.io.js" host=video-call-1205.herokuapp.com request_id=09cde213-78fb-47cf-a78d-39d611b01042 fwd="123.24.189.206" dyno=web.1 connect=0ms service=6ms status=200 bytes=68890 protocol=https
2020-10-10T15:52:43.507110+00:00 heroku[router]: at=info method=GET path="/script.js" host=video-call-1205.herokuapp.com request_id=a6858fc6-40e6-44b7-8874-8f077dd8b400 fwd="123.24.189.206"
dyno=web.1 connect=0ms service=7ms status=200 bytes=1774 protocol=https
2020-10-10T15:52:44.210182+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=NKJDjee" host=video-call-1205.herokuapp.com request_id=b46c3958-6eec-4677-b0b8-7caf4fb10b35 fwd="123.24.189.206" dyno=web.1 connect=0ms service=7ms status=200 bytes=344 protocol=https
2020-10-10T15:52:44.220763+00:00 heroku[router]: at=info method=GET path="/peerjs/id?ts=16023451633060.025927193037433183" host=video-call-1205.herokuapp.com request_id=e49e2680-6d4f-4cd7-938b-4d93dd36d5e4 fwd="123.24.189.206" dyno=web.1 connect=0ms service=16ms status=404 bytes=392 protocol=https
2020-10-10T15:52:44.494078+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=video-call-1205.herokuapp.com request_id=6df4aa48-251b-4e41-b02e-12f6b89e21b8 fwd="123.24.189.206" dyno=web.1 connect=0ms service=3ms status=200 bytes=1031 protocol=https
2020-10-10T15:52:45.314106+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=NKJDjix&sid=Ox_qBmei5z0qCTv_AAAA" host=video-call-1205.herokuapp.com request_id=f281a81d-91bc-4e4c-ad40-c69b7eadedc1 fwd="123.24.189.206" dyno=web.1 connect=0ms service=834ms status=200 bytes=242 protocol=https
2020-10-10T15:53:03.442847+00:00 heroku[router]: at=info method=GET path="/0cfaf06f-de20-4e9c-8910-8e7b0e3a7190" host=video-call-1205.herokuapp.com request_id=06d4a897-e8f4-4eec-a9e9-1f750eb0ba0c fwd="123.24.189.206" dyno=web.1 connect=1ms service=2ms status=304 bytes=151 protocol=https
2020-10-10T15:53:03.730236+00:00 heroku[router]: at=info method=GET path="/socket.io/socket.io.js" host=video-call-1205.herokuapp.com request_id=5d30e05d-1e0b-4d96-8e28-5a4f7e0aa1b8 fwd="123.24.189.206" dyno=web.1 connect=0ms service=1ms status=304 bytes=85 protocol=https
2020-10-10T15:53:03.751249+00:00 heroku[router]: at=info method=GET path="/script.js" host=video-call-1205.herokuapp.com request_id=34223a1d-1cc3-47a6-a538-f03223049e22 fwd="123.24.189.206"
dyno=web.1 connect=0ms service=4ms status=304 bytes=237 protocol=https
2020-10-10T15:53:03.993402+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=NKJDoTu" host=video-call-1205.herokuapp.com request_id=897bbf64-bc57-436c-8d17-5a22a99e408f fwd="123.24.189.206" dyno=web.1 connect=0ms service=2ms status=200 bytes=344 protocol=https
2020-10-10T15:53:03.998413+00:00 heroku[router]: at=info method=GET path="/peerjs/id?ts=16023451830980.4864564404021954" host=video-call-1205.herokuapp.com request_id=74d93f6f-aa91-4d65-a311-fcd55ee69052 fwd="123.24.189.206" dyno=web.1 connect=0ms service=2ms status=404 bytes=392 protocol=https
2020-10-10T15:53:04.243903+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=video-call-1205.herokuapp.com request_id=e7239925-50e3-493d-bf81-ee0a5778c5de fwd="123.24.189.206" dyno=web.1 connect=0ms service=2ms status=304 bytes=151 protocol=https
2020-10-10T15:53:05.123902+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=NKJDoXo&sid=-LlknRjpAmyG2pZjAAAB" host=video-call-1205.herokuapp.com request_id=fb0d685e-47d4-427f-a358-3d20fb98127d fwd="123.24.189.206" dyno=web.1 connect=0ms service=882ms status=200 bytes=242 protocol=https
2020-10-10T15:54:34.503604+00:00 heroku[router]: at=info method=GET path="/" host=video-call-1205.herokuapp.com request_id=ed6b41d6-b279-4cd6-9906-4d746fb484d7 fwd="123.24.189.206" dyno=web.1 connect=0ms service=2ms status=302 bytes=343 protocol=https
2020-10-10T15:54:34.752760+00:00 heroku[router]: at=info method=GET path="/82918cdc-0532-4d7d-878f-cee70753ba9b" host=video-call-1205.herokuapp.com request_id=5984b250-efc1-4c87-8810-c73cd73aa8a6 fwd="123.24.189.206" dyno=web.1 connect=0ms service=2ms status=200 bytes=1056 protocol=https
2020-10-10T15:54:35.012068+00:00 heroku[router]: at=info method=GET path="/socket.io/socket.io.js" host=video-call-1205.herokuapp.com request_id=5257c4d9-5102-4665-9f09-cde1ec08eebe fwd="123.24.189.206" dyno=web.1 connect=0ms service=1ms status=304 bytes=85 protocol=https
2020-10-10T15:54:35.039066+00:00 heroku[router]: at=info method=GET path="/script.js" host=video-call-1205.herokuapp.com request_id=50506f9e-8895-411e-a712-4bfcb95edb77 fwd="123.24.189.206"
dyno=web.1 connect=1ms service=2ms status=304 bytes=237 protocol=https
2020-10-10T15:54:35.288715+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=NKJE8mN" host=video-call-1205.herokuapp.com request_id=f1bb6d06-ccf4-40d4-b5f8-781bf2fb0f33 fwd="123.24.189.206" dyno=web.1 connect=1ms service=2ms status=200 bytes=344 protocol=https
2020-10-10T15:54:35.291544+00:00 heroku[router]: at=info method=GET path="/peerjs/id?ts=16023452743940.9677853939424659" host=video-call-1205.herokuapp.com request_id=47f8c400-85f4-4bce-bf57-3cfd2c77985d fwd="123.24.189.206" dyno=web.1 connect=0ms service=2ms status=404 bytes=392 protocol=https
2020-10-10T15:54:35.392115+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=video-call-1205.herokuapp.com request_id=9bdbabb9-261f-4611-807e-f31561e96ea9 fwd="123.24.189.206" dyno=web.1 connect=0ms service=2ms status=304 bytes=151 protocol=https
2020-10-10T15:54:36.400106+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=polling&t=NKJE8qO&sid=bn5uFuLwEldV9fhJAAAC" host=video-call-1205.herokuapp.com request_id=ad394059-fb4c-448a-bdf1-9cc3c1585058 fwd="123.24.189.206" dyno=web.1 connect=1ms service=857ms status=200 bytes=242 protocol=https
2020-10-10T15:54:36.710379+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=websocket&sid=bn5uFuLwEldV9fhJAAAC" host=video-call-1205.herokuapp.com request_id=a5dd79b9-c210-46f0-b262-0649d858815f fwd="123.24.189.206" dyno=web.1 connect=0ms service=662ms status=101 bytes=183 protocol=https
2020-10-10T15:54:37.969679+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=websocket&sid=-LlknRjpAmyG2pZjAAAB" host=video-call-1205.herokuapp.com request_id=d2beac6d-229e-4d08-b349-a020aa6d9b6b fwd="123.24.189.206" dyno=web.1 connect=1ms service=93219ms status=101 bytes=192 protocol=https
2020-10-10T15:54:39.243856+00:00 heroku[router]: at=info method=GET path="/socket.io/?EIO=3&transport=websocket&sid=Ox_qBmei5z0qCTv_AAAA" host=video-call-1205.herokuapp.com request_id=9cca0024-b633-4203-93e9-e63193137156 fwd="123.24.189.206" dyno=web.1 connect=0ms service=114290ms status=101 bytes=195 protocol=https
2020-10-10T15:55:20.000000+00:00 app[api]: Build started by user dotam1236@gmail.com
2020-10-10T15:55:46.839269+00:00 app[api]: Release v5 created by user dotam1236@gmail.com
2020-10-10T15:55:46.839269+00:00 app[api]: Deploy 0814d749 by user dotam1236@gmail.com
2020-10-10T15:55:47.118469+00:00 heroku[web.1]: Restarting
2020-10-10T15:55:47.121140+00:00 heroku[web.1]: State changed from up to starting
2020-10-10T15:55:48.000000+00:00 app[api]: Build succeeded
2020-10-10T15:55:48.072129+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2020-10-10T15:55:48.105266+00:00 app[web.1]: Error waiting for process to terminate: No child processes
2020-10-10T15:55:48.186453+00:00 heroku[web.1]: Process exited with status 22
2020-10-10T15:55:50.813904+00:00 heroku[web.1]: Starting process with command `npm start`
2020-10-10T15:55:53.643756+00:00 app[web.1]:
2020-10-10T15:55:53.643776+00:00 app[web.1]: > zoom-clone@1.0.0 start /app
2020-10-10T15:55:53.643777+00:00 app[web.1]: > concurrently "node server.js" "peerjs --port 443"
2020-10-10T15:55:53.643777+00:00 app[web.1]:
如您所见,它仅返回一个错误(就我而言):
2020-10-10T15:52:35.108160+00:00 app[web.1]: [1] Error: Error: listen EACCES: permission denied 0.0.0.0:443
看起来无法访问PeerJS的云服务器
请告诉我如何解决它,非常感谢,并祝您愉快
更新:我发现端口<1024是呼叫保留端口,并且不允许使用它们,然后将端口更改为8081,它仍然出现相同的错误,就像部署时的端口一样尚未受到影响。
this is my `server.js`
const express = require('express')
const app = express()
const server = require('http').Server(app)
const io = require('socket.io')(server)
const { v4: uuidV4 } = require('uuid')
var PORT = process.env.PORT || 3000
app.set('view engine', 'ejs')
app.use(express.static('public'))
app.get('/', (req, res) => {
res.redirect(`/${uuidV4()}`)
})
app.get('/:room', (req, res) => {
res.render('room', { roomId: req.params.room })
})
io.on('connection', socket => {
socket.on('join-room', (roomId, userId) => {
socket.join(roomId)
socket.to(roomId).broadcast.emit('user-connected', userId)
socket.on('disconnect', () => {
socket.to(roomId).broadcast.emit('user-disconnected', userId)
})
})
})
server.listen(PORT, () => {
console.log(PORT, 'is listening')
})
这是客户端上的文件script.js
,我在客户端上使用peerJS
const socket = io('/')
const videoGrid = document.getElementById('video-grid')
const myPeer = new Peer(undefined, {
host: '/',
port: '9000'
})
const myVideo = document.createElement('video')
myVideo.muted = true
const peers = {}
navigator.mediaDevices
.getUserMedia({
video: true,
audio: false
})
.then(stream => {
addVideoStream(myVideo, stream)
myPeer.on('call', call => {
call.answer(stream)
const video = document.createElement('video')
call.on('stream', userVideoStream => {
console.log(userVideoStream)
addVideoStream(video, userVideoStream)
})
})
socket.on('user-connected', userId => {
connectToNewUser(userId, stream)
})
})
socket.on('user-disconnected', userId => {
if (peers[userId]) {
console.log('user disconnected', userId)
console.log('peers', peers)
peers[userId].close()
}
})
myPeer.on('open', id => {
socket.emit('join-room', ROOM_ID, id)
})
function connectToNewUser (userId, stream) {
const call = myPeer.call(userId, stream)
const video = document.createElement('video')
call.on('stream', userVideoStream => {
addVideoStream(video, userVideoStream)
})
call.on('close', () => {
video.remove()
})
peers[userId] = call
console.log('peers', peers)
}
function addVideoStream (video, stream) {
video.srcObject = stream
video.addEventListener('loadedmetadata', () => {
video.play()
})
videoGrid.append(video)
}
谢谢你帮我,祝你有美好的一天