I have chat everything is ok. But now my server send message for all users. I want to send private message. How can i identify each user and send private message ?
Client is iOS.
example
Client send to server json data
{
userID:444,
sendTo:555,
message:"Hello"
}
sorry for my poor English..
insert this on onMessange event func
$json = (json_decode($msg,true)); // {"userID":"#", "sendTo":"#", "message":"lorem"}
$msg = $json['message'];
$tosendid = $json['sendTo'];
foreach ($this->clients as $client) {
if ($tosendid == $client->resourceId) {
$client->send($msg);
}
}
I have the same situation and I don't understand how to get $client->resourceId on the front (browser)? I mean when I send message I need to know to which user send this message. In example above you compare $client->resourceId. How I can get it?
Most helpful comment
insert this on onMessange event func