mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Forward: support config full rtmp url forward to other server (#2799)
* Forward: add backend config and demo server for dynamic create forwarder to other server.(#1342) * Forward: if call forward backend failed, then return directly. * Forward: add API description and change return value format. * Forward: add backend conf file and wrapper function for backend service. * Forward: add backend comment in full.conf and update forward.backend.conf. * Forward: rename backend param and add comment tips.
This commit is contained in:
parent
9379ebbc2c
commit
03cf93fc2b
11 changed files with 335 additions and 33 deletions
|
@ -805,6 +805,86 @@ class RESTSnapshots(object):
|
|||
def OPTIONS(self, *args, **kwargs):
|
||||
enable_crossdomain()
|
||||
|
||||
'''
|
||||
handle the forward requests: dynamic forward url.
|
||||
'''
|
||||
class RESTForward(object):
|
||||
exposed = True
|
||||
|
||||
def __init__(self):
|
||||
self.__forwards = []
|
||||
|
||||
def GET(self):
|
||||
enable_crossdomain()
|
||||
|
||||
forwards = {}
|
||||
return json.dumps(forwards)
|
||||
|
||||
'''
|
||||
for SRS hook: on_forward
|
||||
on_forward:
|
||||
when srs reap a dvr file, call the hook,
|
||||
the request in the POST data string is a object encode by json:
|
||||
{
|
||||
"action": "on_forward",
|
||||
"server_id": "server_test",
|
||||
"client_id": 1985,
|
||||
"ip": "192.168.1.10",
|
||||
"vhost": "video.test.com",
|
||||
"app": "live",
|
||||
"tcUrl": "rtmp://video.test.com/live?key=d2fa801d08e3f90ed1e1670e6e52651a",
|
||||
"stream": "livestream",
|
||||
"param":"?token=xxx&salt=yyy"
|
||||
}
|
||||
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()
|
||||
|
||||
# return the error code in str
|
||||
code = Error.success
|
||||
|
||||
req = cherrypy.request.body.read()
|
||||
trace("post to forwards, req=%s"%(req))
|
||||
try:
|
||||
json_req = json.loads(req)
|
||||
except Exception, ex:
|
||||
code = Error.system_parse_json
|
||||
trace("parse the request to json failed, req=%s, ex=%s, code=%s"%(req, ex, code))
|
||||
return json.dumps({"code": int(code), "data": None})
|
||||
|
||||
action = json_req["action"]
|
||||
if action == "on_forward":
|
||||
return self.__on_forward(json_req)
|
||||
else:
|
||||
trace("invalid request action: %s"%(json_req["action"]))
|
||||
code = Error.request_invalid_action
|
||||
|
||||
return json.dumps({"code": int(code), "data": None})
|
||||
|
||||
def OPTIONS(self, *args, **kwargs):
|
||||
enable_crossdomain()
|
||||
|
||||
def __on_forward(self, req):
|
||||
code = Error.success
|
||||
|
||||
trace("srs %s: client id=%s, ip=%s, vhost=%s, app=%s, tcUrl=%s, stream=%s, param=%s"%(
|
||||
req["action"], req["client_id"], req["ip"], req["vhost"], req["app"], req["tcUrl"], req["stream"], req["param"]
|
||||
))
|
||||
|
||||
'''
|
||||
backend service config description:
|
||||
support multiple rtmp urls(custom addresses or third-party cdn service),
|
||||
url's host is slave service.
|
||||
For example:
|
||||
["rtmp://127.0.0.1:19350/test/teststream", "rtmp://127.0.0.1:19350/test/teststream?token=xxxx"]
|
||||
'''
|
||||
forwards = ["rtmp://127.0.0.1:19350/test/teststream"]
|
||||
|
||||
return json.dumps({"code": int(code), "data": {"urls": forwards}})
|
||||
|
||||
# HTTP RESTful path.
|
||||
class Root(object):
|
||||
exposed = True
|
||||
|
@ -846,6 +926,7 @@ class V1(object):
|
|||
self.chats = RESTChats()
|
||||
self.servers = RESTServers()
|
||||
self.snapshots = RESTSnapshots()
|
||||
self.forward = RESTForward()
|
||||
def GET(self):
|
||||
enable_crossdomain();
|
||||
return json.dumps({"code":Error.success, "urls":{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue