2014-11-03 70 views
1

我試圖建立我自己的peerJS服務器上https://github.com/peers/peerjs-server#combining-with-existing-express-app設置peerJS服務器快遞

我的代碼中的自述服務器上合併之後

port = process.env.PORT or 8080 
http = require 'http' 
express = require 'express' 
app = express() 
server = http.createServer app 
app.use '/peerjs', ExpressPeerServer server, debug : on 
server.listen port 
server.listen 9000 

我的客戶端代碼

peer = new Peer 
    host : 'localhost' 
    port : 9000 
    secure : no 
    config : 
     iceServers : [ url : 'stun:stun.l.google.com:19302' ] 

我在客戶端控制檯上收到此錯誤

GET http://localhost:9000/peerjs/peerjs/id?ts=14150106969530.4679094860330224 net::ERR_CONNECTION_REFUSED 

回答

0

一個必須設定自己的客戶端這樣對服務器的路徑:

var peer = new Peer('your_peer_id', {host: 'localhost', port: 9000, path: '/peerjs'}); 

(此路徑必須是與路由路徑相同的,以你的ExpressPeerServer

1

如果你是仍然在尋找一種方法來建立自己的對等服務器,那麼這就是我所做的努力,使其爲我工作。

server.js

// initialize express 
var express = require('express'); 
var app = express(); 
// create express peer server 
var ExpressPeerServer = require('peer').ExpressPeerServer; 

var options = { 
    debug: true 
} 

// create a http server instance to listen to request 
var server = require('http').createServer(app); 

// peerjs is the path that the peerjs server will be connected to. 
app.use('/peerjs', ExpressPeerServer(server, options)); 
// Now listen to your ip and port. 
server.listen(8878, "192.168.1.14"); 

客戶端代碼

我猜,你不應該有這麼多的問題,但如果你想知道該怎麼把某些參數,然後這裏是對等對象的初始化:

var peer = new Peer({ 
    host: '192.168.1.14', 
    port: 8878, 
    path: '/peerjs', 
    config: { 'iceServers': [ 
    { url: 'stun:stun01.sipphone.com' }, 
    { url: 'stun:stun.ekiga.net' }, 
{ url: 'stun:stunserver.org' }, 
{ url: 'stun:stun.softjoys.com' }, 
{ url: 'stun:stun.voiparound.com' }, 
{ url: 'stun:stun.voipbuster.com' }, 
{ url: 'stun:stun.voipstunt.com' }, 
{ url: 'stun:stun.voxgratia.org' }, 
{ url: 'stun:stun.xten.com' }, 
{ 
    url: 'turn:192.158.29.39:3478?transport=udp', 
    credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=', 
    username: '28224511:1379330808' 
}, 
{ 
    url: 'turn:192.158.29.39:3478?transport=tcp', 
    credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=', 
    username: '28224511:1379330808' 
    } 
    ] 
    }, 

debug: 3 
}); 

這應該是他讓你建立連接。