diff --git a/plugin/YPTSocket/YPTSocket.php b/plugin/YPTSocket/YPTSocket.php
index a4ce12399..120298623 100644
--- a/plugin/YPTSocket/YPTSocket.php
+++ b/plugin/YPTSocket/YPTSocket.php
@@ -1,161 +1,161 @@
";
$desc .= "nohup php {$global['systemRootPath']}plugin/YPTSocket/server.php &";
$help = "
run this command start the server Help";
//$desc .= $this->isReadyLabel(array('YPTWallet'));
return $desc.$help;
}
public function getName() {
return "YPTSocket";
}
public function getUUID() {
return "YPTSocket-5ee8405eaaa16";
}
public function getPluginVersion() {
return "1.0";
}
public static function getServerVersion() {
return "2.2";
}
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";
$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');
$obj->showTotalOnlineUsersPerVideo = true;
self::addDataObjectHelper('showTotalOnlineUsersPerVideo', 'Show Total Online Users Per Video');
$obj->showTotalOnlineUsersPerLive = true;
self::addDataObjectHelper('showTotalOnlineUsersPerLive', 'Show Total Online Users Per Live');
$obj->showTotalOnlineUsersPerLiveLink = true;
self::addDataObjectHelper('showTotalOnlineUsersPerLiveLink', 'Show Total Online Users Per LiveLink');
return $obj;
}
public function getFooterCode() {
self::getSocketJS();
}
public static function getSocketJS() {
global $global;
include $global['systemRootPath'] . 'plugin/YPTSocket/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);
_error_log("Socket Send: {$SocketURL}");
\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($isCommandLine=false) {
global $global;
- $socketobj = AVideoPlugin::getDataObject("Socket");
+ $socketobj = AVideoPlugin::getDataObject("YPTSocket");
$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/YPTSocket/functions.php b/plugin/YPTSocket/functions.php
index 61095a849..79ebe72bf 100644
--- a/plugin/YPTSocket/functions.php
+++ b/plugin/YPTSocket/functions.php
@@ -1,120 +1,120 @@
from_users_id = User::getId();
$msgObj->isAdmin = User::isAdmin();
$msgObj->user_name = User::getNameIdentification();
$msgObj->browser = get_browser_name();
$msgObj->yptDeviceId = getDeviceID(false);
$msgObj->token = getToken($timeOut);
$msgObj->time = time();
$msgObj->ip = getRealIpAddr();
$msgObj->send_to_uri_pattern = $send_to_uri_pattern;
$msgObj->autoEvalCodeOnHTML = array();
if (!empty($_REQUEST['webSocketSelfURI'])) {
$msgObj->selfURI = $_REQUEST['webSocketSelfURI'];
} else {
$msgObj->selfURI = getSelfURI();
}
if (empty($msgObj->videos_id)) {
if (!empty($_REQUEST['webSocketVideos_id'])) {
$msgObj->videos_id = $_REQUEST['webSocketVideos_id'];
} else {
$msgObj->videos_id = getVideos_id();
}
}
if (empty($msgObj->live_key)) {
if (!empty($_REQUEST['webSocketLiveKey'])) {
$msgObj->live_key = json_decode($_REQUEST['webSocketLiveKey']);
} else {
$msgObj->live_key = isLive();
}
}
if (AVideoPlugin::isEnabledByName('User_location')) {
$msgObj->location = User_Location::getThisUserLocation();
} else {
$msgObj->location = false;
}
/*
if (!empty($msgObj->live_key)) {
$msgObj->is_live = Live::isLiveAndIsReadyFromKey($msgObj->live_key['key'], $msgObj->live_key['live_servers_id'], true);
if($msgObj->is_live){
$code = "onlineLabelOnline('.liveOnlineLabel');";
}else{
$code = "onlineLabelOffline('.liveOnlineLabel');";
}
$msgObj->autoEvalCodeOnHTML[] = $code;
}
*
*/
return encryptString(json_encode($msgObj));
}
function getDecryptedInfo($string) {
$decriptedString = decryptString($string);
$json = json_decode($decriptedString);
if (!empty($json) && !empty($json->token)) {
if (isTokenValid($json->token)) {
return $json;
} else {
_error_log("socket:getDecryptedInfo: token is invalid ");
}
} else {
_error_log("socket:getDecryptedInfo: json->token is empty ({$decriptedString})");
}
return false;
}
class SocketMessageType {
const NEW_CONNECTION = "NEW_CONNECTION";
const NEW_DISCONNECTION = "NEW_DISCONNECTION";
const DEFAULT_MESSAGE = "DEFAULT_MESSAGE";
const ON_VIDEO_MSG = "ON_VIDEO_MSG";
const ON_LIVE_MSG = "ON_LIVE_MSG";
}
function getTotalViewsLive_key($live_key) {
if (empty($live_key)) {
return false;
}
$live_key = object_to_array($live_key);
_mysql_connect();
$liveUsersEnabled = \AVideoPlugin::isEnabledByName("LiveUsers");
if ($liveUsersEnabled) {
$liveUsers = new \LiveOnlineUsers(0);
$total = $liveUsers->getTotalUsersFromTransmitionKey($live_key['key'], $live_key['live_servers_id']);
} else {
$total = null;
}
_mysql_close();
return $total;
}
function killProcessOnPort() {
- $obj = \AVideoPlugin::getDataObject("Socket");
+ $obj = \AVideoPlugin::getDataObject("YPTSocket");
$port = intval($obj->port);
if (!empty($port)) {
echo 'Searching for port: ' . $port . PHP_EOL;
$command = 'netstat -ano | findstr ' . $port;
exec($command, $output, $retval);
$pid = getPIDUsingPort($port);
if (!empty($pid)) {
echo 'Killing, PID ' . $pid . PHP_EOL;
killProcess($pid);
} else {
echo 'No Need to kill, port NOT found' . PHP_EOL;
}
}
}
diff --git a/plugin/YPTSocket/getWebSocket.json.php b/plugin/YPTSocket/getWebSocket.json.php
index bbac9c9c2..a22ee2ff4 100644
--- a/plugin/YPTSocket/getWebSocket.json.php
+++ b/plugin/YPTSocket/getWebSocket.json.php
@@ -1,21 +1,21 @@
error = true;
$obj->msg = "";
$obj->webSocketToken = "";
$obj->webSocketURL = "";
-if(!AVideoPlugin::isEnabledByName("Socket")){
+if(!AVideoPlugin::isEnabledByName("YPTSocket")){
$obj->msg = "Socket plugin not enabled";
die(json_encode($obj));
}
$obj->error = false;
$obj->webSocketToken = getEncryptedInfo(0);
$obj->webSocketURL = YPTSocket::getWebSocketURL();
die(json_encode($obj));
\ No newline at end of file
diff --git a/plugin/YPTSocket/send.json.php b/plugin/YPTSocket/send.json.php
index fabeeb7d5..db0fbc3e5 100644
--- a/plugin/YPTSocket/send.json.php
+++ b/plugin/YPTSocket/send.json.php
@@ -1,27 +1,27 @@
error = true;
$obj->msg = "";
if(empty($_REQUEST['msg'])){
$obj->msg = "The message is empty";
die(json_encode($obj));
}
-if(!AVideoPlugin::isEnabledByName("Socket")){
+if(!AVideoPlugin::isEnabledByName("YPTSocket")){
$obj->msg = "Socket plugin not enabled";
die(json_encode($obj));
}
$obj = sendSocketMessage($_REQUEST['msg']);
die(json_encode($obj));
\ No newline at end of file
diff --git a/plugin/YPTSocket/server.php b/plugin/YPTSocket/server.php
index e511683ac..532e5947d 100644
--- a/plugin/YPTSocket/server.php
+++ b/plugin/YPTSocket/server.php
@@ -1,73 +1,73 @@
serverVersion = YPTSocket::getServerVersion();
ob_end_flush();
_mysql_close();
session_write_close();
$SocketDataObj->port = intval($SocketDataObj->port);
_error_log("Starting Socket server at port {$SocketDataObj->port}");
killProcessOnPort();
$scheme = parse_url($global['webSiteRootURL'], PHP_URL_SCHEME);
echo "Starting AVideo Socket server version {$SocketDataObj->serverVersion} on port {$SocketDataObj->port}".PHP_EOL;
if(strtolower($scheme)!=='https'){
echo "Your socket server does NOT use a secure connection".PHP_EOL;
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Message()
)
),
$SocketDataObj->port
);
$server->run();
} else {
echo "Your socket server uses a secure connection".PHP_EOL;
$parameters = [
'local_cert' => $SocketDataObj->server_crt_file,
'local_pk' => $SocketDataObj->server_key_file,
'allow_self_signed' => $SocketDataObj->allow_self_signed, // Allow self signed certs (should be false in production)
'verify_peer' => false,
'verify_peer_name'=>false,
'security_level'=>0
];
foreach ($parameters as $key => $value) {
echo "Parameter [{$key}]: $value ".PHP_EOL;
}
$loop = React\EventLoop\Factory::create();
// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server('0.0.0.0:' . $SocketDataObj->port, $loop);
$webSock = new React\Socket\SecureServer($webSock, $loop, $parameters);
$webServer = new Ratchet\Server\IoServer(
new HttpServer(
new WsServer(
new Message()
)
),
$webSock
);
//$socket = new Reactor($webServer->loop);
//$socket->listen(8082, '0.0.0.0'); //Port 2
//$socket->on('connection', [$webServer, 'handleConnect']);
//$webServer->run();
$loop->run();
}
\ No newline at end of file