Using Pusher API notify Particular User

断了今生、忘了曾经 提交于 2019-12-23 03:29:09

问题


i have one mobile web app using jquery mobile and phonegap and other is php website .i want that send notification just to particular user who's online and on mobile app as well, recieve notification which user online on php website end as well as mobile web app so my question is that how to set channel for particular user because now notification sent to all users which is useless of messages and connection.

Currently my code sending notifications to all can any one idea about this problem where changes will require on my code.

on event trigger i have that code php site.

$message = "User Response Has been Sent For Taxi On way";
            $pusher = new Pusher( APP_KEY, APP_SECRET, APP_ID );
            $data = array('message' => $message);
            $pusher->trigger( 'dispatcher_channel', 'dispatcher_Response', $data );

on mobile web app i have that Code.

Pusher.log = function(message) {
          if (window.console && window.console.log) {
            window.console.log(message);
          }
        };

        var pusher = new Pusher('APP_KEY');
        var channel = pusher.subscribe('dispatcher_channel');
        channel.bind('dispatcher_Response', function(data) {
          alert(data.message);
          channel.bind('dispatcher_Response', function(data) {});
        });

回答1:


Try making the username (which I assume is unique to the user) part of the channel name on both ends. Then publish to that channel.



来源:https://stackoverflow.com/questions/19366545/using-pusher-api-notify-particular-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!