2013-10-20 2 views
0

사용자가 node.js 서버로 데이터를 보낼 수 있도록 비공개 채널을 만들려고합니다. 요청은 실패하고, 푸셔 복귀된다 subscription_error을 500푸셔 인증 소켓 ID가 정의되지 않았습니다.

내 Node.js를 (서버 측) 로그의 에러 코드와 함께 '/ 푸셔/인증'

app.post('/pusher/auth', function(req, res) { 
    var socketId = req.body.socket_id;//<--DEBUG: TypeError: Cannot read property 'socket_id' of undefined 

    var channel = req.body.channel_name; 
    var presenceData = { 
    user_id: 'unique_user_id', 
    user_info: { 
     name: 'Mr Pusher', 
     twitter_id: '@pusher' 
    } 
    }; 
    var auth = pusher.auth(socketId, channel, presenceData); 
    res.send(auth); 
}); 
들어오는 요청에서 socket_id를 당길 수없는 여기

는 요청을 보내는 클라이언트 측 :

// Create new Pusher instance and connect 
     var key = "<%= appKey %>" 
     var id = "<%= appKey %>" 
     var secret = "<%= appSecret %>" 
     var pusher = new Pusher("<%= appKey %>"); 

// Subscribe to the channel that the event will be published on 
var channel = pusher.subscribe('private-channel'); 
    channel.bind('pusher:subscription_succeeded',function(){ 
      alert("subscription succeeded") 
      var triggered = channel.trigger("client-event",{}) 
      alert("triggered "+triggered) 
    }) 
    channel.bind('pusher:subscription_error',function(status){ 
      alert("subscription error "+status)//<-- This error gets returned 
    }) 
// Bind to the event on the channel and handle the event when triggered 
channel.bind('client-event', function(data) { 
    // For now, alert the message. 
    alert(data.message); 
}); 

이 자동으로 푸셔 API에 의해 처리, 또는 내가 명시 적으로 보낼 필요가 어떻게해야 하는가를? socket_id를 서버로 보내려면 어떻게해야합니까? 클라이언트의 socket_id 변수에 액세스하는 방법은 무엇입니까?

답변