Create an account at http://www.beaconpush.com if you don't already have one and find your API key and Secret key (go to your account page).
Put your API key and Secret key on row 6 and 7 in classes/beaconpush.php
Simply include the file beaconpush.php in your site and it should be pretty straight forward from there.
require('classes/beaconpush.php');
$beaconpush = new BeaconPush();
// Add user to the channel "theBestChannel"
$beaconpush >add_channel('theBestChannel');
// Send an event (+data) to all users in the channel "theBestChannel"
$beaconpush >send_to_channel('theBestChannel', 'newMessage', array('message' => 'Hello world!'));
In your html file, include the following line before your closing body tag
<?php print $beaconpush >embed(); ?>
and after that, it should look something like this
<html>
<head>
<title>MyBestSite</title>
</head>
<body>
<h1>Welcome!</h1>
<p>Welcome to my best website!</p>
<?php print $beaconpush >embed(); ?>
</body>
</html>
That's pretty much all you need to get started with BeaconPush-PHP!
I'll add better "example returns" later. For the moment, use print_r() to see exactly the results you get back.
string embed ( [ array $options = array() ] )
-
Returns a string with HTML used for including the file client.js from beaconpush.com. Channels and options are returned by this also.
-
Options
-
See beaconpush.com for info on what the options do. Look under JavaScript API -> options
-
Available options is: bool log and string user
$beaconpush->add_channel('theBestChannel');
$beaconpush->embed(array('log' => TRUE, 'user' => 'myCustomIdForUser'));
<script type="text/javascript" src="http://beaconpush.com/1/client.js"></script>
<script type="text/javascript">
Beacon.connect("5a30a673", ['theBestChannel'], {log: true, user: 'myCustomIdForUser'});
</script>
$beaconpush->add_channel('theBestChannel');
$beaconpush->embed();
<script type="text/javascript" src="http://beaconpush.com/1/client.js"></script>
<script type="text/javascript">
Beacon.connect("5a30a673", ['theBestChannel']);
</script>
void add_channel ( string $channel )
- Add the connected user to a channel.
$beaconpush->add_channel('theBestChannel');
void add_channels ( array $channels )
- Add the connected user to multiple channels.
$beaconpush->add_channels( array('theBestChannel', 'foo') );
array send_to_channel ( string $channel, string $event [, array $data = array() ] )
- Sends an event to all users in a channel. The data sent can then be used on the client-side (JavaScript) to do something usefull (like displaying a message).
$beaconpush->send_to_channel('theBestChannel', 'newMessage', array('message' => 'Hello everyone!'));
- We get back an array with data that Beaconpush.com returned
array send_to_channels ( array $channels, string $event [, array $data = array() ] )
- Send an event to all users in multiple channels. Does the exact some thing as
send_to_channel
but sends the event to multiple channels instead of one.
$beaconpush->send_to_channels(array('theBestChannel', 'foo'), 'newMessage', array('message' => 'Hello everyone!'));
- We get back an array containing arrays for each channel we sent the event to with data that Beaconpush.com returned (for each channel)
array send_to_user ( string $user, string $event [, array $data = array() ] )
- Sends an event to a user. The data sent can then be used on the client-side (JavaScript) to do something usefull (like displaying a message).
$beaconpush->send_to_user('theBestUser', 'newMessage', array('message' => 'Hello everyone!'));
- We get back an array with data that Beaconpush.com returned.
array send_to_users ( array $users, string $event [, array $data = array() ] )
- Send an event to multiple users. Does the exact some thing as
send_to_user
but sends the event to multiple users instead of one.
$beaconpush->send_to_users(array('theBestUser', 'bar'), 'newMessage', array('message' => 'Hello everyone!'));
- We get back an array containing arrays for each channel we sent the event to with data that Beaconpush.com returned (for each channel)
bool send_to_users ( string $user )
- Checks if a user is online and connected to Beaconpush.
$beaconpush->is_user_online('theBestUser');
- Returns TRUE if the user is online, else FALSE
array get_users_in_channel ( string $channel )
- Get an array of users currently in a channel.
$beaconpush->get_users_in_channel('foo');
- Returns an array of users.
array get_users_in_channels ( array $channels )
- Get an array of all users found in multiple channels.
$beaconpush->get_users_in_channels(array('theBestChannel', 'foo'));
- Returns an array of users.
string count_users_online ( )
- Get the number of users online (in all channels).
$beaconpush->count_users_online();
- Returns the number of users online
array force_user_logout ( string $user )
- Forces the logout of a user
$beaconpush->force_user_logout('theWorstUser');
- WARNING: The return value for this function is not fully done. Currently it returns the response body Beaconpush gave us, but Beaconpush doesn't give us a response body for force_user_logout, only a result code. You can still use this function.