!29 有直播流可以直播

Merge pull request !29 from Chao Xing/xingchao
pull/58/head
Chao Xing 2018-05-07 11:52:27 +08:00
commit 386cf47785
1 changed files with 42 additions and 25 deletions

View File

@ -53,49 +53,66 @@ class Live extends Api
); );
} }
if ($this->request->request("username")) { // if ($this->request->request("username")) {
$username = $this->request->request("username"); // $username = $this->request->request("username");
// $username = 'qq'; $username = 'xingchao';
$sql = "select b.* $sql = "select b.*
from fa_user as a,fa_live as b from fa_user as a,fa_live as b
where a.id=b.user_id and a.username = '$username'"; where a.id=b.user_id and a.username = '$username'";
$list = Db::query($sql); $list = Db::query($sql);
if (!empty($list)) { if (!empty($list)) {
return true;
} else { $code = trim(strrchr($list[0]['push_url'], '/'), '/');
//创建直播流
$sql = "select id $len1 = strlen($list[0]['push_url']);
$len2 = strlen($code);
$base_url = substr($list[0]['push_url'],0,$len1 - $len2);
// echo $base_url;
$list = array(
'base_url' => $base_url,
'code' => $code,
);
$result = array("rows" => $list);
return (json($result));
} else {
//创建直播流
$sql = "select id
from fa_user from fa_user
where username = '$username'"; where username = '$username'";
$list = Db::query($sql); $list = Db::query($sql);
$user_id = $list[0]['id']; $user_id = $list[0]['id'];
$code = time(); $code = time();
$base_url = "rtmp://47.104.165.49:1935/live/"; $base_url = "rtmp://47.104.165.49:1935/live/";
$push_url = $base_url . $code; $push_url = $base_url . $code;
$pull_url = $push_url; $pull_url = $push_url;
$sql = "INSERT INTO fa_live(push_url,pull_url,user_id,status) VALUES ('$push_url','$pull_url','$user_id','1')"; $sql = "INSERT INTO fa_live(push_url,pull_url,user_id,status) VALUES ('$push_url','$pull_url','$user_id','1')";
// echo $sql; // echo $sql;
// exit(); // exit();
$rs = Db::execute($sql); $rs = Db::execute($sql);
// if ($rs === false) { // if ($rs === false) {
// echo '添加直播流失败'; // echo '添加直播流失败';
// } else { // } else {
// echo '添加直播流成功'; // echo '添加直播流成功';
// } // }
$list = array( $list = array(
'base_url'=>$base_url, 'base_url' => $base_url,
'code'=>$code, 'code' => $code,
); );
$result = array( "rows" => $list); $result = array("rows" => $list);
return json($result); return json($result);
}
} }
// }
$total = $this->model $total = $this->model