PieSocket Events
PieSocket events are represented by the following message structure.
{
"event": "some-event",
"data": "Any string or JSON string",
"meta": "Any string or JSON string",
"system::to": "User ID | Array of User IDs"
}
The following is an explanation of all the parameters in an Event.
| Parameter | Required? | Details |
|---|---|---|
| event | Yes | Name of the event, being listened to by the client |
| data | Yes | Payload of the event |
| meta | No | Additional information about the event |
| system::to | No | A string containing an user ID or an array of valid user IDs, when system::to is defined, this message is only distributed to specified users. See user identity for details about User IDs. |
How To Create Event Instances
JavaScript
In JavaScript, it is a simple JSON Object.
const tweetEvent = {
"event": "new-tweet",
"data": "Hello from @PieSocketHQ",
"meta": "uuid-1",
"system::to": "john"
}
Android
Use the PieSocketEvent class in Android or Java projects.
PieSocketEvent newTweet = new PieSocketEvent("new-tweet");
newTweet.setData("Hello from @PieSocketHQ");
newTweet.setMeta("uuid-1");
Backend
Post payload for PHP and other server-side languages.
$post_fields = [
"key" => "*******",
"secret" => "**********",
"roomId" => 1,
"message" => ["event"=>"new_message", "data" => "Hello world!"]
];
System Events
System Events are the inbuilt events fired by the PieSocket SDKs.
The following is a complete list of all system event names.
| Event | Fired When | Required configuration |
|---|---|---|
| system:connected | Channel connection is ready to send/receive messages. | None |
| system:member_joined | A user has joined | presence=1 |
| system:member_left | A user leaves the room | presence=1 |
| system:message | Any kind of message arrives on the WebSocket connection. | None |
| system:error | An error occurs | None |
| system:closed | The WebSocket connection closes | None |
| * | All events | None |
On this page
