-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
skoniks
authored and
skoniks
committed
Nov 2, 2018
1 parent
62a5034
commit 6b577ce
Showing
13 changed files
with
130 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
return [ | ||
'redis' => [ | ||
'enable' => false, // Use REDIS for redis-available methods (by default uses http) | ||
'driver' => 'centrifugo' // REDIS channel name from Centrifugo config ($driver.".api") | ||
'connection' => 'centrifugo' // Name of REDIS connection in "config/database.php" | ||
], | ||
'url_api' => env('C_URL_API', 'http://localhost:8000/api/'), // HTTP API url for Centrifugo | ||
'secret' => env('C_SECRET', null), // SUPER SECRET API KEY | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,67 @@ | ||
<?php | ||
namespace SKONIKS\Centrifugo; | ||
use SKONIKS\Centrifugo\Transport\RedisClient; | ||
use SKONIKS\Centrifugo\Transport\HttpClient; | ||
|
||
use GuzzleHttp\Client; | ||
use Illuminate\Support\Facades\Redis; | ||
use SKONIKS\Centrifugo\Transport\CHttp; | ||
use SKONIKS\Centrifugo\Transport\CRedis; | ||
|
||
class Centrifugo | ||
{ | ||
protected $rmethods = ['publish', 'broadcast', 'unsubscribe', 'disconnect']; | ||
public function publish($channel, $data) | ||
{ | ||
class Centrifugo { | ||
protected $redis_methods = [ | ||
'publish', 'broadcast', 'unsubscribe', 'disconnect' | ||
]; | ||
public function publish($channel, $data){ | ||
return $this->send('publish', [ | ||
'channel' => $channel, | ||
'data' => $data, | ||
]); | ||
} | ||
public function unsubscribe($channel, $user) | ||
{ | ||
public function broadcast((array)$channels, $data){ | ||
return $this->send('broadcast', [ | ||
'channels' => $channels, | ||
'data' => $data, | ||
]); | ||
} | ||
public function unsubscribe($channel, $user){ | ||
return $this->send('unsubscribe', [ | ||
'channel' => $channel, | ||
'user' => $user, | ||
]); | ||
} | ||
public function disconnect($user) | ||
{ | ||
public function disconnect($user){ | ||
return $this->send('disconnect', [ | ||
'user' => $user, | ||
]); | ||
} | ||
public function presence($channel) | ||
{ | ||
public function presence($channel){ | ||
return $this->send('presence', [ | ||
'channel' => $channel, | ||
]); | ||
} | ||
public function history($channel) | ||
{ | ||
public function history($channel){ | ||
return $this->send('history', [ | ||
'channel' => $channel, | ||
]); | ||
} | ||
public function generateToken($userId, $timestamp, $info = '') | ||
{ | ||
public function channels(){ | ||
return $this->send('channels', []); | ||
} | ||
public function stats(){ | ||
return $this->send('stats', []); | ||
} | ||
public function node(){ | ||
return $this->send('node', []); | ||
} | ||
protected function transport($method){ | ||
if(config('centrifugo.redis.enable') && in_array($method, $this->redis_methods)) | ||
return new RedisClient(); | ||
return new HttpClient(); | ||
} | ||
protected function send($method, $params){ | ||
return $this->transport($method)->send($method, $params); | ||
} | ||
public static function token($user_id, $timestamp, $info = ''){ | ||
$ctx = hash_init('sha256', HASH_HMAC, config('centrifugo.secret')); | ||
hash_update($ctx, $userId); | ||
hash_update($ctx, $user_id); | ||
hash_update($ctx, $timestamp); | ||
hash_update($ctx, $info); | ||
return hash_final($ctx); | ||
} | ||
protected function getTransport($method){ | ||
if(config('centrifugo.transport') == 'redis' && in_array($method, $this->rmethods)) { | ||
$client = Redis::connection(config('centrifugo.redisConnection'))->client(); | ||
return new CRedis($client, config('centrifugo.driver')); | ||
} else { | ||
$client = new Client(['base_uri' => config('centrifugo.baseUrl')]); | ||
return new CHttp($client); | ||
} | ||
} | ||
protected function send($method, $params){ | ||
$transport = $this->getTransport($method); | ||
$response = $transport->send($method, $params); | ||
return $response; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.