tokenly / pusher-client
A library
Installs: 8 921
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- php: >=5.5.0
- mockery/mockery: ^0.9
- nc/faye-client: ~1.1
Requires (Dev)
- phpunit/phpunit: ~4
This package is not auto-updated.
Last update: 2024-10-26 17:19:49 UTC
README
A client component for the client-side messaging pusher service.
Installation
composer require tokenly/pusher-client
- Add
Tokenly\PusherClient\Provider\PusherClientServiceProvider::class
to the list of service providers
Environment Variables
Set the following environment variables
PUSHER_SERVER_URL
(optional, defaults to https://pusher.tokenly.com)PUSHER_CLIENT_URL
(optional, defaults to the server URL)PUSHER_PASSWORD
(required for Tokenly services)
Server-side Usage
Send an event
$channel = 'my-event-channel-name'; $data = json_encode(['fromUser' => 'fred', 'messageId' => 101, 'messageText' => 'hello world!']); $pusher = app(\Tokenly\PusherClient\Client::class); $pusher->send($channel, $data);
Client-side Usage
See the pusher-client.js example for the client javascript code.
Step 1: Include the two libraries
This is best toward the end of your body tag.
<script src="https://pusher.tokenly.com/public/client.js"></script> <script src="/path/to/js/pusher-client.js"></script>
Step 2: Subscribe and respond to events
After the two script tags below are loaded, you can subscribe to a channel
<script> var subscribedClient = PusherClient.subscribeToPusherChanel('my-event-channel-name', function(dataReceived) { // received a websocket message on channel /my-event-channel-name console.log('user '+dataReceived.fromUser+' said '+messageText); }); </script>