Commit 6d28cc303e4aa8f658b6474939615590fc3ff949
1 parent
1e188536
live
Showing
4 changed files
with
77 additions
and
40 deletions
src/main/java/com/cnlive/mz/live/action/LiveAction.java
| @@ -30,6 +30,7 @@ import com.cnlive.mz.live.common.LiveUtils; | @@ -30,6 +30,7 @@ import com.cnlive.mz.live.common.LiveUtils; | ||
| 30 | import com.cnlive.mz.live.entity.TLive; | 30 | import com.cnlive.mz.live.entity.TLive; |
| 31 | import com.cnlive.mz.live.entity.TRoom; | 31 | import com.cnlive.mz.live.entity.TRoom; |
| 32 | import com.cnlive.mz.live.rest.BaseUtil; | 32 | import com.cnlive.mz.live.rest.BaseUtil; |
| 33 | +import com.cnlive.mz.live.service.TCheckService; | ||
| 33 | import com.cnlive.mz.live.service.TLiveService; | 34 | import com.cnlive.mz.live.service.TLiveService; |
| 34 | import com.cnlive.mz.live.service.TRoomService; | 35 | import com.cnlive.mz.live.service.TRoomService; |
| 35 | 36 | ||
| @@ -47,7 +48,8 @@ public class LiveAction { | @@ -47,7 +48,8 @@ public class LiveAction { | ||
| 47 | private TLiveService tLiveService; | 48 | private TLiveService tLiveService; |
| 48 | @Inject | 49 | @Inject |
| 49 | private TRoomService tRoomService; | 50 | private TRoomService tRoomService; |
| 50 | - | 51 | + @Inject |
| 52 | + private TCheckService tCheckService; | ||
| 51 | @Request.Get("/live/preload") | 53 | @Request.Get("/live/preload") |
| 52 | public View preload() { | 54 | public View preload() { |
| 53 | int user_id = CastUtil.castInt(DataContext.getRequest().getSession().getAttribute(LiveUtils.SESSION_KEY_ID)); | 55 | int user_id = CastUtil.castInt(DataContext.getRequest().getSession().getAttribute(LiveUtils.SESSION_KEY_ID)); |
| @@ -114,11 +116,33 @@ public class LiveAction { | @@ -114,11 +116,33 @@ public class LiveAction { | ||
| 114 | } | 116 | } |
| 115 | 117 | ||
| 116 | // 切断 | 118 | // 切断 |
| 117 | - @Request.Get("/check/cut/{id}") | ||
| 118 | - public Result cut(int id) { | ||
| 119 | - return new Result(true); | 119 | + @Request.Post("/check/cut/{id}") |
| 120 | + public Result cut(int id,Params params) throws UnsupportedEncodingException { | ||
| 121 | + String live_url = params.getString("live_url"); | ||
| 122 | + if(live_url.isEmpty()){ | ||
| 123 | + return null; | ||
| 124 | + }else{ | ||
| 125 | + int index = live_url.lastIndexOf("live"); | ||
| 126 | + String streamName = live_url.substring(index+6); | ||
| 127 | + System.out.println("streamName==="+streamName); | ||
| 128 | + String accesskey = BaseUtil.getAccessKey(); | ||
| 129 | + accesskey = java.net.URLEncoder.encode(accesskey,"utf-8"); | ||
| 130 | + String signature = BaseUtil.signature(streamName); | ||
| 131 | + String del = "del"; | ||
| 132 | + String delsignature = BaseUtil.signature(del,streamName); | ||
| 133 | + String expire = BaseUtil.getTimestamp(); | ||
| 134 | + System.out.println(expire+"---expire---"); | ||
| 135 | + //断流。 | ||
| 136 | + try { | ||
| 137 | + addBlackList(signature,accesskey,expire,streamName); | ||
| 138 | + delBlackList(delsignature,accesskey,expire,streamName); | ||
| 139 | + } catch (UnsupportedEncodingException e) { | ||
| 140 | + e.printStackTrace(); | ||
| 141 | + } | ||
| 142 | + boolean flag = tCheckService.closeLive(id); | ||
| 143 | + return new Result(flag); | ||
| 144 | + } | ||
| 120 | } | 145 | } |
| 121 | - | ||
| 122 | // 通过审核 | 146 | // 通过审核 |
| 123 | @Request.Get("/check/pass/{id}") | 147 | @Request.Get("/check/pass/{id}") |
| 124 | public Result pass(int id) { | 148 | public Result pass(int id) { |
| @@ -156,19 +180,12 @@ public class LiveAction { | @@ -156,19 +180,12 @@ public class LiveAction { | ||
| 156 | * @return | 180 | * @return |
| 157 | * @throws UnsupportedEncodingException | 181 | * @throws UnsupportedEncodingException |
| 158 | */ | 182 | */ |
| 159 | - public String addBlackList(String signature, String accesskey, String expire, String streamName) | ||
| 160 | - throws UnsupportedEncodingException { | ||
| 161 | - String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature=" + signature + "&accesskey=" + accesskey | ||
| 162 | - + "&expire=" + expire + "&method=add&app=live&name=" + streamName; | 183 | + public String addBlackList(String signature, String accesskey, String expire,String streamName) throws UnsupportedEncodingException { |
| 184 | + String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature="+signature+"&accesskey="+accesskey+"&expire="+expire+"&app=live&method=add&name=" + streamName; | ||
| 163 | System.out.println(url); | 185 | System.out.println(url); |
| 164 | String jsonArrStr = HttpReq.getRequestWidthResult(url); | 186 | String jsonArrStr = HttpReq.getRequestWidthResult(url); |
| 165 | int status = HttpReq.getRequest(url); | 187 | int status = HttpReq.getRequest(url); |
| 166 | - System.out.println("............" + status); | ||
| 167 | - System.out.println("............" + jsonArrStr); | ||
| 168 | - /* | ||
| 169 | - * Map map = JsonUtil.getMapFromJsonObjStr(jsonArrStr); String | ||
| 170 | - * chatRoomid = (String) map.get("Content-Length"); | ||
| 171 | - */ | 188 | + System.out.println(status+"......and......"+jsonArrStr); |
| 172 | return jsonArrStr; | 189 | return jsonArrStr; |
| 173 | } | 190 | } |
| 174 | 191 | ||
| @@ -182,16 +199,12 @@ public class LiveAction { | @@ -182,16 +199,12 @@ public class LiveAction { | ||
| 182 | * @return | 199 | * @return |
| 183 | * @throws UnsupportedEncodingException | 200 | * @throws UnsupportedEncodingException |
| 184 | */ | 201 | */ |
| 185 | - public Object delBlackList(String signature, String accesskey, String expire, String streamName) | ||
| 186 | - throws UnsupportedEncodingException { | ||
| 187 | - String url = "http://cnlive.uplive.ks-cdn.com/blacklist?signature=" + signature + "&accesskey=" + accesskey | ||
| 188 | - + "&expire=" + expire + "&method=del&app=live&name=" + streamName; | 202 | + public Object delBlackList(String signature, String accesskey, String expire,String streamName) throws UnsupportedEncodingException { |
| 203 | + String url = "http://cnlive.dashboard.ks-cdn.com/blacklist?signature="+signature+"&accesskey="+accesskey+"&expire="+expire+"&app=live&method=del&name=" + streamName; | ||
| 204 | + System.out.println("..url.."+url); | ||
| 189 | String jsonArrStr = HttpReq.getRequestWidthResult(url); | 205 | String jsonArrStr = HttpReq.getRequestWidthResult(url); |
| 190 | - System.out.println(); | ||
| 191 | - /* | ||
| 192 | - * Map map = JsonUtil.getMapFromJsonObjStr(jsonArrStr); String | ||
| 193 | - * chatRoomid = (String) map.get("Content-Length"); | ||
| 194 | - */ | 206 | + System.out.println("..jsonArrStr.."+jsonArrStr); |
| 195 | return jsonArrStr; | 207 | return jsonArrStr; |
| 208 | + | ||
| 196 | } | 209 | } |
| 197 | } | 210 | } |
| 198 | \ No newline at end of file | 211 | \ No newline at end of file |
src/main/java/com/cnlive/mz/live/rest/BaseUtil.java
| @@ -114,7 +114,6 @@ public class BaseUtil { | @@ -114,7 +114,6 @@ public class BaseUtil { | ||
| 114 | public static String signature(String streamName) throws UnsupportedEncodingException { | 114 | public static String signature(String streamName) throws UnsupportedEncodingException { |
| 115 | 115 | ||
| 116 | String method = "GET"; | 116 | String method = "GET"; |
| 117 | - | ||
| 118 | String expire = BaseUtil.getTimestamp(); | 117 | String expire = BaseUtil.getTimestamp(); |
| 119 | String app = "live"; | 118 | String app = "live"; |
| 120 | String methodadd = "add"; | 119 | String methodadd = "add"; |
| @@ -131,17 +130,6 @@ public class BaseUtil { | @@ -131,17 +130,6 @@ public class BaseUtil { | ||
| 131 | String signature = HMACSha1(stringToSign, SECRET_KEY); | 130 | String signature = HMACSha1(stringToSign, SECRET_KEY); |
| 132 | System.out.println( "---signature---"+signature ); | 131 | System.out.println( "---signature---"+signature ); |
| 133 | signature = java.net.URLEncoder.encode(signature, "utf-8"); | 132 | signature = java.net.URLEncoder.encode(signature, "utf-8"); |
| 134 | - | ||
| 135 | - String Expire = String.valueOf(BaseUtil.getTimestamp()).substring(0, 10); | ||
| 136 | - System.out.println(Expire+"---expire----"); | ||
| 137 | - String Resource = "app=live&method=add&nonce=cnlive&public=0&vdoid=12345&stream="+streamName; | ||
| 138 | - Resource = java.net.URLEncoder.encode(Resource,"utf-8"); | ||
| 139 | - String stringToSign = method + "\n" + Expire + "\n" + Resource; | ||
| 140 | - // 2.计算 HMAC-SHA1 | ||
| 141 | - String signature = HMACSha1(stringToSign, AK_SECRET); | ||
| 142 | - System.out.println(signature+"------"); | ||
| 143 | - signature =java.net.URLEncoder.encode(signature,"utf-8"); | ||
| 144 | - | ||
| 145 | return signature; | 133 | return signature; |
| 146 | } | 134 | } |
| 147 | public static String signature(String methodNname,String streamName) throws UnsupportedEncodingException { | 135 | public static String signature(String methodNname,String streamName) throws UnsupportedEncodingException { |
| @@ -165,8 +153,6 @@ public class BaseUtil { | @@ -165,8 +153,6 @@ public class BaseUtil { | ||
| 165 | signature = java.net.URLEncoder.encode(signature, "utf-8"); | 153 | signature = java.net.URLEncoder.encode(signature, "utf-8"); |
| 166 | return signature; | 154 | return signature; |
| 167 | } | 155 | } |
| 168 | - | ||
| 169 | - public static String getUUid() { | ||
| 170 | 156 | ||
| 171 | public static String UUid() { | 157 | public static String UUid() { |
| 172 | 158 |
src/main/webapp/static/assets/cnlive/js/check.js
| @@ -25,6 +25,24 @@ function to_pass(id) { | @@ -25,6 +25,24 @@ function to_pass(id) { | ||
| 25 | } | 25 | } |
| 26 | }); | 26 | }); |
| 27 | } | 27 | } |
| 28 | +//断流处理 | ||
| 29 | +//function play_close(id,live_url){ | ||
| 30 | +// $.ajax({ | ||
| 31 | +// url : '../../check/cut/' + id, | ||
| 32 | +// type : 'post', | ||
| 33 | +// datatype : "json", | ||
| 34 | +// async : true, | ||
| 35 | +// data:{"live_url":live_url}, | ||
| 36 | +// error : function() { | ||
| 37 | +// alert('关闭时发生错误!'); | ||
| 38 | +// }, | ||
| 39 | +// success : function(data) { | ||
| 40 | +// location.href = '../../check/list/1'; | ||
| 41 | +// alert("关闭成功"); | ||
| 42 | +// } | ||
| 43 | +// }); | ||
| 44 | +//} | ||
| 45 | +//change | ||
| 28 | 46 | ||
| 29 | 47 | ||
| 30 | 48 | ||
| 31 | \ No newline at end of file | 49 | \ No newline at end of file |
src/main/webapp/static/assets/cnlive/js/live.js
| @@ -435,5 +435,25 @@ function do_publishreview(id){ | @@ -435,5 +435,25 @@ function do_publishreview(id){ | ||
| 435 | } | 435 | } |
| 436 | }); | 436 | }); |
| 437 | } | 437 | } |
| 438 | - | ||
| 439 | - | 438 | +//断流处理 |
| 439 | +function play_close(id,live_url){ | ||
| 440 | + alert(111); | ||
| 441 | + $.ajax({ | ||
| 442 | + url : '../../check/cut/' + id, | ||
| 443 | + type : 'post', | ||
| 444 | + datatype : "json", | ||
| 445 | + async : true, | ||
| 446 | + data:{"live_url":live_url}, | ||
| 447 | + error : function() { | ||
| 448 | + alert('关闭时发生错误!'); | ||
| 449 | + }, | ||
| 450 | + success : function(data) { | ||
| 451 | + location.href = '../../check/list/1'; | ||
| 452 | + alert("关闭成功"); | ||
| 453 | + } | ||
| 454 | + }); | ||
| 455 | +} | ||
| 456 | +/*function changePlay(id){ | ||
| 457 | + alert(111); | ||
| 458 | + alert(id); | ||
| 459 | +}*/ |