正在显示
1 个修改的文件
包含
39 行增加
和
6 行删除
@@ -332,14 +332,37 @@ class RESTServers(object): | @@ -332,14 +332,37 @@ class RESTServers(object): | ||
332 | ''' | 332 | ''' |
333 | id canbe: | 333 | id canbe: |
334 | ingest: the ingest demo. | 334 | ingest: the ingest demo. |
335 | - meeting: the meeting demo. | 335 | + action: canbe play or mgmt, play to play the inest stream, mgmt to get api/v1/versions. |
336 | + stream: the stream to play, for example, live/livestream for http://server:8080/live/livestream.html | ||
337 | + meeting: the meeting demo. jump to web meeting if index is None. | ||
338 | + local: whether view the local raspberry-pi stream. if "true", redirect to the local(internal) api server. | ||
339 | + index: the meeting stream index, dynamic get the streams from root.api.v1.chats.get_url_by_index(index) | ||
336 | ''' | 340 | ''' |
337 | - def GET(self, id=None): | 341 | + def GET(self, id=None, action="play", stream="live/livestream", index=None, local="false"): |
338 | enable_crossdomain() | 342 | enable_crossdomain() |
339 | if id == "meeting": | 343 | if id == "meeting": |
340 | - url = "http://%s:8085/players/srs_chat.html?port=1935"%(self.__server_ip) | 344 | + if index is None: |
345 | + url = "http://%s:8085"%(self.__server_ip) | ||
346 | + elif local == "true": | ||
347 | + url = "http://%s:8085/api/v1/servers?id=%s&index=%s&local=false"%(self.__server_ip, id, index) | ||
348 | + else: | ||
349 | + rtmp_url = root.api.v1.chats.get_url_by_index(index) | ||
350 | + if rtmp_url is None: | ||
351 | + return "meeting stream not found" | ||
352 | + urls = rtmp_url.replace("...vhost...", "?vhost=").replace("rtmp://", "").split("/") | ||
353 | + hls_url = "http://%s:8080/%s/%s.m3u8"%(urls[0].replace(":1935",""), urls[1].split("?")[0], urls[2]) | ||
354 | + return """ | ||
355 | +<video width="640" height="360" | ||
356 | + autoplay controls autobuffer | ||
357 | + src="%s" | ||
358 | + type="application/vnd.apple.mpegurl"> | ||
359 | +</video>"""%(hls_url); | ||
341 | else: | 360 | else: |
342 | - url = "http://%s:8080/live/livestream.html"%(self.__server_ip) | 361 | + if action == "play": |
362 | + url = "http://%s:8080/%s.html"%(self.__server_ip, stream) | ||
363 | + else: | ||
364 | + url = "http://%s:8080/api/v1/versions"%(self.__server_ip) | ||
365 | + #return "id=%s, action=%s, stream=%s, url=%s, index=%s, local=%s"%(id, action, stream, url, index, local) | ||
343 | raise cherrypy.HTTPRedirect(url) | 366 | raise cherrypy.HTTPRedirect(url) |
344 | 367 | ||
345 | def POST(self): | 368 | def POST(self): |
@@ -354,7 +377,6 @@ class RESTServers(object): | @@ -354,7 +377,6 @@ class RESTServers(object): | ||
354 | enable_crossdomain() | 377 | enable_crossdomain() |
355 | raise cherrypy.HTTPError(405, "Not allowed.") | 378 | raise cherrypy.HTTPError(405, "Not allowed.") |
356 | 379 | ||
357 | - | ||
358 | def OPTIONS(self, id=None): | 380 | def OPTIONS(self, id=None): |
359 | enable_crossdomain() | 381 | enable_crossdomain() |
360 | 382 | ||
@@ -382,6 +404,15 @@ class RESTChats(object): | @@ -382,6 +404,15 @@ class RESTChats(object): | ||
382 | 404 | ||
383 | # dead time in seconds, if exceed, remove the chat. | 405 | # dead time in seconds, if exceed, remove the chat. |
384 | self.__dead_time = 15; | 406 | self.__dead_time = 15; |
407 | + | ||
408 | + ''' | ||
409 | + get the rtmp url of chat object. None if overflow. | ||
410 | + ''' | ||
411 | + def get_url_by_index(self, index): | ||
412 | + index = int(index) | ||
413 | + if index is None or index >= len(self.__chats): | ||
414 | + return None; | ||
415 | + return self.__chats[index]["url"]; | ||
385 | 416 | ||
386 | def GET(self): | 417 | def GET(self): |
387 | enable_crossdomain() | 418 | enable_crossdomain() |
@@ -536,4 +567,6 @@ conf = { | @@ -536,4 +567,6 @@ conf = { | ||
536 | 567 | ||
537 | # start cherrypy web engine | 568 | # start cherrypy web engine |
538 | trace("start cherrypy server") | 569 | trace("start cherrypy server") |
539 | -cherrypy.quickstart(Root(), '/', conf) | 570 | +root = Root() |
571 | +cherrypy.quickstart(root, '/', conf) | ||
572 | + |
-
请 注册 或 登录 后发表评论