-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
{% endblock %}
@@ -36,119 +32,12 @@
+ {{ js_include('lib/layui/layui.js') }}
+ {{ js_include('web/js/live.player.js') }}
+ {{ js_include('web/js/live.im.js') }}
+
{% endblock %}
{% block inline_js %}
-
-
{% endblock %}
\ No newline at end of file
diff --git a/app/Http/Web/Views/index/im.volt b/app/Http/Web/Views/index/im.volt
new file mode 100644
index 00000000..4daf086d
--- /dev/null
+++ b/app/Http/Web/Views/index/im.volt
@@ -0,0 +1,99 @@
+{% extends 'templates/full.volt' %}
+
+{% block content %}
+
+{% endblock %}
+
+{% block inline_js %}
+
+ {{ js_include('lib/layui/layui.js') }}
+
+
+
+{% endblock %}
\ No newline at end of file
diff --git a/app/Http/Web/Views/index/player.volt b/app/Http/Web/Views/index/player.volt
deleted file mode 100644
index 5b1c5b32..00000000
--- a/app/Http/Web/Views/index/player.volt
+++ /dev/null
@@ -1,338 +0,0 @@
-
-
-
-
-
-{{ js_include('library/chplayer/chplayer.min.js') }}
-
-
-
-
- 官网chplayer.com,版本号:1.0
-
以下仅列出部分功能,全部功能请至官网《手册》查看
-
-
-
-
-
-
-
- 更多弹幕动作
-
-
-
单独监听功能:
-
- 播放状态:暂停
- 无跳转时间
- 当前音量:0.8
- 是否全屏:否
- 还未结束
- 视频地址正常
- 当前播放时间(秒):0
-
diff --git a/app/Services/Frontend/Chapter/Learning.php b/app/Services/Frontend/Chapter/Learning.php
index d835a1d2..475c37fe 100644
--- a/app/Services/Frontend/Chapter/Learning.php
+++ b/app/Services/Frontend/Chapter/Learning.php
@@ -14,11 +14,11 @@ class Learning extends FrontendService
use ChapterTrait;
- public function handle()
+ public function handle($id)
{
$post = $this->request->getPost();
- $chapter = $this->checkChapterCache($post['chapter_id']);
+ $chapter = $this->checkChapterCache($id);
$user = $this->getLoginUser();
diff --git a/app/Traits/Auth.php b/app/Traits/Auth.php
index 9041e22a..0165572c 100644
--- a/app/Traits/Auth.php
+++ b/app/Traits/Auth.php
@@ -52,6 +52,7 @@ trait Auth
$user->id = 0;
$user->name = 'guest';
+ $user->avatar = kg_ci_avatar_img_url(null);
return $user;
}
diff --git a/composer.json b/composer.json
index 2a57b207..b58e95db 100644
--- a/composer.json
+++ b/composer.json
@@ -14,6 +14,7 @@
"qcloudsms/qcloudsms_php": "0.1.*",
"qcloud/cos-sdk-v5": "2.*",
"workerman/gateway-worker": "^3.0.12",
+ "workerman/gatewayclient": "^3.0.12",
"whichbrowser/parser": "^2.0",
"hightman/xunsearch": "^1.4.14",
"aferrandini/phpqrcode": "1.0.1",
diff --git a/composer.lock b/composer.lock
index 6f010676..c812be5e 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "1de77fca92539b23fbdbad81127bafd1",
+ "content-hash": "d847018715ab8103c3b5e04db1807223",
"packages": [
{
"name": "aferrandini/phpqrcode",
@@ -58,25 +58,25 @@
"time": "2013-07-08T09:39:08+00:00"
},
{
- "name": "doctrine/lexer",
- "version": "1.1.0",
- "source": {
- "type": "git",
- "url": "https://github.com/doctrine/lexer.git",
- "reference": "e17f069ede36f7534b95adec71910ed1b49c74ea"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/doctrine/lexer/zipball/e17f069ede36f7534b95adec71910ed1b49c74ea",
- "reference": "e17f069ede36f7534b95adec71910ed1b49c74ea",
- "shasum": "",
- "mirrors": [
- {
- "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
- "preferred": true
- }
- ]
- },
+ "name": "doctrine/lexer",
+ "version": "1.1.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/doctrine/lexer.git",
+ "reference": "e17f069ede36f7534b95adec71910ed1b49c74ea"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/doctrine/lexer/zipball/e17f069ede36f7534b95adec71910ed1b49c74ea",
+ "reference": "e17f069ede36f7534b95adec71910ed1b49c74ea",
+ "shasum": "",
+ "mirrors": [
+ {
+ "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+ "preferred": true
+ }
+ ]
+ },
"require": {
"php": "^7.2"
},
@@ -703,16 +703,16 @@
}
},
"notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Michael Dowling",
- "email": "mtdowling@gmail.com",
- "homepage": "https://github.com/mtdowling"
- }
- ],
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Michael Dowling",
+ "email": "mtdowling@gmail.com",
+ "homepage": "https://github.com/mtdowling"
+ }
+ ],
"description": "CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due",
"keywords": [
"cron",
@@ -1898,35 +1898,68 @@
},
"notification-url": "https://packagist.org/downloads/",
"license": [
- "MIT"
+ "MIT"
],
- "homepage": "http://www.workerman.net",
- "keywords": [
- "communication",
- "distributed"
- ],
- "time": "2019-07-02T11:55:24+00:00"
+ "homepage": "http://www.workerman.net",
+ "keywords": [
+ "communication",
+ "distributed"
+ ],
+ "time": "2019-07-02T11:55:24+00:00"
},
- {
- "name": "workerman/workerman",
- "version": "v3.5.22",
- "source": {
- "type": "git",
- "url": "https://github.com/walkor/Workerman.git",
- "reference": "488f108f9e446f31bac4d689bb9f9fe3705862cf"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/walkor/Workerman/zipball/488f108f9e446f31bac4d689bb9f9fe3705862cf",
- "reference": "488f108f9e446f31bac4d689bb9f9fe3705862cf",
- "shasum": "",
- "mirrors": [
- {
- "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
- "preferred": true
- }
- ]
- },
+ {
+ "name": "workerman/gatewayclient",
+ "version": "v3.0.13",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/walkor/GatewayClient.git",
+ "reference": "6f4e76f38947be5cabca2c6fee367151f248d949"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/walkor/GatewayClient/zipball/6f4e76f38947be5cabca2c6fee367151f248d949",
+ "reference": "6f4e76f38947be5cabca2c6fee367151f248d949",
+ "shasum": "",
+ "mirrors": [
+ {
+ "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+ "preferred": true
+ }
+ ]
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "GatewayClient\\": "./"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "homepage": "http://www.workerman.net",
+ "time": "2018-09-15T03:03:50+00:00"
+ },
+ {
+ "name": "workerman/workerman",
+ "version": "v3.5.22",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/walkor/Workerman.git",
+ "reference": "488f108f9e446f31bac4d689bb9f9fe3705862cf"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/walkor/Workerman/zipball/488f108f9e446f31bac4d689bb9f9fe3705862cf",
+ "reference": "488f108f9e446f31bac4d689bb9f9fe3705862cf",
+ "shasum": "",
+ "mirrors": [
+ {
+ "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+ "preferred": true
+ }
+ ]
+ },
"require": {
"php": ">=5.3"
},
@@ -1951,14 +1984,14 @@
"role": "Developer"
}
],
- "description": "An asynchronous event driven PHP framework for easily building fast, scalable network applications.",
- "homepage": "http://www.workerman.net",
- "keywords": [
- "asynchronous",
- "event-loop"
- ],
- "time": "2019-09-06T03:42:47+00:00"
- },
+ "description": "An asynchronous event driven PHP framework for easily building fast, scalable network applications.",
+ "homepage": "http://www.workerman.net",
+ "keywords": [
+ "asynchronous",
+ "event-loop"
+ ],
+ "time": "2019-09-06T03:42:47+00:00"
+ },
{
"name": "xiaochong0302/ip2region",
"version": "v1.0.0",
@@ -1979,16 +2012,16 @@
}
]
},
- "require": {
- "php": ">=7.0"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "Koogua\\Ip2Region\\": "src"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
+ "require": {
+ "php": ">=7.0"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Koogua\\Ip2Region\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@@ -2054,13 +2087,13 @@
"email": "me@yansongda.cn"
}
],
- "description": "专注 Alipay 和 WeChat 的支付扩展包",
- "keywords": [
- "alipay",
- "pay",
- "wechat"
- ],
- "time": "2019-09-21T15:05:57+00:00"
+ "description": "专注 Alipay 和 WeChat 的支付扩展包",
+ "keywords": [
+ "alipay",
+ "pay",
+ "wechat"
+ ],
+ "time": "2019-09-21T15:05:57+00:00"
},
{
"name": "yansongda/supports",
@@ -2082,16 +2115,16 @@
}
]
},
- "require": {
- "guzzlehttp/guzzle": "^6.2",
- "monolog/monolog": "^1.23 || ^2.0",
- "php": ">=7.1.3"
- },
- "require-dev": {
- "friendsofphp/php-cs-fixer": "^2.15",
- "phpunit/phpunit": "^7.5",
- "predis/predis": "^1.1"
- },
+ "require": {
+ "guzzlehttp/guzzle": "^6.2",
+ "monolog/monolog": "^1.23 || ^2.0",
+ "php": ">=7.1.3"
+ },
+ "require-dev": {
+ "friendsofphp/php-cs-fixer": "^2.15",
+ "phpunit/phpunit": "^7.5",
+ "predis/predis": "^1.1"
+ },
"suggest": {
"predis/predis": "Allows to use throttle feature"
},
@@ -2347,16 +2380,16 @@
}
]
},
- "require": {
- "cakephp/core": "^3.6.0",
- "php": ">=5.6.0",
- "psr/simple-cache": "^1.0.0"
- },
- "type": "library",
- "autoload": {
- "psr-4": {
- "Cake\\Cache\\": "."
- }
+ "require": {
+ "cakephp/core": "^3.6.0",
+ "php": ">=5.6.0",
+ "psr/simple-cache": "^1.0.0"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-4": {
+ "Cake\\Cache\\": "."
+ }
},
"notification-url": "https://packagist.jp/downloads/",
"license": [
@@ -2695,15 +2728,15 @@
],
"description": "CakePHP Utility classes such as Inflector, String, Hash, and Security",
"homepage": "https://cakephp.org",
- "keywords": [
- "cakephp",
- "hash",
- "inflector",
- "security",
- "string",
- "utility"
- ],
- "time": "2019-11-21T14:18:54+00:00"
+ "keywords": [
+ "cakephp",
+ "hash",
+ "inflector",
+ "security",
+ "string",
+ "utility"
+ ],
+ "time": "2019-11-21T14:18:54+00:00"
},
{
"name": "jaeger/g-http",
@@ -2962,16 +2995,16 @@
}
]
},
- "require": {
- "php": "^7.1",
- "riimu/kit-phpencoder": "^2.4",
- "robmorgan/phinx": "^0.11",
- "symfony/console": "^2.8|^3.0|^4.0|^5.0"
- },
- "require-dev": {
- "overtrue/phplint": "^1.1",
- "phpstan/phpstan-shim": "^0.11",
- "phpunit/phpunit": "^7.0",
+ "require": {
+ "php": "^7.1",
+ "riimu/kit-phpencoder": "^2.4",
+ "robmorgan/phinx": "^0.11",
+ "symfony/console": "^2.8|^3.0|^4.0|^5.0"
+ },
+ "require-dev": {
+ "overtrue/phplint": "^1.1",
+ "phpstan/phpstan-shim": "^0.11",
+ "phpunit/phpunit": "^7.0",
"squizlabs/php_codesniffer": "^3.4"
},
"bin": [
@@ -2989,16 +3022,16 @@
],
"description": "Migration generator for Phinx",
"homepage": "https://github.com/odan/phinx-migrations-generator",
- "keywords": [
- "database",
- "generator",
- "migration",
- "migrations",
- "mysql",
- "phinx"
- ],
- "time": "2019-11-21T15:15:19+00:00"
- },
+ "keywords": [
+ "database",
+ "generator",
+ "migration",
+ "migrations",
+ "mysql",
+ "phinx"
+ ],
+ "time": "2019-11-21T15:15:19+00:00"
+ },
{
"name": "phalcon/ide-stubs",
"version": "v3.4.3",
@@ -3054,25 +3087,25 @@
"time": "2018-12-09T14:11:06+00:00"
},
{
- "name": "psr/container",
- "version": "1.0.0",
- "source": {
- "type": "git",
- "url": "https://github.com/php-fig/container.git",
- "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
- "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
- "shasum": "",
- "mirrors": [
- {
- "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
- "preferred": true
- }
- ]
- },
+ "name": "psr/container",
+ "version": "1.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/php-fig/container.git",
+ "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
+ "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
+ "shasum": "",
+ "mirrors": [
+ {
+ "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+ "preferred": true
+ }
+ ]
+ },
"require": {
"php": ">=5.3.0"
},
@@ -3692,15 +3725,15 @@
],
"description": "Generic abstractions related to writing services",
"homepage": "https://symfony.com",
- "keywords": [
- "abstractions",
- "contracts",
- "decoupling",
- "interfaces",
- "interoperability",
- "standards"
- ],
- "time": "2019-11-18T17:27:11+00:00"
+ "keywords": [
+ "abstractions",
+ "contracts",
+ "decoupling",
+ "interfaces",
+ "interoperability",
+ "standards"
+ ],
+ "time": "2019-11-18T17:27:11+00:00"
},
{
"name": "symfony/var-dumper",
@@ -3785,25 +3818,25 @@
"time": "2019-12-18T13:41:29+00:00"
},
{
- "name": "symfony/yaml",
- "version": "v5.0.1",
- "source": {
- "type": "git",
- "url": "https://github.com/symfony/yaml.git",
- "reference": "51b684480184fa767b97e28eaca67664e48dd3e9"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/symfony/yaml/zipball/51b684480184fa767b97e28eaca67664e48dd3e9",
- "reference": "51b684480184fa767b97e28eaca67664e48dd3e9",
- "shasum": "",
- "mirrors": [
- {
- "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
- "preferred": true
- }
- ]
- },
+ "name": "symfony/yaml",
+ "version": "v5.0.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/yaml.git",
+ "reference": "51b684480184fa767b97e28eaca67664e48dd3e9"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/yaml/zipball/51b684480184fa767b97e28eaca67664e48dd3e9",
+ "reference": "51b684480184fa767b97e28eaca67664e48dd3e9",
+ "shasum": "",
+ "mirrors": [
+ {
+ "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+ "preferred": true
+ }
+ ]
+ },
"require": {
"php": "^7.2.5",
"symfony/polyfill-ctype": "~1.8"
@@ -3835,16 +3868,16 @@
"license": [
"MIT"
],
- "authors": [
- {
- "name": "Fabien Potencier",
- "email": "fabien@symfony.com"
- },
- {
- "name": "Symfony Community",
- "homepage": "https://symfony.com/contributors"
- }
- ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2019-11-18T17:27:11+00:00"
diff --git a/public/static/web/css/common.css b/public/static/web/css/common.css
index 86867322..57eedb98 100644
--- a/public/static/web/css/common.css
+++ b/public/static/web/css/common.css
@@ -727,6 +727,11 @@
color: gray;
}
+.live-player {
+ width: 800px;
+ height: 450px;
+}
+
.chapter-bg {
background-color: #f2f2f2;
}
diff --git a/public/static/web/js/live.im.js b/public/static/web/js/live.im.js
new file mode 100644
index 00000000..255778f1
--- /dev/null
+++ b/public/static/web/js/live.im.js
@@ -0,0 +1,96 @@
+layui.use(['jquery', 'layim'], function () {
+
+ var $ = layui.jquery;
+ var layim = layui.layim;
+
+ var socket = new WebSocket('ws://127.0.0.1:8282');
+
+ var membersUrl = $('input[name="im.members_url"]').val();
+ var bindUserUrl = $('input[name="im.bind_user_url"]').val();
+ var sendMsgUrl = $('input[name="im.send_msg_url"]').val();
+
+ var group = {
+ id: $('input[name="chapter.id"]').val(),
+ avatar: 'http://tp1.sinaimg.cn/5619439268/180/40030060651/1',
+ name: '直播讨论'
+ };
+
+ var user = {
+ id: $('input[name="user.id"]').val(),
+ name: $('input[name="user.name"]').val(),
+ avatar: $('input[name="user.avatar"]').val(),
+ status: 'online',
+ sign: ''
+ };
+
+ layim.config({
+ brief: true,
+ init: {
+ mine: {
+ 'username': user.name,
+ 'avatar': user.avatar,
+ 'id': user.id,
+ 'status': user.status,
+ 'sign': user.sign
+ }
+ },
+ members: {
+ url: membersUrl
+ }
+ }).chat({
+ type: 'group',
+ name: group.name,
+ avatar: group.avatar,
+ id: group.id
+ });
+
+ layim.on('sendMessage', function (res) {
+ sendMessage(res.mine, res.to);
+ });
+
+ socket.onopen = function () {
+ console.log('socket connect success');
+ };
+
+ socket.onclose = function () {
+ console.log('socket connect close');
+ };
+
+ socket.onerror = function () {
+ console.log('socket connect error');
+ };
+
+ socket.onmessage = function (e) {
+ var data = JSON.parse(e.data);
+ console.log(data);
+ if (data.type === 'ping') {
+ socket.send('pong...');
+ } else if (data.type === 'bind_user') {
+ bindUser(data.client_id);
+ } else if (data.type === 'show_message') {
+ showMessage(data.content);
+ }
+ };
+
+ function bindUser(clientId) {
+ $.ajax({
+ type: 'POST',
+ url: bindUserUrl,
+ data: {client_id: clientId}
+ });
+ }
+
+ function sendMessage(from, to) {
+ $.ajax({
+ type: 'POST',
+ dataType: 'json',
+ url: sendMsgUrl,
+ data: {from: from, to: to}
+ });
+ }
+
+ function showMessage(message) {
+ layim.getMessage(message);
+ }
+
+});
\ No newline at end of file
diff --git a/public/static/web/js/live.player.js b/public/static/web/js/live.player.js
new file mode 100644
index 00000000..7fe8f0d0
--- /dev/null
+++ b/public/static/web/js/live.player.js
@@ -0,0 +1,104 @@
+var interval = null;
+var intervalTime = 5000;
+var position = 0;
+var chapterId = $('input[name="chapter.id"]').val();
+var planId = $('input[name="chapter.plan_id"]').val();
+var userId = $('input[name="user.id"]').val();
+var learningUrl = $('input[name="chapter.learning_url"]').val();
+var playUrls = JSON.parse($('input[name="chapter.play_urls"]').val());
+var requestId = getRequestId();
+
+var options = {
+ live: true,
+ autoplay: true,
+ h5_flv: true,
+ width: 800,
+ height: 450
+};
+
+if (playUrls.rtmp && playUrls.rtmp.od) {
+ options.rtmp = playUrls.rtmp.od;
+}
+
+if (playUrls.rtmp && playUrls.rtmp.hd) {
+ options.rtmp_hd = playUrls.rtmp.hd;
+}
+
+if (playUrls.rtmp && playUrls.rtmp.sd) {
+ options.rtmp_sd = playUrls.rtmp.sd;
+}
+
+if (playUrls.flv && playUrls.flv.od) {
+ options.flv = playUrls.flv.od;
+}
+
+if (playUrls.flv && playUrls.flv.hd) {
+ options.flv_hd = playUrls.flv.hd;
+}
+
+if (playUrls.flv && playUrls.flv.sd) {
+ options.flv_sd = playUrls.flv.sd;
+}
+
+if (playUrls.m3u8 && playUrls.m3u8.od) {
+ options.m3u8 = playUrls.m3u8.od;
+}
+
+if (playUrls.m3u8 && playUrls.m3u8.hd) {
+ options.m3u8_hd = playUrls.m3u8.hd;
+}
+
+if (playUrls.m3u8 && playUrls.m3u8.sd) {
+ options.m3u8_sd = playUrls.m3u8.sd;
+}
+
+if (userId !== '0' && planId !== '0') {
+ options.listener = function (msg) {
+ if (msg.type === 'play') {
+ start();
+ } else if (msg.type === 'pause') {
+ stop();
+ } else if (msg.type === 'end') {
+ stop();
+ }
+ }
+}
+
+var player = new TcPlayer('player', options);
+
+if (position > 0) {
+ player.currentTime(position);
+}
+
+function start() {
+ if (interval != null) {
+ clearInterval(interval);
+ interval = null;
+ }
+ interval = setInterval(learning, intervalTime);
+}
+
+function stop() {
+ clearInterval(interval);
+ interval = null;
+}
+
+function learning() {
+ $.ajax({
+ type: 'POST',
+ url: learningUrl,
+ data: {
+ request_id: requestId,
+ chapter_id: chapterId,
+ plan_id: planId,
+ interval: intervalTime,
+ position: player.currentTime(),
+ }
+ });
+}
+
+function getRequestId() {
+ var id = Date.now().toString(36);
+ id += Math.random().toString(36).substr(3);
+ return id;
+}
\ No newline at end of file
diff --git a/websocket/Events.php b/websocket/Events.php
index e6ad77cd..15dadcb7 100644
--- a/websocket/Events.php
+++ b/websocket/Events.php
@@ -38,8 +38,8 @@ class Events
public static function onConnect($clientId)
{
$message = json_encode([
- 'type' => 'welcome',
- 'message' => 'just enjoy it',
+ 'type' => 'bind_user',
+ 'client_id' => $clientId,
]);
Gateway::sendToClient($clientId, $message);
@@ -53,25 +53,7 @@ class Events
*/
public static function onMessage($clientId, $message)
{
- $content = json_decode($message, true);
- if (!isset($content['type'])) return;
-
- if ($content['type'] == 'join_group') {
-
- $_SESSION['group'] = $content['group'];
-
- Gateway::joinGroup($clientId, $content['group']);
-
- } elseif ($content['type'] == 'send_danmaku') {
-
- $message = [
- 'type' => 'show_danmaku',
- 'danmaku' => $content['danmaku'],
- ];
-
- Gateway::sendToGroup($_SESSION['group'], json_encode($message), [$clientId]);
- }
}
/**