diff --git a/plugin/Socket/Socket.php b/plugin/Socket/Socket.php index c097267b1..d0871b96e 100644 --- a/plugin/Socket/Socket.php +++ b/plugin/Socket/Socket.php @@ -1,157 +1,154 @@ "; $desc .= "nohup php {$global['systemRootPath']}plugin/Socket/server.php &"; //$desc .= $this->isReadyLabel(array('YPTWallet')); return $desc; } public function getName() { return "Socket"; } public function getUUID() { return "Socket-5ee8405eaaa16"; } public function getPluginVersion() { return "1.0"; } public function updateScript() { global $global; /* if (AVideoPlugin::compareVersion($this->getName(), "2.0") < 0) { sqlDal::executeFile($global['systemRootPath'] . 'plugin/PayPerView/install/updateV2.0.sql'); } * */ return true; } public function getEmptyDataObject() { global $global; $obj = new stdClass(); $host = parse_url($global['webSiteRootURL'], PHP_URL_HOST); $server_crt_file = "/etc/letsencrypt/live/{$host}/fullchain.pem"; $server_key_file = "/etc/letsencrypt/live/{$host}/privkey.pem"; if(!file_exists($server_crt_file)){ $server_crt_file = ""; } if(!file_exists($server_key_file)){ $server_key_file = ""; } $host = parse_url($global['webSiteRootURL'], PHP_URL_HOST); $obj->port = "2053"; self::addDataObjectHelper('port', 'Server Port', 'You also MUST open this port on the firewall'); $obj->host = $host; self::addDataObjectHelper('host', 'Server host', 'If your site is HTTPS make sure this host also handle the SSL connection'); $obj->debugSocket = false; self::addDataObjectHelper('debugSocket', 'Show server debugger to admin', 'This will show a panel with some socket informations to the ADMIN user only'); $obj->debugAllUsersSocket = false; self::addDataObjectHelper('debugAllUsersSocket', 'Show server debugger to all', 'Same as above but will show the panel to all users'); $obj->server_crt_file = $server_crt_file; self::addDataObjectHelper('server_crt_file', 'SSL Certificate File', 'If your site use HTTPS, you MUST provide one'); $obj->server_key_file = $server_key_file; self::addDataObjectHelper('server_key_file', 'SSL Certificate Key File', 'If your site use HTTPS, you MUST provide one'); $obj->allow_self_signed = true; self::addDataObjectHelper('allow_self_signed', 'Allow self signed certs', 'Should be unchecked in production'); return $obj; } public function getFooterCode() { self::getSocketJS(); } public static function getSocketJS() { global $global; include $global['systemRootPath'] . 'plugin/Socket/footer.php'; } public static function send($msg, $callbackJSFunction = "", $users_id = "", $send_to_uri_pattern = "") { global $global, $SocketSendObj, $SocketSendUsers_id, $SocketSendResponseObj, $SocketURL; if(!is_string($msg)){ $msg = json_encode($msg); } $SocketSendUsers_id = $users_id; if(!is_array($SocketSendUsers_id)){ $SocketSendUsers_id = array($SocketSendUsers_id); } $SocketSendObj = new stdClass(); $SocketSendObj->webSocketToken = getEncryptedInfo(0,$send_to_uri_pattern); $SocketSendObj->msg = $msg; $SocketSendObj->json = json_decode($msg); $SocketSendObj->callback = $callbackJSFunction; $SocketSendResponseObj = new stdClass(); $SocketSendResponseObj->error = true; $SocketSendResponseObj->msg = ""; $SocketSendResponseObj->msgObj = $SocketSendObj; $SocketSendResponseObj->callbackJSFunction = $callbackJSFunction; require_once $global['systemRootPath'] . 'objects/autoload.php'; - $SocketURL = self::getWebSocketURL(true, true); + $SocketURL = self::getWebSocketURL(true); \Ratchet\Client\connect($SocketURL)->then(function($conn) { global $SocketSendObj, $SocketSendUsers_id, $SocketSendResponseObj; $conn->on('message', function($msg) use ($conn) { //echo "Received: {$msg}\n"; //$conn->close(); $SocketSendResponseObj->error = false; }); foreach ($SocketSendUsers_id as $users_id) { $SocketSendObj->to_users_id = $users_id; $conn->send(json_encode($SocketSendObj)); } $conn->close(); //$SocketSendResponseObj->error = false; }, function ($e) { global $SocketURL; _error_log("Could not connect: {$e->getMessage()} {$SocketURL}", AVideoLog::$ERROR); }); return $SocketSendResponseObj; } - public static function getWebSocketURL($useLocalHost = true, $isCommandLine=false) { + public static function getWebSocketURL($isCommandLine=false) { global $global; $socketobj = AVideoPlugin::getDataObject("Socket"); - $address = "127.0.0.1"; - if (empty($useLocalHost)) { - $address = $socketobj->host; - } + $address = $socketobj->host; $port = $socketobj->port; $protocol = "ws"; $scheme = parse_url($global['webSiteRootURL'], PHP_URL_SCHEME); if(strtolower($scheme)==='https'){ $protocol = "wss"; } return "{$protocol}://{$address}:{$port}?webSocketToken=".getEncryptedInfo(0)."&isCommandLine=".intval($isCommandLine); } } diff --git a/plugin/Socket/footer.php b/plugin/Socket/footer.php index f51adb695..f4629065b 100644 --- a/plugin/Socket/footer.php +++ b/plugin/Socket/footer.php @@ -1,155 +1,155 @@ debugAllUsersSocket) || (User::isAdmin() && !empty($obj->debugSocket))) { $help = "Your socket server is NOT running, to start your socket server, please go to your streamer server SSH terminal and run the code
" . "nohup php {$global['systemRootPath']}plugin/Socket/server.php &"; ?>
Socket Disconnected
Socket Connected
Your User ID 0
Socket ResourceId 0
Total Different Devices 0
Total Users Online 0
Users online on same video as you 0
Users online on same live as you 0