Skip to content

Commit

Permalink
i36: Updates package to work with socket.io v4
Browse files Browse the repository at this point in the history
- Replaces checked in mspack_pack.php with rybakit/msgpack composer
  package
- Adds UID to packed message
- Removes "#emitter" suffix on key

fixes rase-#36
  • Loading branch information
Rob Gonnella committed Aug 18, 2022
1 parent 6756a34 commit 82be06d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 125 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
},
"require": {
"php": ">=5.3",
"ptrofimov/tinyredisclient": "1.1.1"
"ptrofimov/tinyredisclient": "1.1.1",
"rybakit/msgpack": "0.9.1"
},
"autoload": {
"psr-4": {
Expand Down
22 changes: 11 additions & 11 deletions src/Emitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
define('EVENT', 2);
define('BINARY_EVENT', 5);

if (!function_exists('msgpack_pack')) {
require(__DIR__ . '/msgpack_pack.php');
}

class Emitter {
const UID = "4N8LaD";

public function __construct($redis = FALSE, $opts = array()) {
if (is_array($redis)) {
$opts = $redis;
Expand Down Expand Up @@ -41,10 +39,11 @@ public function __construct($redis = FALSE, $opts = array()) {
}

$this->redis = $redis;
$this->key = (isset($opts['key']) ? $opts['key'] : 'socket.io') . '#emitter';
$this->key = (isset($opts['key']) ? $opts['key'] : 'socket.io');

$this->_rooms = array();
$this->_flags = array();
$this->_packer = new \MessagePack\Packer();
}

/*
Expand Down Expand Up @@ -117,10 +116,13 @@ public function emit() {
}

// publish
$packed = msgpack_pack(array($packet, array(
'rooms' => $this->_rooms,
'flags' => $this->_flags
)));
$opts = array(
'rooms' => $this->_rooms,
'flags' => $this->_flags,
'except' => array(),
);

$packed = $this->_packer->pack(array(self::UID, $packet, $opts));

// hack buffer extensions for msgpack with binary
if ($packet['type'] == BINARY_EVENT) {
Expand All @@ -137,5 +139,3 @@ public function emit() {
return $this;
}
}


113 changes: 0 additions & 113 deletions src/msgpack_pack.php

This file was deleted.

0 comments on commit 82be06d

Please sign in to comment.