-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathapp-call.php
210 lines (143 loc) · 5.06 KB
/
app-call.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
//app-call.php : called by app to communicate with web server (login, config, status, interactions)
//This is sample code for demostrating some features. Not designed for production.
//Integrate with own platform login and database system.
//For a functional turnkey integration see PaidVideochat.com turnkey site solution and plugin source code https://plugins.svn.wordpress.org/ppv-live-webcams/trunk/inc/h5videochat.php .
include_once 'settings.php';
include_once 'app-functions.php';
//session info received trough VideoWhisper POST var
if ($VideoWhisper = $_POST['VideoWhisper'])
{
$userID = intval($VideoWhisper['userID']);
$sessionID = intval($VideoWhisper['sessionID']);
$roomID = intval($VideoWhisper['roomID']);
$sessionKey = intval($VideoWhisper['sessionKey']);
$privateUID = intval($VideoWhisper['privateUID'] ?? 0);
$roomActionID = intval($VideoWhisper['roomActionID'] ?? 0);
}
$response['VideoWhisper'] = 'https://videowhisper.com';
$task = $_POST['task'];
if ($task != 'login')
{
//verify user login, session validty
}
if ($task == 'login')
{
//user session parameters and info, updates
$response['user'] = [
'ID'=> intval($userID),
'name'=> (($userID>10000)?'Performer':'User') . $userID,
'sessionID'=> intval($sessionID),
'loggedIn' => true,
'balance' => 100,
'avatar' => VW_H5V_URL .'images/avatar.png',
];
//on login check if any private request was active to restore
//return private room/session if active, depending on integration
$response['room'] = appPublicRoom($roomID, $userID, $options, 'Login success!');
//config params, const
$response['config'] = [
'wss' => $options['wsURLWebRTC'] ?? '',
'application' => $options['applicationWebRTC'] ?? '',
'videoCodec' => $options['webrtcVideoCodec'] ?? '',
'videoBitrate' => $options['webrtcVideoBitrate'] ?? 0,
'audioBitrate' => $options['webrtcAudioBitrate'] ?? 0,
'audioCodec' => $options['webrtcAudioCodec'] ?? '',
'autoBroadcast' => false,
'actionFullscreen' => true,
'actionFullpage' => false,
'serverURL' => VW_H5V_CALL,
];
$response['config']['text'] = appText(); //translations
$response['config']['sfx'] = appSfx();
$roomURL = $_SERVER['REQUEST_SCHEME'] .'://'. $_SERVER['HTTP_HOST'] . dirname(explode('?', $_SERVER['REQUEST_URI'], 2)[0]) . '/?r=' . $roomID;
$response['config']['exitURL'] = $roomURL;
//pass app setup config parameters
if (is_array($options['appSetup']))
if (array_key_exists('Config', $options['appSetup']))
if (is_array($options['appSetup']['Config']))
foreach ($options['appSetup']['Config'] as $key => $value)
$response['config'][$key] = $value;
if (VW_DEVMODE)
{
$response['config']['cameraAutoBroadcast'] = '0';
$response['config']['videoAutoPlay '] = '0';
}
if (!isset($isPerformer)) $response['config']['cameraAutoBroadcast'] = '0';
//$response['config']['devMode '] = '1';
$response['config']['loaded'] = true;
}
//end: task==login
//room
$roomName = 'Room' . $roomID;
$userName = (($userID>10000)?'Performer':'User') . $userID;
$ztime = time();
$needUpdate = array();
//process app task (other than login)
switch ($task)
{
case 'login':
break;
case 'tick':
break;
case 'options':
break;
case 'update':
break;
case 'recorder_upload':
if (!$roomName) appFail('No room for recording.');
if (strstr($filename, ".php")) appFail('Bad uploader!');
$mode = $_POST['mode']; // audio/video
$scenario = $_POST['scenario']; // standalone/chat
if (!$privateUID) $privateUID = 0; //public room
//generate same private room folder for both users
if ($privateUID)
{
if ($isPerformer) $proom = $userID . "_" . $privateUID; //performer id first
else $proom = $privateUID ."_". $userID;
}
$destination = 'uploads';
if (!file_exists($destination)) mkdir($destination);
$destination.="/$roomName";
if (!file_exists($destination)) mkdir($destination);
if ($proom)
{
$destination.="/$proom";
if (!file_exists($destination)) mkdir($destination);
}
$response['_FILES'] = $_FILES;
$allowed = array('mp3', 'ogg', 'opus', 'mp4', 'webm');
$uploads = 0;
$filename = '';
if ($_FILES) if (is_array($_FILES))
foreach ($_FILES as $ix => $file)
{
$filename = filter_var( $file['name'], FILTER_SANITIZE_STRING);
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$response['uploadRecLastExt'] = $ext;
$response['uploadRecLastF'] = $filename;
$filepath = $destination . '/' . $filename;
if (in_array($ext, $allowed))
if (file_exists($file['tmp_name']))
{
move_uploaded_file($file['tmp_name'], $filepath);
$response['uploadRecLast'] = $destination . $filename;
$uploads++;
}
}
$response['uploadCount'] = $uploads;
if (!file_exists($filepath))
{
$response['warning'] = 'Recording upload failed!';
}
break;
default:
$response['warning'] = 'Not implemented in this integration: ' . $task;
}
$response['startTime'] = 0;
$response['messages'] = []; //messages list
$response['timestamp'] = $ztime; //update time
$response['lastMessageID'] = 0;
$response['roomUpdate']['users'] = [];
//send response to app
echo json_encode($response);