|
@@ -5,6 +5,7 @@ import android.util.Log;
|
|
|
import com.wdkl.ncs.janus.rtc.WebRTCEngine;
|
|
|
import com.wdkl.ncs.janus.util.EnumType;
|
|
|
|
|
|
+import org.json.JSONArray;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
import org.webrtc.IceCandidate;
|
|
@@ -631,6 +632,146 @@ public class JanusClient implements WebSocketChannel.WebSocketCallback {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ //---------------------------------------------------- 广播用 开始
|
|
|
+ public static final int ERROR_STREAMING_REQUEST = 0x04;
|
|
|
+
|
|
|
+ public void requestList(){
|
|
|
+ String tid = randomString(12);
|
|
|
+ transactions.put(tid, new Transaction(tid) {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(JSONObject msg) throws Exception {
|
|
|
+ JSONObject data = msg.getJSONObject("plugindata").getJSONObject("data");
|
|
|
+ JSONArray array = data.getJSONArray("list");
|
|
|
+ /*
|
|
|
+ audio_age_ms: 236984209
|
|
|
+ description: "Opus live stream coming from external source"
|
|
|
+ enabled: true
|
|
|
+ id: 112 //来自数据库
|
|
|
+ metadata: "12" //partId,
|
|
|
+ type: "live"
|
|
|
+ */
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError() {
|
|
|
+ janusCallback.onError(ERROR_STREAMING_REQUEST, "获取Streaming List失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ JSONObject message = new JSONObject();
|
|
|
+ JSONObject body = new JSONObject();
|
|
|
+ try {
|
|
|
+ body.putOpt("request", "list");
|
|
|
+ message.put("body", body);
|
|
|
+
|
|
|
+ message.putOpt("janus", "message");
|
|
|
+ message.putOpt("transaction", tid);
|
|
|
+ message.putOpt("session_id", sessionId);
|
|
|
+ message.putOpt("handle_id", currentHandleId);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ sendMessage(message.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void requestInfo(BigInteger channelId){
|
|
|
+ String tid = randomString(12);
|
|
|
+ transactions.put(tid, new Transaction(tid) {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(JSONObject msg) throws Exception {
|
|
|
+ JSONObject data = msg.getJSONObject("plugindata").getJSONObject("data");
|
|
|
+ JSONObject array = data.getJSONObject("info");
|
|
|
+ /*
|
|
|
+ audio: true
|
|
|
+ audio_age_ms: 243502007
|
|
|
+ audioport: 5004
|
|
|
+ audiopt: 111
|
|
|
+ audiortcpport: 0
|
|
|
+ audiortpmap: "opus/48000/2"
|
|
|
+ description: "Opus live stream coming from external source"
|
|
|
+ enabled: true
|
|
|
+ id: 112
|
|
|
+ metadata: "测试一下测试一下"
|
|
|
+ name: "rtp-audio"
|
|
|
+ type: "live"
|
|
|
+ viewers: 1
|
|
|
+ */
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError() {
|
|
|
+ janusCallback.onError(ERROR_STREAMING_REQUEST, "获取Streaming Info失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ JSONObject message = new JSONObject();
|
|
|
+ JSONObject body = new JSONObject();
|
|
|
+ try {
|
|
|
+ body.putOpt("request", "info");
|
|
|
+ body.putOpt("id", channelId);
|
|
|
+ message.put("body", body);
|
|
|
+
|
|
|
+ message.putOpt("janus", "message");
|
|
|
+ message.putOpt("transaction", tid);
|
|
|
+ message.putOpt("session_id", sessionId);
|
|
|
+ message.putOpt("handle_id", currentHandleId);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ sendMessage(message.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void requestWatch(BigInteger channelId){
|
|
|
+ String tid = randomString(12);
|
|
|
+ JSONObject message = new JSONObject();
|
|
|
+ JSONObject body = new JSONObject();
|
|
|
+ try {
|
|
|
+ body.putOpt("request", "watch");
|
|
|
+ body.putOpt("id", channelId);
|
|
|
+ message.put("body", body);
|
|
|
+
|
|
|
+ message.putOpt("janus", "message");
|
|
|
+ message.putOpt("transaction", tid);
|
|
|
+ message.putOpt("session_id", sessionId);
|
|
|
+ message.putOpt("handle_id", currentHandleId);
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ sendMessage(message.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void requestStart(BigInteger channelId, SessionDescription sdp){
|
|
|
+ String tid = randomString(12);
|
|
|
+
|
|
|
+ JSONObject message = new JSONObject();
|
|
|
+ JSONObject body = new JSONObject();
|
|
|
+ try {
|
|
|
+ body.putOpt("request", "start");
|
|
|
+ body.putOpt("id", channelId);
|
|
|
+ message.put("body", body);
|
|
|
+
|
|
|
+ message.putOpt("janus", "message");
|
|
|
+ message.putOpt("transaction", tid);
|
|
|
+ message.putOpt("session_id", sessionId);
|
|
|
+ message.putOpt("handle_id", currentHandleId);
|
|
|
+
|
|
|
+ if (sdp != null) {
|
|
|
+ JSONObject jsep = new JSONObject();
|
|
|
+ jsep.putOpt("type", sdp.type);
|
|
|
+ jsep.putOpt("sdp", sdp.description);
|
|
|
+ message.putOpt("jsep", jsep);
|
|
|
+ }
|
|
|
+ } catch (JSONException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ sendMessage(message.toString());
|
|
|
+ }
|
|
|
+ //---------------------------------------------------- 广播用 结束
|
|
|
+
|
|
|
private synchronized void sendMessage(String message){
|
|
|
if(webSocketChannel!=null){
|
|
|
webSocketChannel.sendMessage(message);
|