123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- using LitJson;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public abstract class SCRtcManager : MonoBehaviour
- {
- public Queue<JsonData> queue;
- private void Start()
- {
- }
- public void InitListener()
- {
- queue = new Queue<JsonData>();
- /*
- StopCoroutine("onUpdateRtc");
- StartCoroutine("onUpdateRtc");*/
- Debug.Log("StartListener");
- }
- private void Update()
- {
- SCRtcFactory.Instance.Update();
- }
- IEnumerator onUpdateRtc()
- {
- while (true)
- {
- yield return new WaitForEndOfFrame();
- SCRtcFactory.Instance.Update();
- yield return new WaitForEndOfFrame();
- }
- }
- public virtual void OnRtcListener(JsonData data)
- {
- string pid;
- SCRtcPeer p;
- if (data != null)
- {
- switch (data["action"].ToString())
- {
-
- case "OnListener":
- switch (data["data"]["action"].ToString())
- {
- case "addPeer":
- SCRtcFactory.Instance.mSCRtcPeers.getPeer(data["data"]["data"]["pid"].ToString()).setInfo(data["data"]["data"]["kind"].ToString(), data["data"]["data"]["cid"].ToString(),true);
- break;
- case "addVideo":
- pid = data["data"]["data"]["peerID"].ToString();
- SCRtcFactory.Instance.mSCRtcPeers.getPeer(pid).setTexture(data);
- break;
- case "changeResolution":
- pid = data["data"]["data"]["peerID"].ToString();
- if (pid != "Local")
- {
- SCRtcFactory.Instance.mSCRtcPeers.getPeer(pid).changeTexture(data);
- }
- break;
- }
- break;
- case "onNotification":
- switch (data["method"].ToString())
- {
- case "closed":
- pid = data["data"]["peerId"].ToString();
- SCRtcFactory.Instance.mSCRtcPeers.removePeers(pid);
-
- break;
- case "joined":
- p = SCRtcFactory.Instance.mSCRtcPeers.addPeers(data["data"]["peerId"].ToString());
- p.setName(data["data"]["nickName"].ToString());
- p.avater = data["data"]["avatar"].ToString();
- p.isSn =bool.Parse(data["data"]["sn"].ToString());
- break;
- case "joinRoom":
- if (data["data"]["room"]["users"].Count > 0)
- {
- for (int i = 0; i < data["data"]["room"]["users"].Count; i++)
- {
- SCRtcPeer sp = SCRtcFactory.Instance.mSCRtcPeers.addPeers(data["data"]["room"]["users"][i]["peerId"].ToString());
- sp.setName(data["data"]["room"]["users"][i]["nickName"].ToString()); ;
- sp.avater = data["data"]["room"]["users"][i]["avatar"].ToString();
- sp.isSn = bool.Parse(data["data"]["room"]["users"][i]["sn"].ToString());
- if (int.Parse(data["data"]["room"]["users"][i]["isCreator"].ToString()) == 1)
- {
- switch (data["data"]["room"]["users"][i]["sn"].ToString())
- {
- case "false":
- RoomMainInfo.isSN = false;
- break;
- case "true":
- RoomMainInfo.isSN = true;
- break;
- }
- RoomMainInfo.isCreator = "1";
- RoomMainInfo.RoomOwner = "用户" + data["data"]["room"]["users"][i]["nickName"].ToString() + "的房间";
- RoomMainInfo.RoomCreatorActivateType = int.Parse(data["data"]["room"]["users"][i]["activateType"].ToString());
- }
- }
- }
- else
- {
- if (!string.IsNullOrEmpty(RoomMainInfo.roomName))
- {
- RoomMainInfo.isCreator = "0";
- RoomMainInfo.RoomOwner = RoomMainInfo.roomName;
- RoomMainInfo.isSN = UserInfo.isSN;
- RoomMainInfo.RoomCreatorActivateType = UserInfo.activateType;
- }
- }
- if (data["data"]["room"].Keys.Contains("fileHistory"))
- {
- if (data["data"]["room"]["fileHistory"].Count > 0)
- {
- for (int i = 0; i < data["data"]["room"]["fileHistory"].Count; i++)
- {
- FileConfig fileConfig = new FileConfig();
- fileConfig.PeerId = data["data"]["room"]["fileHistory"][i]["peerId"].ToString();
- fileConfig.From = data["data"]["room"]["fileHistory"][i]["from"].ToString();
- fileConfig.CreateTime = data["data"]["room"]["fileHistory"][i]["createTime"].ToString();
- fileConfig.Url = data["data"]["room"]["fileHistory"][i]["url"].ToString();
- fileConfig.Path = data["data"]["room"]["fileHistory"][i]["path"].ToString();
- fileConfig.FileName = data["data"]["room"]["fileHistory"][i]["fileName"].ToString();
- if (ShowRoom.Instance)
- {
- ShowRoom.Instance.fileConfiglist.Add(fileConfig);
- }
- }
- }
- }
- break;
- case "init":
- SCRtcFactory.Instance.mSCRtcConfig.routerRtpCapabilities = data["data"].ToJson();
- SCRtcFactory.Instance.mSCRtcHandle.joinRoom(SCRtcFactory.Instance.mSCRtcConfig.routerRtpCapabilities);
-
- break;
- }
- break;
- }
- }
- }
- }
|