Javascript 我正在尝试创建自己的PeerJS服务器
下面是代码,但我不知道我遗漏了什么 index.js(像服务器一样工作) app.js(主js文件) routes.jsJavascript 我正在尝试创建自己的PeerJS服务器,javascript,node.js,express,webrtc,peerjs,Javascript,Node.js,Express,Webrtc,Peerjs,下面是代码,但我不知道我遗漏了什么 index.js(像服务器一样工作) app.js(主js文件) routes.js { 'iceServers': [{ 'url': 'stun:stun.l.google.com:19302' }] }; var express = require('express'); var router = express.Router(); var config = require('./config'); var Call = require('./cal
{ 'iceServers': [{ 'url': 'stun:stun.l.google.com:19302' }] };
var express = require('express');
var router = express.Router();
var config = require('./config');
var Call = require('./call');
// Create a new Call instance, and redirect
router.get('/new', function(req, res) {
var call = Call.create();
res.redirect('/' + call.id);
});
// Add PeerJS ID to Call instance when someone opens the page
router.post('/:id/addpeer/:peerid', function(req, res) {
var call = Call.get(req.param('id'));
if (!call) return res.status(404).send('Call not found');
call.addPeer(req.param('peerid'));
res.json(call.toJSON());
});
// Remove PeerJS ID when someone leaves the page
router.post('/:id/removepeer/:peerid', function(req, res) {
var call = Call.get(req.param('id'));
if (!call) return res.status(404).send('Call not found');
call.removePeer(req.param('peerid'));
res.json(call.toJSON());
});
// Return JSON representation of a Call
router.get('/:id.json', function(req, res) {
var call = Call.get(req.param('id'));
if (!call) return res.status(404).send('Call not found');
res.json(call.toJSON());
});
// Render call page
router.get('/:id', function(req, res) {
var call = Call.get(req.param('id'));
if (!call) return res.redirect('/new');
res.render('call', {
apiKey: config.peerjs.key,
call: call.toJSON()
});
});
// Landing page
router.get('/', function(req, res) {
res.render('index');
});
module.exports = router;
Call.js(html文件)
Rapidcom
var peer=新的对等(id,{host:'https://rapidcom.herokuapp.com,端口:9000,路径:'.public/app'});
window.call=;
我还在heroku上托管了一个PeerJs服务器,请帮我创建这个,我不知道我被困在哪里了。我试着拉每根绳子,但没有得到这样的错误
TypeError:无法读取未定义的属性“key”
在C:\Users\Windows\Desktop\RapidComNew\routes.js:41:27
在Layer.handle[作为handle\u请求](C:\Users\Windows\Desktop\RapidComNew\node\u modules\express\lib\router\Layer.js:82:5)
下一步(C:\Users\Windows\Desktop\RapidComNew\node\u modules\express\lib\router\route.js:100:13)
在Route.dispatch(C:\Users\Windows\Desktop\RapidComNew\node\u modules\express\lib\router\Route.js:81:3)
在Layer.handle[作为handle\u请求](C:\Users\Windows\Desktop\RapidComNew\node\u modules\express\lib\router\Layer.js:82:5)
在C:\Users\Windows\Desktop\RapidComNew\node\u modules\express\lib\router\index.js:233:24
at参数(C:\Users\Windows\Desktop\RapidComNew\node\u modules\express\lib\router\index.js:330:14)
在参数处(C:\Users\Windows\Desktop\RapidComNew\node\u modules\express\lib\router\index.js:346:14)
位于Function.proto.process_参数(C:\Users\Windows\Desktop\RapidComNew\node\u modules\express\lib\router\index.js:390:3)
在app.js中的C:\Users\Windows\Desktop\RapidComNew\node\u modules\express\lib\router\index.js:227:12而不是
var peer = new Peer({
host: location.hostname,
port: location.port || (location.protocol === 'https://rapidcom.herokuapp.com' ? 9000 : 80),
path: '/peerjs'
});
加上这个
me = new Peer({ host:'rapidserver.herokuapp.com', secure:true, port:443, key: 'peerjs', debug: 3})
<!DOCTYPE html>
<html>
<head>
<title>Rapidcom</title>
</head>
<body>
<div class="wrapper">
<div id="display"></div>
</div>
<footer>
<div class="wrapper">
<a href="/new"> ~~~~~Start another call~~~~~~~</a>
</div>
</footer>
var peer = new Peer( id,{ host: 'https://rapidcom.herokuapp.com', port: 9000, path: '.public/app' });
window.call = <%- JSON.stringify(call, null, 2) %>;
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="/app.js"></script>
<script src="/peer.js"></script>
</body>
</html>
var peer = new Peer({
host: location.hostname,
port: location.port || (location.protocol === 'https://rapidcom.herokuapp.com' ? 9000 : 80),
path: '/peerjs'
});
me = new Peer({ host:'rapidserver.herokuapp.com', secure:true, port:443, key: 'peerjs', debug: 3})