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
2013-12-08 10:53:18 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3d4474f620d8533b8f859dc1b2f6dc6b41e32b24
3d4474f6
1 parent
2887cda1
support multiple http hooks for a event.
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
37 行增加
和
16 行删除
trunk/research/api-server/server.py
trunk/research/api-server/server.py
查看文件 @
3d4474f
...
...
@@ -28,13 +28,13 @@ when srs get some event, for example, when client connect
to srs, srs can invoke the http api of the api-server
"""
import
sys
;
import
sys
# reload sys model to enable the getdefaultencoding method.
reload
(
sys
)
;
reload
(
sys
)
# set the default encoding to utf-8
# using exec to set the encoding, to avoid error in IDE.
exec
(
"sys.setdefaultencoding('utf-8')"
);
assert
sys
.
getdefaultencoding
()
.
lower
()
==
"utf-8"
;
exec
(
"sys.setdefaultencoding('utf-8')"
)
assert
sys
.
getdefaultencoding
()
.
lower
()
==
"utf-8"
import
json
,
datetime
,
cherrypy
...
...
@@ -66,25 +66,46 @@ class RESTClients(object):
exposed
=
True
def
GET
(
self
):
enable_crossdomain
();
clients
=
{};
return
json
.
dumps
(
clients
);
enable_crossdomain
()
# for SRS hook: on_connect
clients
=
{}
return
json
.
dumps
(
clients
)
'''
for SRS hook: on_connect
when client connect to vhost/app, call the hook,
the request in the POST data string is a object encode by json:
{
"ip": "192.168.1.10", "vhost": "video.test.com", "app": "live",
"pageUrl": "http://www.test.com/live.html"
}
if valid, the hook must return HTTP code 200(Stauts OK) and response
an int value specifies the error code(0 corresponding to success):
0
'''
def
POST
(
self
):
enable_crossdomain
()
;
enable_crossdomain
()
req
=
cherrypy
.
request
.
body
.
read
();
trace
(
"post to clients, req=
%
s"
%
(
req
));
# return the error code in str
ret
=
Error
.
success
req
=
cherrypy
.
request
.
body
.
read
()
trace
(
"post to clients, req=
%
s"
%
(
req
))
try
:
json_req
=
json
.
loads
(
req
)
except
Exception
,
ex
:
trace
(
"parse the request to json failed, req=
%
s, ex=
%
s"
%
(
req
,
ex
))
return
str
(
Error
.
system_parse_json
);
ret
=
Error
.
system_parse_json
trace
(
"parse the request to json failed, req=
%
s, ex=
%
s, ret=
%
s"
%
(
req
,
ex
,
ret
))
return
str
(
ret
)
trace
(
"srs on_connect: client ip=
%
s, vhost=
%
s, app=
%
s, pageUrl=
%
s"
%
(
json_req
[
"ip"
],
json_req
[
"vhost"
],
json_req
[
"app"
],
json_req
[
"pageUrl"
]
))
# TODO: valid the client.
trace
(
"valid clients post request success."
)
return
str
(
Error
.
success
);
return
str
(
ret
)
def
OPTIONS
(
self
):
enable_crossdomain
()
...
...
@@ -108,7 +129,7 @@ main code start.
'''
# donot support use this module as library.
if
__name__
!=
"__main__"
:
raise
Exception
(
"embed not support"
)
;
raise
Exception
(
"embed not support"
)
# check the user options
if
len
(
sys
.
argv
)
<=
1
:
...
...
请
注册
或
登录
后发表评论