Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Migrate to Ratchet Pawl instead of Textalk websocket client.
Browse files Browse the repository at this point in the history
  • Loading branch information
hperrin committed May 6, 2019
1 parent aa23cd9 commit 7d5a592
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 47 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"sciactive/hookphp": "^2.0",
"cboden/ratchet": "0.4.*",
"zendframework/zend-log": "2.*",
"textalk/websocket": "1.2.*"
"ratchet/pawl": "^0.3.4"
},
"require-dev": {
"squizlabs/php_codesniffer": "3.*"
Expand Down
90 changes: 50 additions & 40 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/HookMethods.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php namespace Nymph\PubSub;

use SciActive\Hook;
use WebSocket\Client as TextalkWebSocketClient;

class HookMethods {
public static function setup() {
Expand Down Expand Up @@ -181,8 +180,12 @@ function (&$return, $name, &$object, &$function, &$data) {

public static function sendMessage($message) {
foreach (Server::$config['entries'] as $host) {
$client = new TextalkWebSocketClient($host);
$client->send($message);
\Ratchet\Client\connect($host)->then(function($conn) use ($message) {
$conn->send($message);
$conn->close();
}, function ($e) {
error_log("Could not connect to PubSub: {$e->getMessage()}");
});
}
}
}
9 changes: 6 additions & 3 deletions src/MessageHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
use WebSocket\Client as TextalkWebSocketClient;

/**
* Handle subscriptions and publications.
Expand Down Expand Up @@ -634,8 +633,12 @@ private function relay($message) {
}

foreach (Server::$config['relays'] as $host) {
$client = new TextalkWebSocketClient($host);
$client->send($message);
\Ratchet\Client\connect($host)->then(function($conn) use ($message) {
$conn->send($message);
$conn->close();
}, function ($e) {
$this->logger->error("Could not connect to PubSub relay: {$e->getMessage()}");
});
}
}

Expand Down

0 comments on commit 7d5a592

Please sign in to comment.