summaryrefslogtreecommitdiff
path: root/src/Message.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Message.php')
-rw-r--r--src/Message.php13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/Message.php b/src/Message.php
index 647afad..92c6005 100644
--- a/src/Message.php
+++ b/src/Message.php
@@ -7,6 +7,8 @@ abstract class Message {
const REQUEST = 0;
const RESPONSE = 1;
+ const PING = 2;
+ const PONG = 3;
protected $type;
@@ -27,10 +29,13 @@ abstract class Message {
* @return string
*/
public function serialize(): string {
- return json_encode([
- $this->type,
- $this->getContent()
- ]);
+ $data = [$this->type];
+ $content = $this->getContent();
+
+ if (!empty($content))
+ $data[] = $content;
+
+ return json_encode($data);
}
} \ No newline at end of file