-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpusher.php
More file actions
44 lines (36 loc) · 1.22 KB
/
Copy pathpusher.php
File metadata and controls
44 lines (36 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require 'vendor/autoload.php';
require_once('config.php'); // config for pusher credential
class PusherClass {
private $pusher;
private $username;
private $sessionid;
// function constructor
public function __construct() {
$options = array(
'cluster' => $GLOBALS['app_cluster'],
'useTLS' => true
);
$this->pusher = new Pusher\Pusher(
$GLOBALS['app_key'],
$GLOBALS['app_secret'],
$GLOBALS['app_id'],
$options
);
$this->username = $_SESSION['username'];
$this->sessionid = session_id();
$data['message'] = $this->username . " has entered the room.";
$data['user_id'] = session_id();
$this->pusher->trigger('presence-my-channel', 'my-event', $data);
}
function auth() {
if (isset($_POST['socket_id'])) {
die($this->pusher->presenceAuth("presence-my-channel", $_POST['socket_id'], $this->sessionid, array('username' => $this->username)));
}
}
function trigger() {
$data['message'] = $_POST['message'];
$data['user_id'] = session_id();
$this->pusher->trigger('presence-my-channel', 'my-event', $data);
}
}