0

ユーザーが node.js サーバーにデータを送信できるようにするプライベート チャネルを作成しようとしています。リクエストが失敗し、エラー コード 500 の pusher:subscription_error が返されます。

私のnode.js(サーバー側)ログは、着信リクエストからsocket_idを「/pusher/auth」にプルできません

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 );
} );

リクエストを送信するクライアント側は次のとおりです。

   // 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 変数にアクセスするにはどうすればよいですか?

4

1 に答える 1

2

bodyParserリクエスト本文を解析して利用可能にする を設定する必要があるようrequest.bodyです。

プッシャーのドキュメントを参照してください: http://pusher.com/docs/authenticating_users#implementing_private_endpoints/lang=node

于 2013-10-21T08:59:25.077 に答える