Download the PHP package wunderwerkio/emitter-sdk without Composer
On this page you can find all versions of the php package wunderwerkio/emitter-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wunderwerkio/emitter-sdk
More information about wunderwerkio/emitter-sdk
Files in wunderwerkio/emitter-sdk
Package emitter-sdk
Short Description PHP SDK for the emitter event broker
License MIT
Informations about the package emitter-sdk
This repository provides a PHP SDK for Emitter.
Installation
Using composer:
Emitter API
This PHP SDK implements the following methods as described in the emitter docs:
- [x]
connect
- [x]
disconnect
- [x]
publish
- [x]
subscribe
- [x]
unsubscribe
- [x]
keygen
- [x]
presence
- [x]
me
Examples
Connect to emitter server
Publish
Subscribe
Please note that this method simply subscribes for a channel.
To receive messages, the addMessageHandler
method must be used!
Listen for messages
In order to receive incoming messages from the server, a callback handler must be registered with addMessageHandler
.
Additionally, a event loop must be started by calling loop()
to start listening for server connections.
This loop method is blocking, but can be released by calling the interrupt()
method.
To avoid a deadlock, make sure you structure your code so that the interrupt()
method is called once the desired messages are received.
Loop handler
The internal event loop supports calling custom handlers on each loop cycle. This can be used to implement timeouts for example to interrupt the event loop if no messages are received in 10 seconds.
Generate a channel key
To publish and subscribe to channels, emitter needs a channel key.
A channel key can be generated with the keygen()
method by passing the master key, the channel name, the desired permissions and optionally a TTL in seconds for the channel key.
Device presence
Emitter has built-in support for device presence.
To receive presence data from other users, the presence()
method can be used to subscribe to presence events.
If the changes
argument is FALSE
changes in presence of other users will not be automatically received and have to be requested via presence()
again.
Please note, that emitter only sends presence info for a maximum of 1000 users.