-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
broadcast-messages-with-your-php-app-boom- #22
Comments
@rodriguesfas can you please try this ? |
Thanks for answering me. This link you sent me, I have already tested the application and it works very well. However, it sends the message from ws in the frontend. I'm needing to send the message inside the php controller. I'm trying to use Broadcast messages with your php App that you suggested in the documentation, but it doesn't work for me, I was wondering if you have a working example of this part or if you would put more details on how it works. |
Please look at the Welcome.php controller.
The main concept is the callback function. You would receive the response into the defined function. You can trigger the event from the front end like below using jQuery
It would trigger the function below
Please look at this Room Chat using PHP websocket. It was built using this |
Hi there,
Thanks your suggestions did work indeed.
I have another question though.
Using php, how can I check which clients are currently active?
My problem:
What is a specific user has multiple open tabs of the same page, then each tab has the same client id.
This causes glitches, so technically each page needs it’s own client id.
However, I need to broadcast to all of these tabs for that user… This means I need to know which client id’s are active.
Kind Regards,
Jaco
Jaco SJ Krüger
B.Eng Mechanical Engineering
Performance Manager
Mobile: +27 79 361 0853
Website: www.basecloudglobal.com<http://www.basecloudglobal.com/>
[A close up of a logo Description automatically generated]<https://www.basecloudglobal.com/>
[review-us-google]<https://www.google.com/search?authuser=1&source=hp&ei=Ev9bXcDtNtDVwQLyxa64Dw&q=basecloud&oq=basecloud&gs_l=psy-ab.3..0i10l4j0i10i30j0i30j0i10i30l2j0i5i30l2.1561.2806..3059...1.0..0.435.2824.3-7j1......0....1..gws-wiz.....2..35i39j0i131j0j0i67.u-O_luTJYQQ&ved=0ahUKEwjAvviG0JHkAhXQalAKHfKiC_cQ4dUDCAU&uact=5#lrd=0x1e955fa6b3d0fdb5:0x5dcd69d9d6690d4a,1,,,>
From: Taki Elias ***@***.***>
Sent: Tuesday, 21 December 2021 15:01
To: takielias/codeigniter-websocket ***@***.***>
Cc: Jaco SJ Krüger ***@***.***>; Mention ***@***.***>
Subject: Re: [takielias/codeigniter-websocket] broadcast-messages-with-your-php-app-boom- (#22)
@rodriguesfas<https://github.com/rodriguesfas> @JacoSJKruger<https://github.com/JacoSJKruger>
Please look at the Welcome.php controller.
public function index()
{
// Load package path
$this->load->add_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket');
$this->load->library('Codeigniter_websocket');
$this->load->remove_package_path(FCPATH . 'vendor/takielias/codeigniter-websocket');
// Run server
$this->codeigniter_websocket->set_callback('auth', array($this, '_auth'));
$this->codeigniter_websocket->set_callback('event', array($this, '_event'));
$this->codeigniter_websocket->set_callback('roomleave', array($this, '_roomleave'));
$this->codeigniter_websocket->run();
}
public function _roomleave($data = null)
{
// Here you will receive data from the frontend roomleave event trigger.
echo 'Hey ! I\'m a room leave EVENT callback' . PHP_EOL;
}
The main concept is the callback function.
You would receive the response into the defined function. You can trigger the event from the front end like below using jQuery
socket.send(JSON.stringify({
'type': 'roomleave',
'room_name': targetName,
'user_id': "buzz4rd"
}));
It would trigger the function below
public function _roomleave($data = null)
{
// Here you will receive data from fron tend roomleave event trigger.
echo 'Hey ! I\'m a room leave EVENT callback' . PHP_EOL;
}
Please look at this Room Chat using PHP websocket<https://github.com/takielias/ci-socket-chat>. It was built using this<https://github.com/romainrg/ratchet_client>
—
Reply to this email directly, view it on GitHub<#22 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AWMUY3JV3KUXE7A2G77GE7LUSB3ALANCNFSM5DI2VH6Q>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID: ***@***.******@***.***>>
|
Hi, thanks for the explanation. Maybe I didn't explain well what I'm trying to do, I have two PHP applications, I want to send data from one to the other, but I don't want it through the front end, but backend to backend. Thank you in advance for your attention in answering me. |
Define a global array of logged-in users. If you get a new logged-in user in that array it means already logged in. Disconnect the previous one and active the new one. Simple solution. |
Why don't you use rest API? |
Hi!
Could you give me more details on how to use this piece of code: https://github.com/takielias/codeigniter-websocket#broadcast-messages-with-your-php-app-boom-
Please, if it's not too much bother, put an example of use. Hug.
The text was updated successfully, but these errors were encountered: