-
Notifications
You must be signed in to change notification settings - Fork 19
/
app-functions.php
299 lines (215 loc) · 9.33 KB
/
app-functions.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<?php
//app functions needed by app calls, depend on integration
//For more advanced implementations see WordPress plugin and its php source code:
//https://wordpress.org/plugins/ppv-live-webcams/
//https://plugins.svn.wordpress.org/ppv-live-webcams/trunk/inc/h5videochat.php
//demo setup saves variables in plain files in uploads folder: integration should use framework database
function varSave($path, $var)
{
if (!file_exists('uploads')) mkdir('uploads');
file_put_contents('uploads/' . $path, serialize($var));
}
function varLoad($path)
{
if (!file_exists('uploads/' . $path)) return false;
return unserialize(file_get_contents('uploads/' . $path));
}
function arrayLoad($path)
{
$res = varLoad($path);
if (is_array($res)) return $res;
else return array();
}
// app parameter functions
function __( $text, $domain = 'default' )
{
return $text;
}
function path2url($file)
{
$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
return dirname($url) . '/' . str_replace( dirname(__FILE__) , '', $file);
}
function appFail($message = 'Request Failed', $response = null)
{
//bad request: fail
if (!$response) $response = array();
$response['error'] = $message;
$response['VideoWhisper'] = 'https://videowhisper.com';
echo json_encode($response);
die();
}
function appSfx()
{
//sound effects sources
$base = VW_H5V_URL. 'sounds/';
return array(
'message' => $base . 'message.mp3',
'hello' => $base . 'hello.mp3',
'leave' => $base . 'leave.mp3',
'call' => $base . 'call.mp3',
'warning' => $base . 'warning.mp3',
'error' => $base . 'error.mp3',
'buzz' => $base . 'buzz.mp3',
);
}
function appText()
{
//implement translations
//returns texts
return array(
'Send' => __('Send', 'ppv-live-webcams'),
'Type your message' => __('Type your message', 'ppv-live-webcams'),
'Chat' => __('Chat', 'ppv-live-webcams'),
'Camera' => __('Camera', 'ppv-live-webcams'),
'Users' => __('Users', 'ppv-live-webcams'),
'Options' => __('Options', 'ppv-live-webcams'),
'Files' => __('Files', 'ppv-live-webcams'),
'Presentation' => __('Presentation', 'ppv-live-webcams'),
'Tap for Sound' => __('Tap for Sound', 'ppv-live-webcams'),
'Enable Audio' => __('Enable Audio', 'ppv-live-webcams'),
'Mute' => __('Mute', 'ppv-live-webcams'),
'Reload' => __('Reload', 'ppv-live-webcams'),
'Broadcast' => __('Broadcast', 'ppv-live-webcams'),
'Stop Broadcast' => __('Stop Broadcast', 'ppv-live-webcams'),
'Make a selection to start!' => __('Make a selection to start!', 'ppv-live-webcams'),
'Lights On' => __('Lights On', 'ppv-live-webcams'),
'Dark Mode' => __('Dark Mode', 'ppv-live-webcams'),
'Enter Fullscreen' => __('Enter Fullscreen', 'ppv-live-webcams'),
'Exit Fullscreen' => __('Exit Fullscreen', 'ppv-live-webcams'),
'Site Menu' => __('Site Menu', 'ppv-live-webcams'),
'Request Private' => __('Request Private', 'ppv-live-webcams'),
'Request Private 2 Way Videochat Show' => __('Request Private 2 Way Videochat Show', 'ppv-live-webcams'),
'Performer Disabled Private Requests' => __('Performer Disabled Private Requests', 'ppv-live-webcams'),
'Performer is Busy in Private' => __('Performer is Busy in Private', 'ppv-live-webcams'),
'Performer is Not Online' => __('Performer is Not Online', 'ppv-live-webcams'),
'Nevermind' => __('Nevermind', 'ppv-live-webcams'),
'Accept' => __('Accept', 'ppv-live-webcams'),
'Decline' => __('Decline', 'ppv-live-webcams'),
'Close Private' => __('Close Private', 'ppv-live-webcams'),
'Next' => __('Next', 'ppv-live-webcams'),
'Next: Random Videochat Room' => __('Next: Random Videochat Room', 'ppv-live-webcams'),
'Name' => __('Name', 'ppv-live-webcams'),
'Size' => __('Size', 'ppv-live-webcams'),
'Age' => __('Age', 'ppv-live-webcams'),
'Upload: Drag and drop files here, or click to select files' => __('Upload: Drag and drop files here, or click to select files', 'ppv-live-webcams'),
'Uploading. Please wait...' => __('Uploading. Please wait...', 'ppv-live-webcams'),
'Open' => __('Open', 'ppv-live-webcams'),
'Delete' => __('Delete', 'ppv-live-webcams'),
'Media Displayed' => __('Media Displayed', 'ppv-live-webcams'),
'Remove' => __('Remove', 'ppv-live-webcams'),
'Default' => __('Default', 'ppv-live-webcams'),
'Empty' => __('Empty', 'ppv-live-webcams'),
'Profile' => __('Profile', 'ppv-live-webcams'),
'Show' => __('Show', 'ppv-live-webcams'),
'Private Call' => __('Private Call', 'ppv-live-webcams'),
'Exit' => __('Exit', 'ppv-live-webcams'),
'External Broadcast' => __('External Broadcast', 'ppv-live-webcams'),
'Broadcast with external apps for advanced compositions, scenes, effects or reliability compared to web based interface and protocols. External broadcasts have higher latency and improved capacity, reliability specific to HLS delivery method. New broadcasts show in about 10 seconds and unavailability updates after 1 minute.' => __('Broadcast with external apps for advanced compositions, scenes, effects or reliability compared to web based interface and protocols. External broadcasts have higher latency and improved capacity, reliability specific to HLS delivery method. New broadcasts show in about 10 seconds and unavailability updates after 1 minute.', 'ppv-live-webcams'),
);
}
function appRoomUsers($roomID, $options)
{
$sessions = arrayLoad($roomID . '_sessions');
foreach ($sessions as $key => $session)
{
if (!is_array($userMeta = unserialize($session['meta'] ?? ''))) $userMeta = array();
$item = [];
$item['userID'] = intval($session['uid']);
$item['userName'] = $session['username'] ?? '';
if (!$item['userName']) $item['userName'] = '#' . $session['uid'];
$item['sdate'] = intval($session['sdate']);
$item['meta'] = $userMeta;
$item['updated'] = intval($session['edate']);
$item['avatar'] = VW_H5V_URL .'images/avatar.png';
$item['url'] = 'https://videowhisper.com/tickets_submit.php';
$items[intval($session['uid'])] = $item;
}
return $items;
}
function appTipOptions($options)
{
$tipOptions = stripslashes($options['tipOptions']);
if ($tipOptions)
{
$p = xml_parser_create();
xml_parse_into_struct($p, trim($tipOptions), $vals, $index);
$error = xml_get_error_code($p);
xml_parser_free($p);
if (is_array($vals)) return $vals;
}
return array();
}
function appStreamName($userID, $roomID, $options)
{
return 'stream' . $userID;
}
function appStream($userID, $roomID, $options)
{
$key = $options['webKey'] . $roomID; //a secret key to implement stream verification
return 'stream' . $userID . '?channel_id=' . $roomID . '&userID=' . urlencode($userID) . '&key=' . urlencode($key) . '&ip=' . urlencode($_SERVER['REMOTE_ADDR']) . '&transcoding=0&room=Room' . $roomID. '&privateUID=0';
}
function appPublicRoom($roomID, $userID, $options, $welcome ='')
{
//public room parameters, specific for this user
//depends on integration
$room = array();
$room['ID'] = $roomID;
$room['name'] = 'Room' . $roomID;
$room['performer'] = 'Caller' . (10000+$roomID);
$room['performerID'] = (10000+$roomID);
$collaboration = $options['collaboration'];
if (VW_DEVMODE && VW_DEVMODE_COLLABORATION) $collaboration = true;
$isPerformer = ($userID == (10000+$roomID));
$clientID = $roomID;
// $privateUID = the other user ID
if ($isPerformer) $privateUID = $clientID;
else $privateUID = $room['performerID'];
$room['privateUID'] = $privateUID;
//screen
$room['screen'] = 'Way2Screen';
$room['streamBroadcast'] = appStream($userID, $roomID, $options);
$room['streamBroadcastName'] = appStreamName($userID, $roomID, $options);
$room['streamUID'] = intval($privateUID);
$room['streamPlayback'] = appStream($privateUID, $roomID, $options);
$room['streamPlaybackName'] = appStreamName($privateUID, $roomID, $options);
//$room['actionPrivate'] = !$isPerformer;
$room['actionPrivateClose'] = false;
$room['privateUID'] = 0;
$room['actionID'] = 0;
$room['welcome'] = ' 👥 ' . sprintf('Welcome to private booth "%s", user #%s!', $room['name'] , $userID);
$room['welcomeImage'] = VW_H5V_URL . 'images/chat.png';
if ($isPerformer) //member: performer
{
$room['welcome'] .= "\n". 'You are room owner (caller).';
}
else //member: client
{
$room['welcome'] .= "\n".'You are invited participant (client).';
}
//if ($options['videochatNext']) if (!$isPerformer) $room['next'] = true;
if ($welcome) $room['welcome'] .= "\n" . $welcome;
//configure tipping options for clients
$room['tips'] = false;
if ($options['tips'])
if (!isset($session) || !$session->broadcaster)
{
$tipOptions = appTipOptions($options);
if (count($tipOptions))
{
$room['tipOptions'] = $tipOptions;
$room['tips'] = true;
$room['tipsURL'] = VW_H5V_URL . 'tips/';
}
}
//demo goal
$room['welcome'] .= "\n 🎁 " . 'Current gifts goal' .': '. 'Demo Goal';
$room['welcome'] .= "\n " . 'Chat can display goals that can be achieved with gifts/donations.';
$room['welcomeProgressValue'] = 8;
$room['welcomeProgressTotal'] = 10;
$room['welcomeProgressDetails'] = 'Demo Goal';
//offline snapshot (poster) and video
$room['snapshot'] = VW_H5V_URL . 'images/no-picture.png';
$room['videoOffline'] = VW_H5V_URL . 'videos/hamsterad.mp4';;
return $room;
}