|
@@ -32,6 +32,15 @@ class Handle
|
|
|
$stream = $method->stop($info['key']);
|
|
|
}
|
|
|
|
|
|
+ # 保存
|
|
|
+ public function save($id)
|
|
|
+ {
|
|
|
+ $info = Dever::db('live/stream')->one($id);
|
|
|
+ $config = Dever::db('live/info')->one($info['live_id']);
|
|
|
+ $method = $this->method($config);
|
|
|
+ return $method->save($info['key']);
|
|
|
+ }
|
|
|
+
|
|
|
# 初始化流
|
|
|
public function init($id, $name = '')
|
|
|
{
|
|
@@ -42,34 +51,16 @@ class Handle
|
|
|
if ($name) {
|
|
|
$info['key'] = $name;
|
|
|
}
|
|
|
- $config = Dever::db('live/info')->one($info['live_id']);
|
|
|
-
|
|
|
- $method = $this->method($config);
|
|
|
- $stream = $method->create($info['key']);
|
|
|
-
|
|
|
- $rtmp = $method->getRtmp($info['key'], $info['times'] * 3600);
|
|
|
-
|
|
|
- $url = $method->getPlay($info['key']);
|
|
|
-
|
|
|
- $data['where_id'] = $id;
|
|
|
- $data['live'] = $rtmp;
|
|
|
- $data['url_rtmp'] = $url['rtmp'];
|
|
|
- $data['url_hls'] = $url['hls'];
|
|
|
- $data['url_hdl'] = $url['hdl'];
|
|
|
- $data['url_pic'] = $url['pic'];
|
|
|
- $live['info'] = $stream;
|
|
|
-
|
|
|
- $data['info'] = Dever::json_encode($live);
|
|
|
-
|
|
|
- Dever::db('live/stream')->update($data);
|
|
|
|
|
|
- return $data;
|
|
|
+ return $this->get($info);
|
|
|
}
|
|
|
|
|
|
# 获取流信息 定时跑
|
|
|
- public function get($id)
|
|
|
+ public function get($info)
|
|
|
{
|
|
|
- $info = Dever::db('live/stream')->one($id);
|
|
|
+ if (!is_array($info)) {
|
|
|
+ $info = Dever::db('live/stream')->one($id);
|
|
|
+ }
|
|
|
|
|
|
$config = Dever::db('live/info')->one($info['live_id']);
|
|
|
|
|
@@ -81,9 +72,13 @@ class Handle
|
|
|
|
|
|
$stream = $method->getInfo($info['key']);
|
|
|
|
|
|
- $live = $method->getLiveStatus($info['key']);
|
|
|
-
|
|
|
- $hitory = $method->history($info['key']);
|
|
|
+ try {
|
|
|
+ $live = $method->getLiveStatus($info['key']);
|
|
|
+ $hitory = $method->history($info['key']);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $live = array();
|
|
|
+ $hitory = array();
|
|
|
+ }
|
|
|
|
|
|
$data['where_id'] = $id;
|
|
|
$data['live'] = $rtmp;
|
|
@@ -97,6 +92,12 @@ class Handle
|
|
|
$live['live'] = $live;
|
|
|
$live['hitory'] = $history;
|
|
|
|
|
|
+ if ($live) {
|
|
|
+ $data['status'] = 2;
|
|
|
+ } else {
|
|
|
+ $data['status'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
$data['info'] = Dever::json_encode($live);
|
|
|
|
|
|
Dever::db('live/stream')->update($data);
|