Created
September 18, 2019 23:56
-
-
Save bayareawebpro/82b856f188e349887746d076777d6518 to your computer and use it in GitHub Desktop.
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
<?php namespace App; | |
use Pusher\Pusher; | |
/** | |
* The Pusher Api Class | |
* (not implemented yet) | |
*/ | |
class PusherApi | |
{ | |
protected $pusher; | |
/** | |
* PusherApi constructor. | |
*/ | |
public function __construct(){ | |
$this->pusher = new Pusher( | |
config()->get('broadcasting.connections.pusher.key'), | |
config()->get('broadcasting.connections.pusher.secret'), | |
config()->get('broadcasting.connections.pusher.app_id'), | |
array( | |
'cluster' => config()->get('broadcasting.connections.pusher.options.cluster'), | |
'encrypted' => config()->get('broadcasting.connections.pusher.options.encrypted'), | |
) | |
); | |
} | |
/** | |
* Get a user's online status. | |
* @param $channel string | |
* @param $user_id int | |
* @return boolean | |
* @throws \Exception | |
*/ | |
public function isOnline($channel = 'default', $user_id = 0){ | |
$response = $this->pusher->get('/channels/'.$channel.'/users'); | |
if( | |
$response['status'] === 200 && | |
$response['result'] && | |
$response['result']['users'] | |
){ | |
return (bool) collect($response['result']['users'])->where('id', $user_id)->count(); | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment