I'm just starting with WebSockets right now.
I'm working with Twilio (voip API) and I need to make a responsive page that reacts when something happen in a phone call.
For example: The user starts the call and the browser alerts them that they're in a call. If the user hangs up, the status "in-call" must be removed.
What I'm not figuring out to do is make a $client->send($jsonWithCallStatus)
from the server if I don't have the $client
object? How can I get that object?
If I was able to understand your question, you are looking for a way to send json to a client.
And you don't have the client object yet.
To make a client object you would first have to get the client(browser/app) to connect to the WebSocket server. Then you would be able to make a $connection
object which connects to the certain client.
Then you would be able to assign an ID to this $connection
object and save this ID in your database or whatever you are using.
This ID could be reused to later retrieve the $connection
object and send the certain data to that client.
The ID I mentioned before could be the same as a userId, if you have that anywhere.
More information about what you are doing and using might be really usefull to further help you.