Skip to content

Instantly share code, notes, and snippets.

@bayareawebpro
Created September 18, 2019 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bayareawebpro/82b856f188e349887746d076777d6518 to your computer and use it in GitHub Desktop.
Save bayareawebpro/82b856f188e349887746d076777d6518 to your computer and use it in GitHub Desktop.
<?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