2014-04-19 52 views
1

我使用PHP和Pusher API編程聊天。 現在,我試圖向個人用戶發起一個事件,但我不知道如何去做。 每個用戶都由會話(用戶名)標識。 這是我如何觸發一條消息:如何僅使用Pusher將事件觸發給個人?

$pusher->trigger(
     'presence-nettuts', //the channel 
     'new_message', //the event 
     array('message' => $message) //the data to send 
); 

//echo the success array for the ajax call 
echo json_encode(array(
     'message' => $message, 
     'success' => true 
)); 
exit(); 

我想直接的事件僅在線用戶,這是由他的用戶名使用會話標識。

你能指導我怎麼做嗎?

謝謝。

+0

可能重複的[推杆發送存在事件以特定構件(http://stackoverflow.com/questions/15591424/pusher-發送-存在事件到特定構件) – leggetter

回答

0

您的頻道名稱應該是該用戶唯一的。 所以,一種可能性是使用唯一的像的用戶名的東西來創建一個信道:

$pusher->trigger(
'presence-nettuts-'.$username, //the channel 
'new_message', //the event 
array('message' => $message) //the data to send 
);