2016-06-17 10 views
0

PeerJS Serverでは、接続イベントのパラメータはidではありません。私はそれがソケットだと思います。PeerJS - 接続イベントのパラメータがidではありません

以下は私のコードです。

var express = require('express'); 
var app = express(); 
var ExpressPeerServer = require('peer').ExpressPeerServer; 

app.get('/', function(req, res, next) { res.send('Hello world!'); }); 

var server = app.listen(9000); 

var options = { 
    debug: true 
}; 

app.use('/api', ExpressPeerServer(server, options)); 

server.on('connection', function(id) { console.log(id); }); 

私はそれを実行してhttp://localhost:9000/を入力

は、コンソール版画巨大なテキストは、IDのように見えるしていません。

Socket { 
    _connecting: false, 
    _hadError: false, 
    _handle: 
    TCP { 
    _externalStream: {}, 
    fd: -1, 
    reading: true, 
    owner: [Circular], 
    onread: [Function: onread], 
    onconnection: null, 
    writeQueueSize: 0 }, 
    _parent: null, 
    _host: null, 
    _readableState: 
    ReadableState { 
    objectMode: false, 
    highWaterMark: 16384, 
    buffer: [], 
    length: 0, 
    pipes: null, 
    pipesCount: 0, 
    flowing: true, 
    ended: false, 
    endEmitted: false, 
    reading: true, 
    sync: false, 
    needReadable: true, 
    emittedReadable: false, 
    readableListening: false, 
    resumeScheduled: true, 
    defaultEncoding: 'utf8', 
    ranOut: false, 
    awaitDrain: 0, 
    readingMore: false, 
    decoder: null, 
    encoding: null }, 
    readable: true, 
    domain: null, 
    _events: 
    { end: [ [Object], [Function: socketOnEnd] ], 
    finish: [Function: onSocketFinish], 
    _socketEnd: [Function: onSocketEnd], 
    drain: [ [Function: ondrain], [Function: socketOnDrain] ], 
    timeout: [Function], 
    error: [Function: socketOnError], 
    close: [Function: serverSocketCloseListener], 
    data: [Function: socketOnData], 
    resume: [Function: onSocketResume], 
    pause: [Function: onSocketPause] }, 
    _eventsCount: 10, 
    _maxListeners: undefined, 
    _writableState: 
    WritableState { 
    objectMode: false, 
    highWaterMark: 16384, 
    needDrain: false, 
    ending: false, 
    ended: false, 
    finished: false, 
    decodeStrings: false, 
    defaultEncoding: 'utf8', 
    length: 0, 
    writing: false, 
    corked: 0, 
    sync: true, 
    bufferProcessing: false, 
    onwrite: [Function], 
    writecb: null, 
    writelen: 0, 
    bufferedRequest: null, 
    lastBufferedRequest: null, 
    pendingcb: 0, 
    prefinished: false, 
    errorEmitted: false, 
    bufferedRequestCount: 0, 
    corkedRequestsFree: CorkedRequest { next: [Object], entry: null, finish: [Function] } }, 
    writable: true, 
    allowHalfOpen: true, 
    destroyed: false, 
    bytesRead: 0, 
    _bytesDispatched: 0, 
    _sockname: null, 
    _pendingData: null, 
    _pendingEncoding: '', 
    server: 
    Server { 
    domain: null, 
    _events: 
     { request: [Object], 
     connection: [Object], 
     clientError: [Function], 
     error: [Function], 
     upgrade: [Function] }, 
    _eventsCount: 5, 
    _maxListeners: undefined, 
    _connections: 1, 
    _handle: 
     TCP { 
     _externalStream: {}, 
     fd: -1, 
     reading: false, 
     owner: [Circular], 
     onread: null, 
     onconnection: [Function: onconnection], 
     writeQueueSize: 0 }, 
    _usingSlaves: false, 
    _slaves: [], 
    _unref: false, 
    allowHalfOpen: true, 
    pauseOnConnect: false, 
    httpAllowHalfOpen: false, 
    timeout: 120000, 
    _pendingResponseData: 0, 
    _connectionKey: '6::::9000', 
    _webSocketPaths: { '/api/peerjs': 1 } }, 
    _server: 
    Server { 
    domain: null, 
    _events: 
     { request: [Object], 
     connection: [Object], 
     clientError: [Function], 
     error: [Function], 
     upgrade: [Function] }, 
    _eventsCount: 5, 
    _maxListeners: undefined, 
    _connections: 1, 
    _handle: 
     TCP { 
     _externalStream: {}, 
     fd: -1, 
     reading: false, 
     owner: [Circular], 
     onread: null, 
     onconnection: [Function: onconnection], 
     writeQueueSize: 0 }, 
    _usingSlaves: false, 
    _slaves: [], 
    _unref: false, 
    allowHalfOpen: true, 
    pauseOnConnect: false, 
    httpAllowHalfOpen: false, 
    timeout: 120000, 
    _pendingResponseData: 0, 
    _connectionKey: '6::::9000', 
    _webSocketPaths: { '/api/peerjs': 1 } }, 
    _idleTimeout: 120000, 
    _idleNext: { _idleNext: [Circular], _idlePrev: [Circular] }, 
    _idlePrev: { _idleNext: [Circular], _idlePrev: [Circular] }, 
    _idleStart: 2700, 
    parser: 
    HTTPParser { 
    '0': [Function: parserOnHeaders], 
    '1': [Function: parserOnHeadersComplete], 
    '2': [Function: parserOnBody], 
    '3': [Function: parserOnMessageComplete], 
    '4': [Function: onParserExecute], 
    _headers: [], 
    _url: '', 
    _consumed: true, 
    socket: [Circular], 
    incoming: null, 
    outgoing: null, 
    maxHeaderPairs: 2000, 
    onIncoming: [Function: parserOnIncoming] }, 
    on: [Function: socketOnWrap], 
    _paused: false } 

バニラIDを取得するにはどうすればよいですか?

答えて

1

ExpressPeerServerではなくhttpモジュールの接続イベントを使用しようとしました。

以下は変更されたコードです。

var express = require('express'); 
var app = express(); 
var ExpressPeerServer = require('peer').ExpressPeerServer; 

app.get('/', function(req, res, next) { res.send('Hello world!'); }); 

var server = app.listen(9000); 

var options = { 
    debug: true 
}; 

var peerServer = ExpressPeerServer(server, options); 
app.use('/api', peerServer); 

peerServer.on('connection', function(id) { console.log(id); }); 

http://localhost:9000/と入力すると、バニラIDが印刷されます。

関連する問題