Commit 8461327f authored by Kulya's avatar Kulya 😊

n_files1

parent 0f51406a
Pipeline #14 canceled with stages
Ajax functions:
--------------------------------------------------------------
checkEnterLogin ---------------------------------------------------------
Input:
{login} - string
Output:
Success: UserID
Failed: false
checkPassAndEnter ---------------------------------------------------------
Input:
{UserId} - string,
{Password} - string
Output:
Success: UserID
Failed: false
getActiveRoomData -------------------------------------------------------
Input (POST):
{room} - string (number or room, required)
Output (JSON):
array of object parameters and array of memebers objects
getAllRooms ---------------------------------------------------------
[No input parameters]
Output: {rooms} - array of arrays
getAllUsers ---------------------------------------------------------
[No input parameters]
Output: {users} - array of arrays
saveUserData ---------------------------------------------------------
Input (POST):
{num} - string,
{password} - string
{name} - string
{room} - string (number or room, optional, default 7777)
Output:
Success: Msg
Failed: Error
isFreeNumber ---------------------------------------------------------------
Input (POST):
{num} - string,
Output:
Success: Ok
Failed: Error
saveProfile ---------------------------------------------------------------
Input (POST):
{name} required, default: (2top+15)
{video-layout-name} default: (2top+15)
{video-canvas-size} default: (1920x1080)
{video-canvas-bgcolor} default: (#333333)
{video-layout-bgcolor} default: (#000000)
{video-codec-bandwidth} default: (2mb)
{video-fps} default: (30)
Output:
Success: Ok
Failed: Error
saveRoom ---------------------------------------------------------------------
Input (POST):
{name} required (a-zA-Z)
{number} default: (0-9)
Output:
Success: Ok
Failed: Error
remove_room_file ----------------------------------------------------------------
Input (POST):
{number} required: (0-9)
Output:
Success: Ok
Failed: Error
get_all_profiles -----------------------------------------------------------------
[No input parameters]
Output: {profiles} - array of arrays
get_all_layouts -------------------------------------------------------------------
[No input parameters]
Output: {layouts} - array of arrays
-----------------------------------------------------------------------------------
JS FUNCS
-----------------------------------------------------------------------------------
user_moveto(room,uid,lid)
user_volume_out(room,uid)
user_volume_in(room,uid)
user_unvmute(room,uid)
user_vmute(room,uid)
user_volumeon(room,uid)
user_volumeoff(room,uid)
user_unmute(room,uid)
user_mute(room,uid)
user_kick(room,uid)
change_layout_to(room,layout)
-----------------------------------------------------------------------------------
mute - отключения микрофона
unmute - вкл микр
vmute - отключения исх видео
unvmute - вкл исх видео
vmute-snap
deaf - заглушить мембера
undeaf - мембер снова слышит
volume_in Adjust the gain on the audio coming from a member conference <confname> volume_in <member_id>|all|last|non_moderator [<newval>]
volume_out Adjust the volume of audio going to a member conference <confname> volume_out <member_id>|all|last|non_moderator [<newval>]
hold - убрать с лайоута
unhold - вернуть в лайоут
vblind - мембер не видит других мемберов
unvblind - норм
conference 7777 vid-floor 142 force - если меняем флур нужно перевести флур на другого мембера
conference 7777 vid-layer 142 1
conference 7777 vid-layout 1x1 - поменять лайоут (сетку)
\ No newline at end of file
Kulya.png

1.07 KB

# vMajlis-GUI
## Laravel PHP Framework
vMajlis-GUI
\ No newline at end of file
[![Build Status](https://travis-ci.org/laravel/framework.svg)](https://travis-ci.org/laravel/framework)
[![Total Downloads](https://poser.pugx.org/laravel/framework/d/total.svg)](https://packagist.org/packages/laravel/framework)
[![Latest Stable Version](https://poser.pugx.org/laravel/framework/v/stable.svg)](https://packagist.org/packages/laravel/framework)
[![Latest Unstable Version](https://poser.pugx.org/laravel/framework/v/unstable.svg)](https://packagist.org/packages/laravel/framework)
[![License](https://poser.pugx.org/laravel/framework/license.svg)](https://packagist.org/packages/laravel/framework)
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, queueing, and caching.
Laravel is accessible, yet powerful, providing powerful tools needed for large, robust applications. A superb inversion of control container, expressive migration system, and tightly integrated unit testing support give you the tools you need to build any application with which you are tasked.
## Official Documentation
Documentation for the framework can be found on the [Laravel website](http://laravel.com/docs).
## Contributing
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](http://laravel.com/docs/contributions).
## Security Vulnerabilities
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell at taylor@laravel.com. All security vulnerabilities will be promptly addressed.
### License
The Laravel framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
#!/usr/bin/env php
<?php
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Artisan Application
|--------------------------------------------------------------------------
|
| When we run the console application, the current CLI command will be
| executed in this console and the response sent back to a terminal
| or another output device for the developers. Here goes nothing!
|
*/
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);
/*
|--------------------------------------------------------------------------
| Shutdown The Application
|--------------------------------------------------------------------------
|
| Once Artisan has finished running. We will fire off the shutdown events
| so that any final work may be done by the application before we shut
| down the process. This is the last thing to happen to the request.
|
*/
$kernel->terminate($input, $status);
exit($status);
This diff is collapsed.
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"cboden/ratchet": "^0.4.1",
"workerman/workerman": "^3.5"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
// SSL context.
$context = array(
'ssl' => array(
'local_cert' => '/etc/letsencrypt/live/online.vmajlis.uz/fullchain.pem',
'local_pk' => '/etc/letsencrypt/live/online.vmajlis.uz/privkey.pem',
'verify_peer' => false,
)
);
// массив для связи соединения пользователя и необходимого нам параметра
$users = [];
$GLOBALS["chTime"] = time();
$GLOBALS["users"] = [];
// Create a Websocket server
$ws_worker = new Worker("websocket://0.0.0.0:8085",$context);
// 4 processes
$ws_worker->count = 4;
$ws_worker->transport = 'ssl';
tLog( "-------- ======== WebSOCKET start on [0.0.0.0]:[8085] =========----------" );
$ws_worker->onWorkerStart = function() use (&$users) {
// создаём локальный tcp-сервер, чтобы отправлять на него сообщения из кода нашего сайта
$inner_tcp_worker = new Worker("tcp://127.0.0.1:12345");
// создаём обработчик сообщений, который будет срабатывать,
// когда на локальный tcp-сокет приходит сообщение
$inner_tcp_worker->onMessage = function($connection, $data) use (&$users) {
tLog( "onMessage: " . $data );
$connection->send("Msg got by Server.");
$data = json_decode($data,true);
// отправляем сообщение пользователю по userId
if (isset($GLOBALS["users"][$data->user])) {
$webconnection = $GLOBALS["users"][$data->user];
$webconnection->send($data->message);
}
/*if (isset($users[$data->user])) {
$webconnection = $users[$data->user];
$webconnection->send($data->message);
}*/
};
$inner_tcp_worker->listen();
};
$ws_worker->onConnect = function($connection) use (&$users, $ws_worker) {
$connection->onWebSocketConnect = function($connection) use (&$users, $ws_worker) {
tLog( "onConnect: " . json_encode($_GET) );
tLog( "onConnect_WSconn: " . $connection->id );
//$users[$_GET['v']] = $connection;
$GLOBALS["users"][$_GET['v']] = $connection;
$myConnId = $connection->id;
/* TEST connections */
foreach($ws_worker->connections as $connection){
tLog( "checkSEND: " . $connection->id );
if( $myConnId == $connection->id ){
$connection->send("Wellcome: [".$_GET['v']."][".$GLOBALS["users"][$_GET['v']]->id."][".$myConnId."]");
} else {
$connection->send("NewConnect: [".$_GET['v']."][".$GLOBALS["users"][$_GET['v']]->id."][".$myConnId."]");
}
}
};
};
// Emitted when connection Msg
$ws_worker->onMessage = function($connection, $data) use(&$users, $ws_worker)
{
tLog( "onMessage_users: " . json_encode($GLOBALS["users"]) );
tLog( "onMessage_DATA: " . $data );
$arData = json_decode($data,true);
tLog( "onMessage_VID: " . $arData['vid'] );
if( isset($GLOBALS["users"][$arData['vid']]) ) {
$connection->send("I know you!");
} else {
$connection->send("Who you!");
}
};
// Emitted when connection closed
$ws_worker->onClose = function($connection) use(&$users)
{
tLog( "onClose: " . json_encode($connection) );
// удаляем параметр при отключении пользователя
//$user = array_search($connection, $users);
$user = array_search($connection, $GLOBALS["users"]);
unset($GLOBALS["users"][$user]);
};
function tLog( $text ) {
$logfile = __DIR__."/websocket.log";
$nowdate = date("Y-m-d_H:i:s");
file_put_contents($logfile, $nowdate."(".$GLOBALS["chTime"] .") [".$text."] \n", FILE_APPEND | LOCK_EX);
}
// Run worker
Worker::runAll();
\ No newline at end of file
This diff is collapsed.
<?php
/*
create_png_from_text(array(
'width' => '',
'height' => '',
'text' => '',
'file' => ''
));
*/
$params = ["text"=>urldecode($argv[1])];
if(!empty($argv[2])) { $params["file"] =$argv[2]; }
if(!empty($argv[3])) { $params["width"] =$argv[3]; }
if(!empty($argv[4])) { $params["height"] =$argv[4]; }
$this->create_png_from_text();
protected function create_png_from_text($args){
$font = "/usr/local/freeswitch/fonts/montserrat/Montserrat-Italic.otf";
if( empty($args) ){ $args = "Default";}
if( !is_array($args) ){
$args = array( 'text' => $args );
}
$width = ( !empty($args["width"]) ) ? (int)$args["width"] : 1280; //640; //1920; //640;
$height = ( !empty($args["height"]) ) ? (int)$args["height"] : 720; //480; //1080; //480;
$text = $args["text"];
$file = ( !empty($args["file"]) ) ? $args["file"] : false;
if( $width > 1000 ){
$fontsize = 25;
} else {
$fontsize = 20;
}
$img = imagecreate($width, $height);
$black = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $black);
$txtInTransparent = imagecolorallocate($img, 255, 255, 255);
$image_width = imagesx($img);
$image_height = imagesy($img);
$text_box = imagettfbbox($fontsize, 0, $font, $text);
$text_width = $text_box[0] - $text_box[2];
$text_height = $text_box[1] - $text_box[7];
$x = 50; //$image_width - ($text_width / 2);
$y = $image_height - ($text_height + 5);
imagettftext($img, $fontsize, 0, $x, $y, $txtInTransparent, $font, $text);
//imagettftext($img, $fontsize, 0, $x, $y, $txtInTransparent, $font, $text.'-['.$image_height.']-['.$text_height.']-['.$y.']' ); //For tests
if( !empty($file) ){
imagepng($img, $file);
} else {
header('Content-Type: image/png');
imagepng($img);
}
imagedestroy($img);
}
?>
var elixir = require('laravel-elixir');
/*
|--------------------------------------------------------------------------
| Elixir Asset Management
|--------------------------------------------------------------------------
|
| Elixir provides a clean, fluent API for defining some basic Gulp tasks
| for your Laravel application. By default, we are compiling the Sass
| file for our application, as well as publishing vendor resources.
|
*/
elixir(function(mix) {
mix
.sass('app.scss')
.styles([
'bootstrap.min.css',
'bootstrap-grid.min.css'
])
.scripts([
'jquery.js',
'bootstrap.min.js',
'bootstrap.bundle.min.js'
]);
});
\ No newline at end of file
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
// SSL context.
$context = array(
'ssl' => array(
'local_cert' => '/etc/letsencrypt/live/online.vmajlis.uz/fullchain.pem',
'local_pk' => '/etc/letsencrypt/live/online.vmajlis.uz/privkey.pem',
'verify_peer' => false,
)
);
// массив для связи соединения пользователя и необходимого нам параметра
$users = [];
$GLOBALS["chTime"] = time();
// Create a Websocket server
$ws_worker = new Worker("websocket://0.0.0.0:8085",$context);
// 4 processes
$ws_worker->count = 4;
$ws_worker->transport = 'ssl';
tLog( "-------- ======== WebSOCKET start on [0.0.0.0]:[8085] =========----------" );
$ws_worker->onWorkerStart = function() use (&$users)
{
// создаём локальный tcp-сервер, чтобы отправлять на него сообщения из кода нашего сайта
$inner_tcp_worker = new Worker("tcp://127.0.0.1:12345");
// создаём обработчик сообщений, который будет срабатывать,
// когда на локальный tcp-сокет приходит сообщение
$inner_tcp_worker->onMessage = function($connection, $data) use (&$users) {
tLog( "onMessage: " . $data );
$connection->send("Msg got by Server.");
$data = json_decode($data,true);
// отправляем сообщение пользователю по userId
if (isset($users[$data->user])) {
$webconnection = $users[$data->user];
$webconnection->send($data->message);
}
};
$inner_tcp_worker->listen();
};
$ws_worker->onConnect = function($connection) use (&$users)
{
$connection->onWebSocketConnect = function($connection) use (&$users)
{
$connection->send("Connection succesfull!");
// при подключении нового пользователя сохраняем get-параметр, который же сами и передали со страницы сайта
//$users[$_COOKIE['PHPSESSID']] = $connection;
tLog( "onConnect: " . json_encode($_GET) );
$users[$_GET['v']] = $connection;
// вместо get-параметра можно также использовать параметр из cookie, например $_COOKIE['PHPSESSID']
};
};
// Emitted when connection Msg
$ws_worker->onMessage = function($connection, $data) use(&$users)
{
tLog( "onMessage_users: " . json_encode($users) );
tLog( "onMessage: " . json_encode($_GET) );
tLog( "onMessage_DATA: " . json_encode($data) );
if( !empty($users[$_GET['v']]) ) {
$connection->send("I know you!");
} else {
$connection->send("Who you!");
}
};
// Emitted when connection closed
$ws_worker->onClose = function($connection) use(&$users)
{
tLog( "onClose: " . json_encode($connection) );
// удаляем параметр при отключении пользователя
$user = array_search($connection, $users);
unset($users[$user]);
};
function tLog( $text ) {
$logfile = __DIR__."/websocket.log";
$nowdate = date("Y-m-d_H:i:s");
file_put_contents($logfile, $nowdate."(".$GLOBALS["chTime"] .") [".$text."] \n", FILE_APPEND | LOCK_EX);
}
// Run worker
Worker::runAll();
\ No newline at end of file
suites:
main:
namespace: App
psr4_prefix: App
src_path: app
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
<exclude>
<file>./app/Http/routes.php</file>
</exclude>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylorotwell@gmail.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
require_once __DIR__.'/public/index.php';
<?php
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$request = Illuminate\Http\Request::capture();
$response = $kernel->handle( $request );
$mdt = $response->getContent();
var_dump("AAAAAAAAAAAAAAAAAAA");
var_dump("<hr>");
var_dump($request);
\ No newline at end of file
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
// SSL context.
$context = array(
'ssl' => array(
'local_cert' => '/etc/letsencrypt/live/online.vmajlis.uz/fullchain.pem',
'local_pk' => '/etc/letsencrypt/live/online.vmajlis.uz/privkey.pem',
'verify_peer' => false,
)
);
// массив для связи соединения пользователя и необходимого нам параметра
$users = [];
$GLOBALS["chTime"] = time();
// Create a Websocket server
$ws_worker = new Worker("websocket://0.0.0.0:8085",$context);
// 4 processes
$ws_worker->count = 4;
$ws_worker->transport = 'ssl';
tLog( "-------- ======== WebSOCKET start on [0.0.0.0]:[8085] =========----------" );
$ws_worker->onWorkerStart = function() use (&$users)
{
// создаём локальный tcp-сервер, чтобы отправлять на него сообщения из кода нашего сайта
$inner_tcp_worker = new Worker("tcp://127.0.0.1:12345");
// создаём обработчик сообщений, который будет срабатывать,
// когда на локальный tcp-сокет приходит сообщение
$inner_tcp_worker->onMessage = function($connection, $data) use (&$users) {
tLog( "onMessage: " . $data );
$connection->send("Msg got by Server.");
$data = json_decode($data,true);
// отправляем сообщение пользователю по userId
if (isset($users[$data->user])) {
$webconnection = $users[$data->user];
$webconnection->send($data->message);
}
};
$inner_tcp_worker->listen();
};
$ws_worker->onConnect = function($connection) use (&$users)
{
$connection->onWebSocketConnect = function($connection) use (&$users)
{
$connection->send("Connection succesfull!");
// при подключении нового пользователя сохраняем get-параметр, который же сами и передали со страницы сайта
//$users[$_COOKIE['PHPSESSID']] = $connection;
tLog( "onConnect: " . json_encode($_GET) );
$users[$_GET['v']] = $connection;
// вместо get-параметра можно также использовать параметр из cookie, например $_COOKIE['PHPSESSID']
};
};
// Emitted when connection Msg
$ws_worker->onMessage = function($connection, $data) use(&$users)
{
tLog( "onMessage_users: " . json_encode($users) );
tLog( "onMessage_DATA: " . $data );
$arData = json_decode($data,true);
if( isset($users[$arData['v']]) ) {
$connection->send("I know you!");
} else {
$connection->send("Who you!");
}
};
// Emitted when connection closed
$ws_worker->onClose = function($connection) use(&$users)
{
tLog( "onClose: " . json_encode($connection) );
// удаляем параметр при отключении пользователя
$user = array_search($connection, $users);
unset($users[$user]);
};
function tLog( $text ) {
$logfile = __DIR__."/websocket.log";
$nowdate = date("Y-m-d_H:i:s");
file_put_contents($logfile, $nowdate."(".$GLOBALS["chTime"] .") [".$text."] \n", FILE_APPEND | LOCK_EX);
}
// Run worker
Worker::runAll();
\ No newline at end of file
File added
<?php
require_once __DIR__ . '/vendor/autoload.php';
/* Laravel connection */
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$request = Illuminate\Http\Request::capture();
$GLOBALS["wbsock"] = '123';
use Workerman\Worker;
// SSL context.
$context = array(
'ssl' => array(
'local_cert' => '/etc/letsencrypt/live/online.vmajlis.uz/fullchain.pem',
'local_pk' => '/etc/letsencrypt/live/online.vmajlis.uz/privkey.pem',
'verify_peer' => false,
)
);
// массив для связи соединения пользователя и необходимого нам параметра
$users = [];
// Create a Websocket server
$ws_worker = new Worker("websocket://0.0.0.0:8085",$context);
// 4 processes
$ws_worker->count = 4;
$ws_worker->transport = 'ssl';
$getSystemData = function ($req) use($kernel,$request){
$GLOBALS["datas"] = $req;
$response = $kernel->handle( $request );
$res = $response->getContent();
//$kernel->terminate($request, $response);
return $res;
};
tLog( "-------- ======== WebSOCKET start on [0.0.0.0]:[8085] =========----------" );
$ws_worker->onWorkerStart = function() use (&$users) {
$inner_tcp_worker = new Worker("tcp://127.0.0.1:12345");
$inner_tcp_worker->onMessage = function($connection, $data) use (&$users) {
tLog( "onMessage: " . $data );
$data = json_decode($data,true);
// отправляем сообщение пользователю по userId
if (isset($users[$data["vid"]])) {
$webconnection = $users[$data["vid"]];
$webconnection->send('{"ok":"Your msg: '.$data["msg"].'"}');
}
};
$inner_tcp_worker->listen();
};
$ws_worker->onConnect = function($connection) use (&$users, $ws_worker) {
$connection->onWebSocketConnect = function($connection) use (&$users, $ws_worker) {
tLog( "onConnect_GET: " . json_encode($_GET) );
$users[$_GET['v']] = $connection;
$myConnId = $connection->id;
$myConnIP = $connection->getRemoteIp();
//tLog( "onConnect_LARAV_CONN: " . $vtr );
/* RESEND to all connections */
foreach($ws_worker->connections as $allConn){
tLog( "checkConnSEND: " . $allConn->id );
if( $myConnId == $allConn->id ){
$allConn->send('{"connection":"ok","msg":"Wellcome"}'); //: ['.$_GET['v'].']['.$allConn->id.']['.$myConnId.']
} /*else {
if(!empty($vtr)){
$allConn->send('{"newVisitor":"ok","vid":"'.$_GET['v'].'","cid":"'.$allConn->id.'","visitor":"'.json_encode($vtr).'"}' );
}
}*/
}
};
};
// Emitted when connection Msg
$ws_worker->onMessage = function($connection, $data) use(&$users, $ws_worker,$getSystemData) {
tLog( "------------=========================--------------------- " );
tLog( "onMessage_DATA: " . $data );
$arData = json_decode($data,true);
tLog( "onMessage_VID: " . $arData["vid"] );
$myConnId = $connection->id;
$myConnIP = $connection->getRemoteIp();
$arData["cid"] = $myConnId;
$arData["vip"] = $myConnIP;
$arData["userkeys"] = array_keys($users);
if( !empty( $arData['cmd'] ) ){
$cmdRes = $getSystemData($arData);
tLog( "checkRes_CMD: " . $cmdRes );
$cmdRes = json_decode($cmdRes,true);
tLog( "JSON error------: " . json_last_error() );
//tLog( "checkRes_VSTRs------: " . $cmdRes["count"] );
//array("count"=>count($arVisitors), "allvisitors"=> $arVisitors, "newvisit"=> $newvisit);
// NewVisit to All
$arLastMessages = ( !empty($cmdRes["arLastMessages"]) ) ? $cmdRes["arLastMessages"] : "";
$allvstrs = ( !empty($cmdRes["allvisitors"]) ) ? $cmdRes["allvisitors"] : "";
$allCnt = ( !empty($cmdRes["count"]) ) ? $cmdRes["count"] : 0;
$toMe = json_encode(array("allvisitors"=>$allvstrs,"lastmessages"=>$arLastMessages,"count"=>$allCnt ));
$connection->send($toMe);
if( !empty($cmdRes["newvisit"]) ) {
$toAll = json_encode(array("newvisit"=>$cmdRes["newvisit"]));
foreach($users as $uKey => $uConn ){
if( $myConnId != $uConn->id ){
$uConn->send($toAll);
}
}
}
return;
}
if(!empty($arData["message"])){
$newMsgRes = $getSystemData($arData);
tLog( "checkRes_inc_MSG: " . $newMsgRes );
$arMsgRes = json_decode($newMsgRes,true);
tLog( "JSON error------: " . json_last_error() );
tLog( "onMessage_Sent_OK: " . $users[$arData['vid']]->id );
$users[$arData['vid']]->send('{"sent":"ok","oldID":"'.$arData['messageId'].'","newID":"'.$arMsgRes["newMsgId"].'","toName":"'.$arMsgRes["toName"].'","ip":"'.$myConnIP.'","sid":"'.$users[$arData['vid']]->id.'"}');
tLog( "onMessage_Check_Lichka: " . $arData['room'] ."_". $arData['to'] );
if( $arData['room'] != $arData['to'] ){
$users[$arData['to']]->send('{"newmessage":"ok","msgID":"'.$arMsgRes["newMsgId"].'","msgDate":"'.$arMsgRes["newMsgDate"].'","private":"yes","fromId":"'.$arData['vid'].'","from":"'.$arData['name'].'","message":"'.$arData['message'].'","sid":"'.$users[$arData['to']]->id.'"}');
} else {
/* RESEND to all connections */
foreach($users as $uKey => $uConn ){
$cid = $uConn->id;
if( $myConnId != $cid ) {
if( in_array($uKey,$arMsgRes["vkeys"]) ){
tLog( "checkMsgSEND_to_Other: " . $cid );
$uConn->send('{"newmessage":"ok","msgID":"'.$arMsgRes["newMsgId"].'","msgDate":"'.$arMsgRes["newMsgDate"].'","fromId":"'.$arData['vid'].'","from":"'.$arData['name'].'","message":"'.$arData['message'].'","sid":"'.$cid.'"}');
}
}
}
}
return;
}
/*
foreach($ws_worker->connections as $connection){
tLog( "checkMsgSEND: " . $connection->id );
if( $myConnId == $connection->id ){
$newMsgID = time() . $arData['messageId'];
$connection->send('{"sent":"ok","oldID":"'.$arData['messageId'].'","newID":"'.$newMsgID.'","ip":"'.$myConnIP.'","sid":"'.$connection->id.'"}'); //Wellcome: [".$_GET['v']."][".$users[$_GET['v']]->id."][".$myConnId."]
} else {
$connection->send('{"msgID":"'.$newMsgID.'","fromId":"'.$arData['vid'].'","from":"'.$arData['name'].'","message":"'.$arData['message'].'","sid":"'.$connection->id.'"}'); //NewConnect: [".$_GET['v']."][".$users[$_GET['v']]->id."][".$myConnId."]
}
}
*/
/*
if( isset($users[$arData['vid']]) ) {
$connection->send("I know you! [".$users[$arData['vid']]->id."]");
} else {
$connection->send("Who you! [".$connection->id."]");
}*/
};
// Emitted when connection closed
$ws_worker->onClose = function($connection) use(&$users) {
tLog( "onClose: " . $connection->id );
// удаляем параметр при отключении пользователя
//$user = array_search($connection, $users);
$vid = array_search($connection, $users);
unset($users[$vid]);
foreach($users as $uConn ){
$uConn->send('{"closevisitor":"'.$vid.'"}');
}
};
function tLog( $text ) {
$logfile = __DIR__."/websocket.log";
$nowdate = date("Y-m-d_H:i:s");
file_put_contents($logfile, $nowdate."[".$text."] \n", FILE_APPEND | LOCK_EX);
}
// Run worker
Worker::runAll();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment