1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-30 06:11:38 +08:00

完善直播推流和拉流

This commit is contained in:
xiaochong0302 2020-06-16 20:11:59 +08:00
parent 98e6a69e4a
commit 2dee6efb04
13 changed files with 445 additions and 146 deletions

View File

@ -68,9 +68,11 @@ class TestController extends Controller
*/ */
public function livePushAction() public function livePushAction()
{ {
$streamName = $this->request->getQuery('stream');
$liveService = new LiveService(); $liveService = new LiveService();
$pushUrl = $liveService->getPushUrl('test'); $pushUrl = $liveService->getPushUrl($streamName);
$codeUrl = $this->url->get( $codeUrl = $this->url->get(
['for' => 'web.qrcode_img'], ['for' => 'web.qrcode_img'],
@ -95,14 +97,11 @@ class TestController extends Controller
{ {
$liveService = new LiveService(); $liveService = new LiveService();
$m3u8PullUrls = $liveService->getPullUrls('test', 'm3u8'); $pullUrls = $liveService->getPullUrls('test');
$flvPullUrls = $liveService->getPullUrls('test', 'flv');
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
$this->view->pick('public/live_player'); $this->view->pick('public/live_player');
$this->view->setVar('m3u8_pull_urls', $m3u8PullUrls); $this->view->setVar('pull_urls', $pullUrls);
$this->view->setVar('flv_pull_urls', $flvPullUrls);
} }
/** /**

View File

@ -32,10 +32,35 @@
</form> </form>
<form class="layui-form kg-form">
<fieldset class="layui-elem-field layui-field-title">
<legend>推流测试</legend>
</fieldset>
<div class="layui-form-item">
<label class="layui-form-label">Stream Name</label>
<div class="layui-input-block">
<input class="layui-input" type="text" name="stream_name" value="chapter_{{ chapter.id }}" readonly="readonly">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"></label>
<div class="layui-input-block">
<button type="button" class="layui-btn" id="show-push-test">提交</button>
<button type="button" class="kg-back layui-btn layui-btn-primary">返回</button>
</div>
</div>
</form>
<script> <script>
layui.use(['laydate'], function () { layui.use(['jquery', 'layer', 'laydate'], function () {
var $ = layui.jquery;
var layer = layui.layer;
var laydate = layui.laydate; var laydate = layui.laydate;
laydate.render({ laydate.render({
@ -48,6 +73,18 @@
type: 'datetime' type: 'datetime'
}); });
$('#show-push-test').on('click', function () {
var streamName = $('input[name=stream_name]').val();
var url = '/admin/test/live/push?stream=' + streamName;
layer.open({
type: 2,
title: '推流测试',
resize: false,
area: ['680px', '380px'],
content: [url, 'no']
});
});
}); });
</script> </script>

View File

@ -19,20 +19,52 @@
<script> <script>
var flvPullUrls = '{{ flv_pull_urls|json_encode }}'; var playUrls = JSON.parse('{{ pull_urls|json_encode }}');
var flv = JSON.parse(flvPullUrls);
var config = { var options = {
flv: flv.od,
flv_sd: flv.sd,
flv_hd: flv.hd,
live: true, live: true,
h5_flv: true,
autoplay: true, autoplay: true,
clarity: 'hd', h5_flv: true,
width: 720, width: 720,
height: 405 height: 405
}; };
var player = new TcPlayer('player', config); 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;
}
var player = new TcPlayer('player', options);
</script> </script>

View File

@ -26,24 +26,25 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">开启鉴权</label> <label class="layui-form-label">开启鉴权</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="radio" name="pull_auth_enabled" value="1" title="是" {% if live.pull_auth_enabled == 1 %}checked{% endif %}> <input type="radio" name="pull_auth_enabled" value="1" title="是" lay-filter="pull_auth_enabled" {% if live.pull_auth_enabled == 1 %}checked{% endif %}>
<input type="radio" name="pull_auth_enabled" value="0" title="否" {% if live.pull_auth_enabled == 0 %}checked{% endif %}> <input type="radio" name="pull_auth_enabled" value="0" title="否" lay-filter="pull_auth_enabled" {% if live.pull_auth_enabled == 0 %}checked{% endif %}>
</div> </div>
</div> </div>
<div id="pull-auth-block" {% if live.pull_auth_enabled == '0' %}style="display:none;"{% endif %}>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">鉴权密钥</label> <label class="layui-form-label">鉴权密钥</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" type="text" name="pull_auth_key" value="{{ live.pull_auth_key }}"> <input class="layui-input" type="text" name="pull_auth_key" value="{{ live.pull_auth_key }}">
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">有效时间(秒)</label> <label class="layui-form-label">有效时间(秒)</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" type="text" name="pull_auth_delta" value="{{ live.pull_auth_delta }}"> <input class="layui-input" type="text" name="pull_auth_delta" value="{{ live.pull_auth_delta }}">
</div> </div>
</div> </div>
</div>
<fieldset class="layui-elem-field layui-field-title"> <fieldset class="layui-elem-field layui-field-title">
<legend>转码配置</legend> <legend>转码配置</legend>
@ -52,12 +53,12 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">开启转码</label> <label class="layui-form-label">开启转码</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="radio" name="pull_trans_enabled" value="1" title="是" {% if live.pull_trans_enabled == 1 %}checked{% endif %}> <input type="radio" name="pull_trans_enabled" value="1" title="是" lay-filter="pull_trans_enabled" {% if live.pull_trans_enabled == 1 %}checked{% endif %}>
<input type="radio" name="pull_trans_enabled" value="0" title="否" {% if live.pull_trans_enabled == 0 %}checked{% endif %}> <input type="radio" name="pull_trans_enabled" value="0" title="否" lay-filter="pull_trans_enabled" {% if live.pull_trans_enabled == 0 %}checked{% endif %}>
</div> </div>
</div> </div>
<table class="kg-table layui-table layui-form"> <table class="kg-table layui-table layui-form" id="ptt-block" {% if live.pull_trans_enabled == '0' %}style="display:none;"{% endif %}>
<colgroup> <colgroup>
<col> <col>
<col> <col>
@ -74,22 +75,22 @@
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td><input class="layui-input" type="text" name="ptt[id][fd]" value="{{ ptt.fd.id }}" readonly="true"></td> <td><input class="layui-input" type="text" name="ptt[id][fd]" value="{{ ptt.fd.id }}" readonly="readonly"></td>
<td><input class="layui-input" type="text" name="ptt[summary][fd]" value="{{ ptt.fd.summary }}" readonly="true"></td> <td><input class="layui-input" type="text" name="ptt[summary][fd]" value="{{ ptt.fd.summary }}" readonly="readonly"></td>
<td><input class="layui-input" type="text" name="ptt[bit_rate][fd]" value="{{ ptt.fd.bit_rate }}" readonly="true"></td> <td><input class="layui-input" type="text" name="ptt[bit_rate][fd]" value="{{ ptt.fd.bit_rate }}" readonly="readonly"></td>
<td><input class="layui-input" type="text" name="ptt[height][fd]" value="{{ ptt.fd.height }}" readonly="true"></td> <td><input class="layui-input" type="text" name="ptt[height][fd]" value="{{ ptt.fd.height }}" readonly="readonly"></td>
</tr> </tr>
<tr> <tr>
<td><input class="layui-input" type="text" name="ptt[id][sd]" value="{{ ptt.sd.id }}" readonly="true"></td> <td><input class="layui-input" type="text" name="ptt[id][sd]" value="{{ ptt.sd.id }}" readonly="readonly"></td>
<td><input class="layui-input" type="text" name="ptt[summary][sd]" value="{{ ptt.sd.summary }}" readonly="true"></td> <td><input class="layui-input" type="text" name="ptt[summary][sd]" value="{{ ptt.sd.summary }}" readonly="readonly"></td>
<td><input class="layui-input" type="text" name="ptt[bit_rate][sd]" value="{{ ptt.sd.bit_rate }}" readonly="true"></td> <td><input class="layui-input" type="text" name="ptt[bit_rate][sd]" value="{{ ptt.sd.bit_rate }}" readonly="readonly"></td>
<td><input class="layui-input" type="text" name="ptt[height][sd]" value="{{ ptt.sd.height }}" readonly="true"></td> <td><input class="layui-input" type="text" name="ptt[height][sd]" value="{{ ptt.sd.height }}" readonly="readonly"></td>
</tr> </tr>
<tr> <tr>
<td><input class="layui-input" type="text" name="ptt[id][hd]" value="{{ ptt.hd.id }}" readonly="true"></td> <td><input class="layui-input" type="text" name="ptt[id][hd]" value="{{ ptt.hd.id }}" readonly="readonly"></td>
<td><input class="layui-input" type="text" name="ptt[summary][hd]" value="{{ ptt.hd.summary }}" readonly="true"></td> <td><input class="layui-input" type="text" name="ptt[summary][hd]" value="{{ ptt.hd.summary }}" readonly="readonly"></td>
<td><input class="layui-input" type="text" name="ptt[bit_rate][hd]" value="{{ ptt.hd.bit_rate }}" readonly="true"></td> <td><input class="layui-input" type="text" name="ptt[bit_rate][hd]" value="{{ ptt.hd.bit_rate }}" readonly="readonly"></td>
<td><input class="layui-input" type="text" name="ptt[height][hd]" value="{{ ptt.hd.height }}" readonly="true"></td> <td><input class="layui-input" type="text" name="ptt[height][hd]" value="{{ ptt.hd.height }}" readonly="readonly"></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -113,7 +114,7 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">Stream Name</label> <label class="layui-form-label">Stream Name</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" type="text" name="stream_name" value="test" readonly="true"> <input class="layui-input" type="text" name="stream_name" value="test" readonly="readonly">
</div> </div>
</div> </div>
@ -129,11 +130,30 @@
<script> <script>
layui.use(['jquery', 'layer'], function () { layui.use(['jquery', 'form', 'layer'], function () {
var $ = layui.jquery; var $ = layui.jquery;
var form = layui.form;
var layer = layui.layer; var layer = layui.layer;
form.on('radio(pull_auth_enabled)', function (data) {
var block = $('#pull-auth-block');
if (data.value === '1') {
block.show();
} else {
block.hide();
}
});
form.on('radio(pull_trans_enabled)', function (data) {
var block = $('#ptt-block');
if (data.value === '1') {
block.show();
} else {
block.hide();
}
});
$('#show-pull-test').on('click', function () { $('#show-pull-test').on('click', function () {
var url = '/admin/test/live/pull'; var url = '/admin/test/live/pull';
layer.open({ layer.open({

View File

@ -18,24 +18,25 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">开启鉴权</label> <label class="layui-form-label">开启鉴权</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="radio" name="push_auth_enabled" value="1" title="是" {% if live.push_auth_enabled == 1 %}checked{% endif %}> <input type="radio" name="push_auth_enabled" value="1" title="是" lay-filter="push_auth_enabled" {% if live.push_auth_enabled == 1 %}checked{% endif %}>
<input type="radio" name="push_auth_enabled" value="0" title="否" {% if live.push_auth_enabled == 0 %}checked{% endif %}> <input type="radio" name="push_auth_enabled" value="0" title="否" lay-filter="push_auth_enabled" {% if live.push_auth_enabled == 0 %}checked{% endif %}>
</div> </div>
</div> </div>
<div id="push-auth-block" {% if live.push_auth_enabled == '0' %}style="display:none;"{% endif %}>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">鉴权密钥</label> <label class="layui-form-label">鉴权密钥</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" type="text" name="push_auth_key" value="{{ live.push_auth_key }}"> <input class="layui-input" type="text" name="push_auth_key" value="{{ live.push_auth_key }}">
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">有效时间(秒)</label> <label class="layui-form-label">有效时间(秒)</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" type="text" name="push_auth_delta" value="{{ live.push_auth_delta }}"> <input class="layui-input" type="text" name="push_auth_delta" value="{{ live.push_auth_delta }}">
</div> </div>
</div> </div>
</div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label"></label> <label class="layui-form-label"></label>
@ -56,7 +57,7 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">Stream Name</label> <label class="layui-form-label">Stream Name</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" type="text" name="stream_name" value="test" readonly="true"> <input class="layui-input" type="text" name="stream_name" value="test" readonly="readonly">
</div> </div>
</div> </div>
@ -72,13 +73,23 @@
<script> <script>
layui.use(['jquery', 'layer'], function () { layui.use(['jquery', 'form', 'layer'], function () {
var $ = layui.jquery; var $ = layui.jquery;
var form = layui.form;
var layer = layui.layer; var layer = layui.layer;
form.on('radio(push_auth_enabled)', function (data) {
var block = $('#push-auth-block');
if (data.value === '1') {
block.show();
} else {
block.hide();
}
});
$('#show-push-test').on('click', function () { $('#show-push-test').on('click', function () {
var url = '/admin/test/live/push'; var url = '/admin/test/live/push?stream=test';
layer.open({ layer.open({
type: 2, type: 2,
title: '推流测试', title: '推流测试',

View File

@ -7,18 +7,19 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">存储方式</label> <label class="layui-form-label">存储方式</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="radio" name="storage_type" value="nearby" title="就近存储" lay-filter="storage-type" {% if vod.storage_type == "nearby" %}checked{% endif %}> <input type="radio" name="storage_type" value="nearby" title="就近存储" lay-filter="storage_type" {% if vod.storage_type == "nearby" %}checked{% endif %}>
<input type="radio" name="storage_type" value="fixed" title="固定区域" lay-filter="storage-type" {% if vod.storage_type == "fixed" %}checked{% endif %}> <input type="radio" name="storage_type" value="fixed" title="固定区域" lay-filter="storage_type" {% if vod.storage_type == "fixed" %}checked{% endif %}>
</div> </div>
</div> </div>
<div id="storage-region-block" class="layui-form-item" {% if vod.storage_type == 'nearby' %}style="display:none;"{% endif %}> <div id="storage-region-block" {% if vod.storage_type == 'nearby' %}style="display:none;"{% endif %}>
<div class="layui-form-item">
<label class="layui-form-label">所在区域</label> <label class="layui-form-label">所在区域</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" type="text" name="storage_region" value="{{ vod.storage_region }}"> <input class="layui-input" type="text" name="storage_region" value="{{ vod.storage_region }}">
</div> </div>
</div> </div>
</div>
<fieldset class="layui-elem-field layui-field-title"> <fieldset class="layui-elem-field layui-field-title">
<legend>转码配置</legend> <legend>转码配置</legend>
@ -27,47 +28,49 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">视频格式</label> <label class="layui-form-label">视频格式</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="radio" name="video_format" value="hls" title="HLS" lay-filter="video-format" {% if vod.video_format == "hls" %}checked{% endif %}> <input type="radio" name="video_format" value="hls" title="HLS" lay-filter="video_format" {% if vod.video_format == "hls" %}checked{% endif %}>
<input type="radio" name="video_format" value="mp4" title="MP4" lay-filter="video-format" {% if vod.video_format == "mp4" %}checked{% endif %}> <input type="radio" name="video_format" value="mp4" title="MP4" lay-filter="video_format" {% if vod.video_format == "mp4" %}checked{% endif %}>
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">视频模板ID</label> <label class="layui-form-label">视频模板ID</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" type="text" name="video_template" readonly="true" layui-verify="required"> <input class="layui-input" type="text" name="video_template" readonly="readonly" layui-verify="required">
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">音频格式</label> <label class="layui-form-label">音频格式</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="radio" name="audio_format" value="m4a" title="M4A" lay-filter="audio-format" {% if vod.audio_format == "m4a" %}checked{% endif %}> <input type="radio" name="audio_format" value="m4a" title="M4A" lay-filter="audio_format" {% if vod.audio_format == "m4a" %}checked{% endif %}>
<input type="radio" name="audio_format" value="mp3" title="MP3" lay-filter="audio-format" {% if vod.audio_format == "mp3" %}checked{% endif %}> <input type="radio" name="audio_format" value="mp3" title="MP3" lay-filter="audio_format" {% if vod.audio_format == "mp3" %}checked{% endif %}>
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">音频模板ID</label> <label class="layui-form-label">音频模板ID</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" type="text" name="audio_template" readonly="true" layui-verify="required"> <input class="layui-input" type="text" name="audio_template" readonly="readonly" layui-verify="required">
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">开启水印</label> <label class="layui-form-label">开启水印</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="radio" name="watermark_enabled" value="1" title="是" lay-filter="watermark-enabled" {% if vod.watermark_enabled == 1 %}checked{% endif %}> <input type="radio" name="watermark_enabled" value="1" title="是" lay-filter="watermark_enabled" {% if vod.watermark_enabled == 1 %}checked{% endif %}>
<input type="radio" name="watermark_enabled" value="0" title="否" lay-filter="watermark-enabled" {% if vod.watermark_enabled == 0 %}checked{% endif %}> <input type="radio" name="watermark_enabled" value="0" title="否" lay-filter="watermark_enabled" {% if vod.watermark_enabled == 0 %}checked{% endif %}>
</div> </div>
</div> </div>
<div id="watermark-template-block" class="layui-form-item" {% if vod.watermark_enabled == 0 %}style="display:none;"{% endif %}> <div id="watermark-template-block" {% if vod.watermark_enabled == '0' %}style="display:none;"{% endif %}>
<div class="layui-form-item">
<label class="layui-form-label">水印模板ID</label> <label class="layui-form-label">水印模板ID</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" type="text" name="watermark_template" value="{{ vod.watermark_template }}"> <input class="layui-input" type="text" name="watermark_template" value="{{ vod.watermark_template }}">
</div> </div>
</div> </div>
</div>
<fieldset class="layui-elem-field layui-field-title"> <fieldset class="layui-elem-field layui-field-title">
<legend>主分发配置</legend> <legend>主分发配置</legend>
@ -95,12 +98,12 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">开启防盗链</label> <label class="layui-form-label">开启防盗链</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="radio" name="key_anti_enabled" value="1" title="是" lay-filter="key-anti-enabled" {% if vod.key_anti_enabled == 1 %}checked{% endif %}> <input type="radio" name="key_anti_enabled" value="1" title="是" lay-filter="key_anti_enabled" {% if vod.key_anti_enabled == 1 %}checked{% endif %}>
<input type="radio" name="key_anti_enabled" value="0" title="否" lay-filter="key-anti-enabled" {% if vod.key_anti_enabled == 0 %}checked{% endif %}> <input type="radio" name="key_anti_enabled" value="0" title="否" lay-filter="key_anti_enabled" {% if vod.key_anti_enabled == 0 %}checked{% endif %}>
</div> </div>
</div> </div>
<div id="key-anti-block" class="layui-form-item" {% if vod.key_anti_enabled == 0 %}style="display:none;"{% endif %}> <div id="key-anti-block" {% if vod.key_anti_enabled == '0' %}style="display:none;"{% endif %}>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">防盗链Key</label> <label class="layui-form-label">防盗链Key</label>
<div class="layui-input-block"> <div class="layui-input-block">
@ -134,7 +137,7 @@
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">请求方法</label> <label class="layui-form-label">请求方法</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input class="layui-input" type="text" name="file" value="DescribeAudioTrackTemplates" readonly="true"> <input class="layui-input" type="text" name="file" value="DescribeAudioTrackTemplates" readonly="readonly">
</div> </div>
</div> </div>
@ -173,7 +176,7 @@
} }
}; };
form.on('radio(storage-type)', function (data) { form.on('radio(storage_type)', function (data) {
var block = $('#storage-region-block'); var block = $('#storage-region-block');
if (data.value === 'fixed') { if (data.value === 'fixed') {
block.show(); block.show();
@ -182,29 +185,29 @@
} }
}); });
form.on('radio(watermark-enabled)', function (data) { form.on('radio(watermark_enabled)', function (data) {
var block = $('#watermark-template-block'); var block = $('#watermark-template-block');
if (data.value === 1) { if (data.value === '1') {
block.show(); block.show();
} else { } else {
block.hide(); block.hide();
} }
}); });
form.on('radio(key-anti-enabled)', function (data) { form.on('radio(key_anti_enabled)', function (data) {
var block = $('#key-anti-block'); var block = $('#key-anti-block');
if (data.value === 1) { if (data.value === '1') {
block.show(); block.show();
} else { } else {
block.hide(); block.hide();
} }
}); });
form.on('radio(video-format)', function (data) { form.on('radio(video_format)', function (data) {
changeVideoTemplate(data.value); changeVideoTemplate(data.value);
}); });
form.on('radio(audio-format)', function (data) { form.on('radio(audio_format)', function (data) {
changeAudioTemplate(data.value); changeAudioTemplate(data.value);
}); });

View File

@ -0,0 +1,48 @@
<?php
namespace App\Http\Web\Controllers;
class LiveController extends Controller
{
/**
* @Get("/stats", name="web.live.stats")
*/
public function statsAction()
{
}
/**
* @Get("/users", name="web.live.users")
*/
public function usersAction()
{
}
/**
* @Post("/login", name="web.live.login")
*/
public function loginAction()
{
}
/**
* @Post("/logout", name="web.live.logout")
*/
public function logoutAction()
{
}
/**
* @Post("/message", name="web.live.message")
*/
public function messageAction()
{
}
}

View File

@ -0,0 +1,154 @@
{% extends 'templates/full.volt' %}
{% block content %}
{% set course_url = url({'for':'web.course.show','id':chapter.course.id}) %}
<div class="breadcrumb">
<span class="layui-breadcrumb">
<span><i class="layui-icon layui-icon-return"></i> <a href="{{ course_url }}">返回课程主页</a></span>
</span>
</div>
<div class="layout-main clearfix">
<div class="layout-content">
<div id="player" class="container"></div>
</div>
<div class="layout-sidebar">
<div class="sidebar-online container">
<div class="layui-tab layui-tab-brief">
<ul class="layui-tab-title">
<li class="layui-this">讨论</li>
<li>成员</li>
</ul>
<div class="layui-tab-content">
<div class="layui-tab-item layui-show" id="tab-comments" data-url="#"></div>
<div class="layui-tab-item" id="tab-users" data-url="#"></div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block include_js %}
<script src="//imgcache.qq.com/open/qcloud/video/vcplayer/TcPlayer-2.3.2.js"></script>
{% endblock %}
{% block inline_js %}
<script>
var interval = null;
var intervalTime = 5000;
var position = 0;
var chapterId = '{{ chapter.id }}';
var courseId = '{{ chapter.course.id }}';
var planId = '{{ chapter.me.plan_id }}';
var userId = '{{ auth_user.id }}';
var requestId = getRequestId();
var playUrls = JSON.parse('{{ chapter.play_urls|json_encode }}');
var options = {
live: true,
autoplay: true,
h5_flv: true,
width: 760,
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: '/learning',
data: {
request_id: requestId,
chapter_id: chapterId,
course_id: courseId,
user_id: userId,
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;
}
</script>
{% endblock %}

View File

@ -22,10 +22,14 @@
{% endblock %} {% endblock %}
{% block inline_js %} {% block include_js %}
<script src="//imgcache.qq.com/open/qcloud/video/vcplayer/TcPlayer-2.3.2.js"></script> <script src="//imgcache.qq.com/open/qcloud/video/vcplayer/TcPlayer-2.3.2.js"></script>
{% endblock %}
{% block inline_js %}
<script> <script>
var interval = null; var interval = null;
@ -41,28 +45,22 @@
var options = { var options = {
autoplay: false, autoplay: false,
width: 760, width: 760,
height: 450, height: 450
clarity: 'hd',
clarityLabel: {
od: '高清',
hd: '标清',
sd: '流畅'
}
}; };
if ('hd' in playUrls) { if (playUrls.od) {
options.m3u8 = playUrls.hd.url; options.m3u8 = playUrls.od.url;
} }
if ('sd' in playUrls) { if (playUrls.hd) {
options.m3u8_hd = playUrls.sd.url; options.m3u8_hd = playUrls.hd.url;
} }
if ('fd' in playUrls) { if (playUrls.sd) {
options.m3u8_sd = playUrls.fd.url; options.m3u8_sd = playUrls.sd.url;
} }
if (userId !== '0') { if (userId !== '0' && planId !== '0') {
options.listener = function (msg) { options.listener = function (msg) {
if (msg.type === 'play') { if (msg.type === 'play') {
start(); start();

View File

@ -15,7 +15,6 @@ use App\Services\Frontend\ChapterTrait;
use App\Services\Frontend\CourseTrait; use App\Services\Frontend\CourseTrait;
use App\Services\Frontend\Service as FrontendService; use App\Services\Frontend\Service as FrontendService;
use App\Services\Live as LiveService; use App\Services\Live as LiveService;
use WhichBrowser\Parser as BrowserParser;
class ChapterInfo extends FrontendService class ChapterInfo extends FrontendService
{ {
@ -151,21 +150,9 @@ class ChapterInfo extends FrontendService
protected function formatChapterLive(ChapterModel $chapter) protected function formatChapterLive(ChapterModel $chapter)
{ {
$headers = getallheaders();
$browserParser = new BrowserParser($headers);
$liveService = new LiveService(); $liveService = new LiveService();
$stream = "chapter-{$chapter->id}"; $playUrls = $liveService->getPullUrls("chapter_{$chapter->id}");
$format = $browserParser->isType('desktop') ? 'flv' : 'hls';
$playUrls = $liveService->getPullUrls($stream, $format);
$chapterRepo = new ChapterRepo();
$live = $chapterRepo->findChapterLive($chapter->id);
/** /**
* @var array $attrs * @var array $attrs
@ -177,9 +164,9 @@ class ChapterInfo extends FrontendService
'title' => $chapter->title, 'title' => $chapter->title,
'summary' => $chapter->summary, 'summary' => $chapter->summary,
'model' => $attrs['model'], 'model' => $attrs['model'],
'start_time' => $attrs['start_time'],
'end_time' => $attrs['end_time'],
'play_urls' => $playUrls, 'play_urls' => $playUrls,
'start_time' => $live->start_time,
'end_time' => $live->end_time,
'user_count' => $chapter->user_count, 'user_count' => $chapter->user_count,
'agree_count' => $chapter->agree_count, 'agree_count' => $chapter->agree_count,
'oppose_count' => $chapter->oppose_count, 'oppose_count' => $chapter->oppose_count,
@ -231,6 +218,8 @@ class ChapterInfo extends FrontendService
$this->courseUser = $courseUser; $this->courseUser = $courseUser;
$this->joinedCourse = true;
$this->incrCourseUserCount($course); $this->incrCourseUserCount($course);
} }
@ -238,10 +227,12 @@ class ChapterInfo extends FrontendService
{ {
if ($user->id == 0) return; if ($user->id == 0) return;
if ($this->joinedChapter) return; if (!$this->joinedCourse) return;
if (!$this->ownedChapter) return; if (!$this->ownedChapter) return;
if ($this->joinedChapter) return;
$chapterUser = new ChapterUserModel(); $chapterUser = new ChapterUserModel();
$chapterUser->plan_id = $this->courseUser->plan_id; $chapterUser->plan_id = $this->courseUser->plan_id;
@ -253,6 +244,8 @@ class ChapterInfo extends FrontendService
$this->chapterUser = $chapterUser; $this->chapterUser = $chapterUser;
$this->joinedChapter = true;
$this->incrChapterUserCount($chapter); $this->incrChapterUserCount($chapter);
} }

View File

@ -41,21 +41,11 @@ class Live extends Service
* 获取拉流地址 * 获取拉流地址
* *
* @param string $streamName * @param string $streamName
* @param string $format * @param string $appName
* @return mixed * @return mixed
*/ */
public function getPullUrls($streamName, $format) public function getPullUrls($streamName, $appName = 'live')
{ {
$extension = ($format == 'hls') ? 'm3u8' : $format;
$extensions = ['flv', 'm3u8'];
if (!in_array($extension, $extensions)) {
return null;
}
$appName = 'live';
$protocol = $this->settings['pull_protocol']; $protocol = $this->settings['pull_protocol'];
$domain = $this->settings['pull_domain']; $domain = $this->settings['pull_domain'];
$authEnabled = $this->settings['pull_auth_enabled']; $authEnabled = $this->settings['pull_auth_enabled'];
@ -63,30 +53,44 @@ class Live extends Service
$authKey = $this->settings['pull_auth_key']; $authKey = $this->settings['pull_auth_key'];
$expireTime = $this->settings['pull_auth_delta'] + time(); $expireTime = $this->settings['pull_auth_delta'] + time();
$formats = ['rtmp', 'flv', 'm3u8'];
$urls = []; $urls = [];
if ($transEnabled) { if ($transEnabled) {
foreach (['fd', 'sd', 'hd', 'od'] as $rateName) { foreach ($formats as $format) {
$realStreamName = ($rateName == 'od') ? $streamName : "{$streamName}_{$rateName}"; foreach (['od', 'hd', 'sd', 'fd'] as $rateName) {
$realStreamName = $rateName == 'od' ? $streamName : "{$streamName}_{$rateName}";
$authParams = $this->getAuthParams($realStreamName, $authKey, $expireTime); $authParams = $this->getAuthParams($realStreamName, $authKey, $expireTime);
$url = "{$protocol}://{$domain}/{$appName}/{$realStreamName}.{$extension}"; $extension = $format != 'rtmp' ? ".{$format}" : '';
$realProtocol = $format != 'rtmp' ? $protocol : 'rtmp';
$url = "{$realProtocol}://{$domain}/{$appName}/{$realStreamName}{$extension}";
$url .= $authEnabled ? "?{$authParams}" : ''; $url .= $authEnabled ? "?{$authParams}" : '';
$urls[$rateName] = $url; $urls[$format][$rateName] = $url;
}
} }
} else { } else {
foreach ($formats as $format) {
$authParams = $this->getAuthParams($streamName, $authKey, $expireTime); $authParams = $this->getAuthParams($streamName, $authKey, $expireTime);
$url = "{$protocol}://{$domain}/{$appName}/{$streamName}.{$extension}"; $extension = $format != 'rtmp' ? ".{$format}" : '';
$realProtocol = $format != 'rtmp' ? $protocol : 'rtmp';
$url = "{$realProtocol}://{$domain}/{$appName}/{$streamName}{$extension}";
$url .= $authEnabled ? "?{$authParams}" : ''; $url .= $authEnabled ? "?{$authParams}" : '';
$urls['od'] = $url; $urls[$format]['od'] = $url;
}
} }
return $urls; return $urls;

View File

@ -23,7 +23,7 @@ require_once dirname(__DIR__) . '/vendor/autoload.php';
$worker = new BusinessWorker(); $worker = new BusinessWorker();
// worker名称 // worker名称
$worker->name = 'DanmakuBusinessWorker'; $worker->name = 'CourseBusinessWorker';
// businessWorker进程数量 // businessWorker进程数量
$worker->count = 4; $worker->count = 4;

View File

@ -23,7 +23,7 @@ require_once dirname(__DIR__) . '/vendor/autoload.php';
$gateway = new Gateway("websocket://0.0.0.0:8282"); $gateway = new Gateway("websocket://0.0.0.0:8282");
// gateway名称status方便查看 // gateway名称status方便查看
$gateway->name = 'DanmakuGateway'; $gateway->name = 'CourseGateway';
// gateway进程数 // gateway进程数
$gateway->count = 4; $gateway->count = 4;