forked from Fenrirthviti/stream-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
340 lines (314 loc) · 11.3 KB
/
index.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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<?php
// includes site vars
include 'inc/config.php';
// enable if error reporting is on
if ($debug === true) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
}
// class includes
spl_autoload_register(function ($class) {
if ($class !== 'index') {
if ($class !== 'index' && file_exists('api/' . strtolower($class) . '.php')) {
include 'api/' . strtolower($class) . '.php';
} elseif (file_exists('lib/' . strtolower($class) . '.class.php')) {
include 'lib/' . strtolower($class) . '.class.php';
}
}
});
// verify we're logged in
require 'inc/auth.php';
// Load RTMP channels informations
$rtmpclass = new rtmp();
$rtmpinfo = $rtmpclass->checkStreams();
// grab account info
$email = filter_var($_SESSION['authenticated'], FILTER_VALIDATE_EMAIL);
$accountinfo = $user->info($email);
// functions to convert raw bytes/bits to something more readable for stream info
/**
* @param $bites
* @param int $decimals
* @return string
*/
function bitsConvert($bites, $decimals = 2)
{
$sz = 'BKMGTP';
$factor = floor((strlen($bites) - 1) / 3);
return sprintf("%.{$decimals}f", $bites / pow(1000, $factor)) . @$sz[$factor];
}
/**
* @param $bytes
* @param int $decimals
* @return string
*/
function bytesConvert($bytes, $decimals = 2)
{
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
// Check if we're trying to watch a video or stream
// Get Request URI and break into components
$request = trim(filter_input(INPUT_SERVER, 'REQUEST_URI'), '/');
$uriVars = explode('/', $request, 4);
// Set current page and then
// check if we're trying to
// watch a video or stream
$page = $uriVars[0];
if ($page === 'watch') {
$streamkey = $uriVars[1];
$subemail = $user->updateStreamkey($streamkey, 'email');
// Set up data for checking subscription status
$sub = new subscription($accountinfo['api_key'], $streamkey);
$list = $sub->_list();
$subarray = json_decode($list);
if (in_array($subemail, $subarray->subscribed)) {
$substatus = 'Unsubscribe';
$subcolor = 'style="background-color: rgb(0, 188, 212)"';
} else {
$substatus = 'Subscribe';
$subcolor = '';
}
}
if ($page === 'video') {
$video = $uriVars[1];
}
if ($page === 'download') {
$download = filter_var($uriVars[1], FILTER_SANITIZE_STRING);
$file = "/var/tmp/rec/" . $download;
if (file_exists($file)) {
$size = filesize("./" . basename($file));
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $size);
header("Content-Disposition: attachment; filename=\"" . basename($file) . "\"");
header("Expires: 0");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
readfile($file);
exit();
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title><?= $sitetitle ?> Site<?php if (!empty($streamkey)) {
echo ' - Watching ' . $user->updateStreamkey($streamkey, 'channel');
} ?>
</title>
<link href="/img/favicon.ico" rel="shortcut icon" type="image/x-icon"/>
<link href='https://fonts.googleapis.com/css?family=Roboto:400,500,300,100,700,900' rel='stylesheet'
type='text/css'>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="/js/vjs/6.2.6/video-js.min.css">
<link rel="stylesheet" type="text/css" href="/js/vjs/video-js-skin.css">
<link rel="stylesheet" href="/css/application.css">
<link rel="stylesheet" href="/css/site.css">
<link rel="stylesheet" href="/js/jqui/jquery-ui.min.css">
<link rel="stylesheet" href="/js/sb/jquery.mCustomScrollbar.css">
<script src="/js/jquery.min.js"></script>
<script src="/js/jqui/jquery-ui.min.js"></script>
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer mdl-layout--fixed-header"><!-- START LAYOUT WRAP -->
<!-- START NAV HEADER -->
<header class="mdl-layout__header">
<div class="mdl-layout__header-row">
<div class="mdl-layout-spacer"></div>
<?php if (!empty($streamkey)) { ?>
<a class="mdl-navigation__link force_link" onclick="popoutPlayer()">
<i class="material-icons" role="presentation">video_label</i>
Switch to Popout Player
</a>
<a class="mdl-navigation__link" id="toggleChat" href="#">
<i class="material-icons" role="presentation">chat</i>
Show/Hide Chat
</a>
<a class="mdl-navigation__link force_link" onclick="resetPlayer()">
<i class="material-icons" role="presentation">video_label</i>
Reset Player
</a>
<?php } ?>
<div class="avatar-dropdown" id="icon">
<span><?= $accountinfo['display_name'] ?></span>
<img src="<?= $accountinfo['profile_img'] ?>">
</div>
<ul class="mdl-menu mdl-list mdl-menu--bottom-right mdl-js-menu mdl-shadow--2dp account-dropdown"
for="icon">
<li class="mdl-list__item mdl-list__item--two-line">
<span class="mdl-list__item-primary-content">
<img class="material-icons mdl-list__item-avatar"
src="<?= $accountinfo['profile_img'] ?>">
<span><?= $accountinfo['display_name'] ?></span>
<span class="mdl-list__item-sub-title"><?= $accountinfo['email'] ?></span>
</span>
</li>
<li class="list__item--border-top"></li>
<a href="#" class="mdl-menu__item mdl-list__item copyButton" id="copyButton"
title="Copy to clipboard"
data-clipboard-text="<?= $accountinfo['display_name'] ?>?key=<?= $accountinfo['stream_key']; ?>">
<span class="mdl-list__item-primary-content">
<i class="material-icons mdl-list__item-icon">vpn_key</i>
<span>Stream Key</span>
<i class="material-icons md-16 copyIcon">content_copy</i>
</a>
<li class="list__item--border-top"></li>
<a href="/settings" class="mdl-menu__item mdl-list__item">
<span class="mdl-list__item-primary-content">
<i class="material-icons mdl-list__item-icon">settings</i>
Settings
</span>
</a>
<a href="?action=logout" class="mdl-menu__item mdl-list__item">
<span class="mdl-list__item-primary-content">
<i class="material-icons mdl-list__item-icon text-color--secondary">exit_to_app</i>
Log out
</span>
</a>
</ul>
</div>
</header>
<!-- END NAV HEADER -->
<!-- START NAV DRAWER -->
<div class="mdl-layout__drawer">
<header class="dm-logo-header"><?= $sitetitle ?></header>
<nav class="mdl-navigation">
<a class="mdl-navigation__link<?php
if ($page === 'channels' || (empty($page) && empty($streamkey))) {
echo ' mdl-navigation__link--current';
}
?>" href="/channels">
<i class="material-icons" role="presentation">videogame_asset</i>
Live channels
</a>
<a class="mdl-navigation__link<?php
if ($page === 'videos') {
echo ' mdl-navigation__link--current';
}
?>" href="/videos">
<i class="material-icons" role="presentation">video_library</i>
Videos
</a>
<a class="mdl-navigation__link<?php
if ($page === 'chat') {
echo ' mdl-navigation__link--current';
}
?>" href="/chat">
<i class="material-icons" role="presentation">chat</i>
Global Chat
</a>
<?php if (!empty($streamkey)) { ?>
<a class="mdl-navigation__link mdl-navigation__link--current mdl-typography--text-nowrap-ellipsis"
href="/watch/<?= $streamkey; ?>">
<i class="material-icons" role="presentation">visibility</i>
Watching: <?php echo $user->updateStreamkey($streamkey, 'channel'); ?>
</a>
<button id="subButton" class="mdl-button mdl-js-button mdl-button--raised" channel="<?= $streamkey; ?>"
type="button" <?= $subcolor ?>><?= $substatus ?></button>
<div id="subToast" class="mdl-js-snackbar mdl-snackbar">
<div class="mdl-snackbar__text"></div>
<button class="mdl-snackbar__action" type="button"></button>
</div>
<?php } else { ?>
<a class="mdl-navigation__link" href="/">
<i class="material-icons" role="presentation">visibility</i>
Watching: N/A
</a>
<?php } ?>
<div class="mdl-layout-spacer"></div>
<a class="mdl-navigation__link" target="_blank" href="https://github.com/Fenrirthviti/">
<i class="material-icons" role="presentation">link</i>
GitHub
</a>
</nav>
</div>
<!-- END NAV DRAWER-->
<!-- START CONTENT PAGE -->
<main class="mdl-layout__content" id="mainContent">
<?php
// Load the appropriate page, but only if it exists
// and checking first if trying to watch a stream or play a video
if (!empty($streamkey)) {
include 'inc/index/streamplayer.php';
} elseif (!empty($video)) {
include 'inc/index/videoplayer.php';
} elseif (file_exists('inc/index/' . $page . '.php') === true) {
include 'inc/index/' . $page . '.php';
} elseif (empty($page) || ($page === 'index.php')) {
include 'inc/index/channels.php';
} else {
include 'inc/404.php';
}
?>
<div id="keyCopy" class="mdl-js-snackbar mdl-snackbar keyCopy-toast">
<div class="mdl-snackbar__text keyCopy-text"></div>
<button class="mdl-snackbar__action keyCopy-action" type="button"></button>
</div>
</main>
<!-- END CONTENT PAGE-->
</div> <!-- END LAYOUT WRAP -->
<!-- START FOOTER -->
<script src="/js/date.format.min.js"></script>
<script src="/js/material.js"></script>
<script src="/js/getmdl-select.min.js"></script>
<script src="/js/sb/jquery.mCustomScrollbar.concat.min.js"></script>
<script src="/js/vjs/6.2.6/video.min.js"></script>
<script src="/js/vjs/6.2.6/videojs-flash.min.js"></script>
<script src="/js/vjs/videojs-persistvolume.js"></script>
<script src="/js/vjs/videojs-contrib-hls.min.js"></script>
<script src="/js/clipboard.min.js"></script>
<script src="/js/rachni.js"></script>
<script type='text/javascript'>
new Clipboard('.copyButton');
var api_key = "<?= $accountinfo['api_key'] ?>";
var display_name = "<?= $accountinfo['display_name'] ?>";
var jp_status = "<?= $accountinfo['chat_jp_setting'] ?>";
<?php if (!empty($streamkey)) { ?>
var live_status = true;
var stream_key = "<?= $streamkey; ?>";
var current_channel = '<?= $streamkey; ?>';
var videoposter = '<?php echo $user->updateStreamkey($streamkey, 'offline_image') ?>';
var streamPlayer = videojs('streamPlayer', {
techOrder: ['flash'],
sources: [{
src: 'rtmp://<?= $surl ?>/live&<?= $streamkey ?>',
type: 'rtmp/flv',
label: 'Flash'
}],
});
streamPlayer.persistvolume({namespace: "Rachni-Volume-Control-" + stream_key});
streamPlayer.on('fullscreenchange', function () {
setTimeout(function () {
$('#output').mCustomScrollbar('scrollTo', 'bottom');
}, 200);
});
this.popoutPlayer = function () {
streamPlayer.pause();
window.open("<?= $furl ?>/popout/<?= $streamkey ?>", "_blank", "menubar=0,scrollbars=0,status=0,titlebar=0,toolbar=0,top=200,left=200,resizable=yes,width=1280,height=784");
};
this.resetPlayer = function () {
streamPlayer.reset();
streamPlayer.src({type: 'rtmp/flv', src: 'rtmp://<?= $surl ?>/live&<?= $streamkey ?>'});
streamPlayer.persistvolume({namespace: "Rachni-Volume-Control-" + stream_key});
$('.vjs-poster').hide();
live_status = true;
};
<?php } elseif (!empty($video)) { ?>
var videoPlayer = videojs('videoPlayer', {
techOrder: ['html5'],
sources: [{
src: '//<?= $surl ?>/rec/<?= $video ?>',
type: 'video/mp4',
}],
});
videoPlayer.persistvolume({namespace: "Rachni-Volume-Control-<?= $video ?>"});
<?php } else { ?>
var current_channel = 'GlobalChatChannel';
<?php } ?>
</script>
</body>
</html>
<!-- END FOOTER -->