winlin

support generate link page for rtmp url

@@ -234,6 +234,15 @@ function parse_rtmp_url(rtmp_url) { @@ -234,6 +234,15 @@ function parse_rtmp_url(rtmp_url) {
234 } 234 }
235 } 235 }
236 236
  237 + // when vhost equals to server, and server is ip,
  238 + // the vhost is __defaultVhost__
  239 + if (a.hostname == vhost) {
  240 + var re = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
  241 + if (re.test(a.hostname)) {
  242 + vhost = "__defaultVhost__";
  243 + }
  244 + }
  245 +
237 var ret = { 246 var ret = {
238 server: a.hostname, port: port, 247 server: a.hostname, port: port,
239 vhost: vhost, app: app, stream: stream 248 vhost: vhost, app: app, stream: stream
@@ -49,6 +49,60 @@ @@ -49,6 +49,60 @@
49 URL: 49 URL:
50 <input type="text" id="txt_url" class="input-xxlarge" value=""></input> 50 <input type="text" id="txt_url" class="input-xxlarge" value=""></input>
51 <button class="btn btn-primary" id="btn_play">播放视频</button> 51 <button class="btn btn-primary" id="btn_play">播放视频</button>
  52 + <button class="btn" id="btn_generate_link">生成链接</button>
  53 + </div>
  54 + <div id="link_modal" class="modal hide fade">
  55 + <div class="modal-header">
  56 + <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  57 + <h3><a href="https://github.com/simple-rtmp-server/srs">SRS Link Generator</a></h3>
  58 + </div>
  59 + <div class="modal-body">
  60 + <div class="form-horizontal">
  61 + <div class="control-group">
  62 + <label class="control-label" for="link_server">服务器地址</label>
  63 + <div class="controls">
  64 + <span id="link_server" class="span4 uneditable-input"></span>
  65 + </div>
  66 + </div>
  67 + <div class="control-group">
  68 + <label class="control-label" for="link_port">服务器端口</label>
  69 + <div class="controls">
  70 + <span id="link_port" class="span2 uneditable-input"></span>
  71 + </div>
  72 + </div>
  73 + <div class="control-group">
  74 + <label class="control-label" for="link_vhost">RTMP Vhost</label>
  75 + <div class="controls">
  76 + <span id="link_vhost" class="span4 uneditable-input"></span>
  77 + </div>
  78 + </div>
  79 + <div class="control-group">
  80 + <label class="control-label" for="link_app">RTMP App</label>
  81 + <div class="controls">
  82 + <span id="link_app" class="span4 uneditable-input"></span>
  83 + </div>
  84 + </div>
  85 + <div class="control-group">
  86 + <label class="control-label" for="link_stream">RTMP Stream</label>
  87 + <div class="controls">
  88 + <span id="link_stream" class="span4 uneditable-input"></span>
  89 + </div>
  90 + </div>
  91 + <div class="control-group">
  92 + <label class="control-label" for="link_rtmp">RTMP地址</label>
  93 + <div class="controls">
  94 + <span id="link_rtmp" class="span4 uneditable-input"></span>
  95 + </div>
  96 + </div>
  97 + <div class="control-group">
  98 + <label class="control-label" for="link_url">播放链接地址</label>
  99 + <div class="controls">
  100 + <div style="margin-top:5px;"><a href="#" id="link_url">请右键拷贝此链接地址.</a></div>
  101 + </div>
  102 + </div>
  103 + </div>
  104 + </div>
  105 + <div class="modal-footer"></div>
52 </div> 106 </div>
53 <div class="container"> 107 <div class="container">
54 <hr/> 108 <hr/>
@@ -337,6 +391,8 @@ @@ -337,6 +391,8 @@
337 } 391 }
338 392
339 $(function(){ 393 $(function(){
  394 + var query = parse_query_string();
  395 +
340 // get the vhost and port to set the default url. 396 // get the vhost and port to set the default url.
341 // for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo 397 // for example: http://192.168.1.213/players/jwplayer6.html?port=1935&vhost=demo
342 // url set to: rtmp://demo:1935/live/livestream 398 // url set to: rtmp://demo:1935/live/livestream
@@ -408,6 +464,22 @@ @@ -408,6 +464,22 @@
408 } 464 }
409 }); 465 });
410 466
  467 + $("#btn_generate_link").click(function(){
  468 + var rtmp = parse_rtmp_url($("#txt_url").val());
  469 + var url = "http://" + query.host + query.pathname + "?"
  470 + + "vhost=" + rtmp.vhost + "&app=" + rtmp.app + "&stream=" + rtmp.stream
  471 + + "&server=" + rtmp.server + "&port=" + rtmp.port
  472 + + "&autostart=true";
  473 + $("#link_server").text(rtmp.server);
  474 + $("#link_port").text(rtmp.port);
  475 + $("#link_vhost").text(rtmp.vhost);
  476 + $("#link_app").text(rtmp.app);
  477 + $("#link_stream").text(rtmp.stream);
  478 + $("#link_rtmp").text($("#txt_url").val());
  479 + $("#link_url").attr("href", url);
  480 + $("#link_modal").modal({show:true, keyboard:false});
  481 + });
  482 +
411 $("#btn_play").click(function(){ 483 $("#btn_play").click(function(){
412 url = $("#txt_url").val(); 484 url = $("#txt_url").val();
413 $("#main_modal").modal({show:true, keyboard:false}); 485 $("#main_modal").modal({show:true, keyboard:false});
@@ -450,7 +522,6 @@ @@ -450,7 +522,6 @@
450 }); 522 });
451 } 523 }
452 524
453 - var query = parse_query_string();  
454 var jwplayer_url = "http://" + query.host + query.dir + "/jwplayer6.html?vhost=demo.srs.com&app=live&hls_autostart=true"; 525 var jwplayer_url = "http://" + query.host + query.dir + "/jwplayer6.html?vhost=demo.srs.com&app=live&hls_autostart=true";
455 if (true) { 526 if (true) {
456 $("#srs_publish_hls").attr("href", jwplayer_url + "&stream=livestream"); 527 $("#srs_publish_hls").attr("href", jwplayer_url + "&stream=livestream");