-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsample.php
46 lines (39 loc) · 1.31 KB
/
sample.php
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
45
46
<?php
error_reporting(E_ALL);
session_start();
require('./ortc.php');
/* -------------------- */
/* REPLACE THESE VALUES */
/* -------------------- */
$URL = 'http://ortc-developers.realtime.co/server/2.1';
$AK = 'YOUR_APPLICATION_KEY';// your realtime.co application key
$PK = 'YOUR_APPLICATION_PRIVATE_KEY';// your realtime.co private key
$TK = 'YOUR_AUTHENTICATION_TOKEN';// token: could be randomly generated in the session
$CH = 'MyChannel'; //channel
$ttl = 180;
$isAuthRequired = false;
$result = false;
/* -------------------- */
/* END */
/* -------------------- */
// ORTC auth
// on a live usage we would already have the auth token authorized and stored in a php session
// Since a developer appkey does not require authentication the following code is optional
if( ! array_key_exists('ortc_token', $_SESSION) ){
$_SESSION['ortc_token'] = $TK;
}
$rt = new Realtime( $URL, $AK, $PK, $TK );
if($isAuthRequired){
$result = $rt->auth(
array(
$CH => 'w'
),
$ttl
);//post authentication permissions. w -> write; r -> read
echo 'authentication status '.( $result ? 'success' : 'failed' ).'<br/>';
}
if($result || !$isAuthRequired){
$result = $rt->send($CH, "Sending message from php API", $response);
echo ' send status '.( $result ? 'success' : 'failed' ).'<br/>';
}
?>