Authored by wuxiao

后台房间结束推送按钮

... ... @@ -18,4 +18,13 @@ class AjaxController extends BaseController
$log = Yii::$app->redisIm->rpop(Yii::$app->params['cache_prefix'].'push_goods_log');
$this->renderJson(Yii::$app->params['success_code'],'',(string)$log);
}
/**
* 将房间结束直播
*/
public function actionStopliving()
{
$room_id = Yii::$app->request->get('room_id');
$this->renderJson(Yii::$app->params['success_code'],'',$room_id);
}
}
... ...
... ... @@ -70,15 +70,10 @@ class ProductController extends BaseController
}
}
//推送服务地址
$wsAddrs = (new \common\models\SysConfig)->getServerAddr();
$wsAddr = @ArrayHelper::getValue($wsAddrs, ['websocket',0]);
return $this->render('list',[
'room'=> \app\models\Room::findOne(['room_id'=>$room_id]),
'pagination'=>$pagination,
'list'=>$list,
'wsAddr'=>$wsAddr
]);
}
... ...
<?php
use yii\web\View;
use yii\helpers\ArrayHelper;
$this->registerJsFile('/js/php.js',array('postion'=>View::POS_END));
$this->registerJsFile('/js/common.js',array('position'=>View::POS_END));
?>
<?php
//推送服务地址
$wsAddrs = (new \common\models\SysConfig)->getServerAddr();
$wsAddr = @ArrayHelper::getValue($wsAddrs, ['websocket',0]);
?>
<script type="text/javascript">
<?php $this->beginBlock('javascript');?>
var socket_arr = '<?=$wsAddr?>'.split(":");
var wsAddr = socket_arr[0];
var port = socket_arr[1];
/**
* websocket推送指令
* @returns {undefined}
*/
function callWebsocket(sendCallback,afterSendCallback = function(){},errorSendCallback = function(){}){
if (!window.ws || window.ws.readyState === undefined || window.ws.readyState != 1) {
websocket(wsAddr,port,'/',function(){
consoleLog('连接服务器');
sendCallback();
},function(evt){
consoleLog('收到消息: '+evt.data);
data = JSON.parse(evt.data);
if (data.status == 1){
consoleLog('请求推送成功');
afterSendCallback();
}else{
consoleLog('请求推送失败');
errorSendCallback();
}
},function(){
consoleLog('连接已关闭');
},function(){
consoleLog('有错误出现');
});
}else{
sendCallback();
}
}
/**
* 页面打印发送记录
* @param {type} msg
* @returns {undefined}
*/
function consoleLog(msg){
if (msg){
console.log(msg);
}
if ($('#wsRuntime').size()){
$('#wsRuntime').append('&nbsp;'+msg+'<br />');
}
}
/**
* 密钥生成
* @param {type} package
* @returns {unresolved}
*/
function makeSign(package){
package['private_key'] = 'a85bb0674e08986c6b115d5e3a4884fa';
package = ksort(package);
packageList = [];
for (key in package){
packageList.push(trim(key + '=' + package[key]));
}
package['secret'] = strtolower(md5(implode('&', packageList)));
delete(package['private_key']);
return package;
}
<?php
$this->endBlock();
$this->registerJs($this->blocks['javascript'],View::POS_END)
?>
</script>
\ No newline at end of file
... ...
<?php
use yii\web\View;
use yii\helpers\Html;
use backend\widgets\LinkPager;
use backend\widgets\YHGImage\Common\Images as CommonImages;
... ... @@ -6,6 +7,48 @@ use backend\widgets\YHGImage\Common\Images as CommonImages;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<?php echo $this->render('@app/views/layouts/websocket');?>
<script type="text/javascript">
<?php $this->beginBlock('javascript');?>
/**
* 推送房间结束直播指令
* @returns {undefined}
*/
function stopLiving(room_id){
if (!confirm('将房间设为直播结束状态,确定?')){
return;
}
callWebsocket(function(){
consoleLog('');
consoleLog('发起房间结束直播指令');
cmd = {cmd:11,room:room_id,msg:'',videoLen:'10:23'};
cmd = makeSign(cmd);
cmd = JSON.stringify(cmd);
consoleLog('发送消息: '+cmd);
ws.send(cmd);
alert('指令已发送');
},function(){
$.get('/ajax/stopliving',{room_id:room_id},function(json){
console.log(json);
if (json.data){
consoleLog('监听到推送记录: '+json.data);
}
},'json');
alert('推送成功');
},function(){
alert('推送失败!');
});
}
<?php
$this->endBlock();
$this->registerJs($this->blocks['javascript'],View::POS_END)
?>
</script>
<div class="panel panel-default">
<div class="panel-body">
<form action="" method="GET" class="form-inline">
... ... @@ -63,6 +106,12 @@ $this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
</td>
<td>
<span>
<?php if ($model->living == 1)://直播中?>
<button type="button" onclick="stopLiving(<?=$model->room_id?>)" class="btn btn-danger btn-metro">结束直播</button>
<?php endif;?>
</span>
<a href="/live/roomedit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a>
<a href="/forbidden/index?room_id=<?=$model->room_id?>" class="btn btn-default btn-white">禁言</a>
... ... @@ -70,7 +119,7 @@ $this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
<a href="/product/list/<?=$model->room_id?>" class="btn btn-default btn-white">商品</a>
<span>
<?php if ($model->status == 0)://未开始?>
<?php if ($model->status == 0)://关闭状态?>
<a onclick="return confirm('启用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=enable" class="btn btn-success btn-metro">启用直播</a>
<a onclick="return confirm('删除直播间?')" href="/live/roomoperate/<?=$model->id?>?type=del" class="btn btn-danger btn-metro">删除</a>
<?php else:?>
... ...
... ... @@ -5,48 +5,18 @@ use backend\widgets\LinkPager;
$this->title = $this->params['main_title'].'-'.$this->params['sub_title'];
?>
<?php
$this->registerJsFile('/js/php.js',array('postion'=>View::POS_END));
?>
<?php echo $this->render('@app/views/layouts/websocket');?>
<script type="text/javascript">
<?php $this->beginBlock('javascript');?>
var socket_arr = '<?=$wsAddr?>'.split(":");
var wsAddr = socket_arr[0];
var port = socket_arr[1];
var i = 0;
var room_id = <?=$room->room_id?>;
var interval_handle;
var default_interval = 3;
/**
* websocket推送指令
* @returns {undefined}
*/
function callWebsocket(callback){
if (!window.ws || window.ws.readyState === undefined || window.ws.readyState != 1) {
websocket(wsAddr,port,'/',function(){
consoleLog('连接服务器');
callback();
},function(evt){
consoleLog('收到消息: '+evt.data);
data = JSON.parse(evt.data);
if (data.status == 1){
consoleLog('请求推送成功');
}else{
consoleLog('请求推送失败');
}
},function(){
consoleLog('连接已关闭');
},function(){
consoleLog('有错误出现');
});
}else{
callback();
}
}
/**
* 推送商品列表刷新指令
* @param {type} product_id
* @returns {undefined}
*/
function refreshProduct(){
... ... @@ -121,31 +91,6 @@ function getPushlog(interval){
$('#pushlog').text('开始监听推送记录').attr('onclick','getPushlog('+default_interval+')');
}
}
/**
* 页面打印发送记录
* @param {type} msg
* @returns {undefined}
*/
function consoleLog(msg){
if (msg){
console.log(msg);
}
$('#runtime').append('&nbsp;'+msg+'<br />');
}
/**
* 密钥生成
* @param {type} package
* @returns {unresolved}
*/
function makeSign(package){
package['private_key'] = 'a85bb0674e08986c6b115d5e3a4884fa';
package = ksort(package);
packageList = [];
for (key in package){
packageList.push(trim(key + '=' + package[key]));
}
return strtolower(md5(implode('&', packageList)));
}
<?php
$this->endBlock();
$this->registerJs($this->blocks['javascript'],View::POS_END)
... ... @@ -214,6 +159,6 @@ $this->registerJs($this->blocks['javascript'],View::POS_END)
</div>
<div class="form-group">
<div class="col-sm-6" id="runtime">
<div class="col-sm-6" id="wsRuntime">
</div>
</div><!-- form-group -->
\ No newline at end of file
... ...