-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathlive_backend.php
31 lines (28 loc) · 976 Bytes
/
live_backend.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
<?php
$server = new swoole_websocket_server("0.0.0.0", 12450);
$server->on('open', function (swoole_websocket_server $server, $request) {
//print_r($request);
echo "Request Room ID:" . $request->server['path_info'] . PHP_EOL;
if ($request->server['path_info'] !== '/push') {
if ($request->server['path_info'] !== '/play') {
$server->push($request->fd, json_encode(['status' => 404, 'message' => 'Live Stream Not Found']));
$server->close($request->fd);
} else {
echo "server: handshake success with fd{$request->fd}\n";
}
}
});
$server->on('message', function (swoole_websocket_server $server, $frame) {
echo "receive from {$frame->fd}" . PHP_EOL;
$data = $frame->data;
foreach ($server->connections as $fd) {
$server->push($fd, $data);
}
//$json = json_decode($data, true);
// if ($json['type'] == 'owner' || $json['type'] == 'danmaku') {
// }
});
$server->on('close', function ($ser, $fd) {
echo "client {$fd} closed\n";
});
$server->start();