Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-04-11 11:29:17 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
acdd5a827edf5bf3ad1441a87e4c4b96b1203c4e
acdd5a82
1 parent
ff902780
update api server, support servers
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
39 行增加
和
6 行删除
trunk/research/api-server/server.py
trunk/research/api-server/server.py
查看文件 @
acdd5a8
...
...
@@ -332,14 +332,37 @@ class RESTServers(object):
'''
id canbe:
ingest: the ingest demo.
meeting: the meeting demo.
action: canbe play or mgmt, play to play the inest stream, mgmt to get api/v1/versions.
stream: the stream to play, for example, live/livestream for http://server:8080/live/livestream.html
meeting: the meeting demo. jump to web meeting if index is None.
local: whether view the local raspberry-pi stream. if "true", redirect to the local(internal) api server.
index: the meeting stream index, dynamic get the streams from root.api.v1.chats.get_url_by_index(index)
'''
def
GET
(
self
,
id
=
None
):
def
GET
(
self
,
id
=
None
,
action
=
"play"
,
stream
=
"live/livestream"
,
index
=
None
,
local
=
"false"
):
enable_crossdomain
()
if
id
==
"meeting"
:
url
=
"http://
%
s:8085/players/srs_chat.html?port=1935"
%
(
self
.
__server_ip
)
if
index
is
None
:
url
=
"http://
%
s:8085"
%
(
self
.
__server_ip
)
elif
local
==
"true"
:
url
=
"http://
%
s:8085/api/v1/servers?id=
%
s&index=
%
s&local=false"
%
(
self
.
__server_ip
,
id
,
index
)
else
:
rtmp_url
=
root
.
api
.
v1
.
chats
.
get_url_by_index
(
index
)
if
rtmp_url
is
None
:
return
"meeting stream not found"
urls
=
rtmp_url
.
replace
(
"...vhost..."
,
"?vhost="
)
.
replace
(
"rtmp://"
,
""
)
.
split
(
"/"
)
hls_url
=
"http://
%
s:8080/
%
s/
%
s.m3u8"
%
(
urls
[
0
]
.
replace
(
":1935"
,
""
),
urls
[
1
]
.
split
(
"?"
)[
0
],
urls
[
2
])
return
"""
<video width="640" height="360"
autoplay controls autobuffer
src="
%
s"
type="application/vnd.apple.mpegurl">
</video>"""
%
(
hls_url
);
else
:
url
=
"http://
%
s:8080/live/livestream.html"
%
(
self
.
__server_ip
)
if
action
==
"play"
:
url
=
"http://
%
s:8080/
%
s.html"
%
(
self
.
__server_ip
,
stream
)
else
:
url
=
"http://
%
s:8080/api/v1/versions"
%
(
self
.
__server_ip
)
#return "id=%s, action=%s, stream=%s, url=%s, index=%s, local=%s"%(id, action, stream, url, index, local)
raise
cherrypy
.
HTTPRedirect
(
url
)
def
POST
(
self
):
...
...
@@ -354,7 +377,6 @@ class RESTServers(object):
enable_crossdomain
()
raise
cherrypy
.
HTTPError
(
405
,
"Not allowed."
)
def
OPTIONS
(
self
,
id
=
None
):
enable_crossdomain
()
...
...
@@ -382,6 +404,15 @@ class RESTChats(object):
# dead time in seconds, if exceed, remove the chat.
self
.
__dead_time
=
15
;
'''
get the rtmp url of chat object. None if overflow.
'''
def
get_url_by_index
(
self
,
index
):
index
=
int
(
index
)
if
index
is
None
or
index
>=
len
(
self
.
__chats
):
return
None
;
return
self
.
__chats
[
index
][
"url"
];
def
GET
(
self
):
enable_crossdomain
()
...
...
@@ -536,4 +567,6 @@ conf = {
# start cherrypy web engine
trace
(
"start cherrypy server"
)
cherrypy
.
quickstart
(
Root
(),
'/'
,
conf
)
root
=
Root
()
cherrypy
.
quickstart
(
root
,
'/'
,
conf
)
...
...
请
注册
或
登录
后发表评论