|
@@ -1,259 +0,0 @@
|
|
|
-using Blue;
|
|
|
-using GHZRtc;
|
|
|
-using LitJson;
|
|
|
-using Newtonsoft.Json;
|
|
|
-using Newtonsoft.Json.Linq;
|
|
|
-using UnityEngine;
|
|
|
-using UnityEngine.UI;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-public class GHZRTCManager : SingletonMono<GHZRTCManager>, IController
|
|
|
-{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private string uid;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private string channelName;
|
|
|
-
|
|
|
- public string UID
|
|
|
- {
|
|
|
- get => uid;
|
|
|
- set
|
|
|
- {
|
|
|
- if (value != null)
|
|
|
- this.uid = value;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public string ChannelName
|
|
|
- {
|
|
|
- get => channelName;
|
|
|
- set
|
|
|
- {
|
|
|
- if (value != null)
|
|
|
- this.channelName = value;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void Init()
|
|
|
- {
|
|
|
- Debug.LogError("Init");
|
|
|
- GHZRtcManager.Instance.Init();
|
|
|
- }
|
|
|
-
|
|
|
- public string RoomID;
|
|
|
- public void JoinTest()
|
|
|
- {
|
|
|
- EndustryLoginUserInfo sendLogin = new EndustryLoginUserInfo()
|
|
|
- {
|
|
|
- account = "cy2",
|
|
|
- password = "1"
|
|
|
- };
|
|
|
- string jsonLogin = JsonMapper.ToJson(sendLogin);
|
|
|
- HttpTool.Instance.PostLogin("https://api-fat1.ghz-tech.com" + HttpActionLang.login, jsonLogin, mes =>
|
|
|
- {
|
|
|
- JObject obj = JObject.Parse(mes);
|
|
|
- if (obj["code"].ToString() == "200")
|
|
|
- {
|
|
|
- if (!string.IsNullOrWhiteSpace(obj["data"].ToString()) && !string.IsNullOrWhiteSpace(obj["data"]["token"].ToString()))
|
|
|
- {
|
|
|
- login.UserInfo.Instance.Token = obj["data"]["token"].ToString();
|
|
|
-
|
|
|
- JsonData data = new JsonData();
|
|
|
- data["roomId"] = RoomID;
|
|
|
- StartCoroutine(HttpTool.Instance.SendHttp("https://api-fat1.ghz-tech.com" + HttpActionLang.rtc_JoinRoom, data.ToJson(), message =>
|
|
|
- {
|
|
|
- JObject jobject = JObject.Parse(message);
|
|
|
- if (jobject["code"].ToString() == "200" && !string.IsNullOrWhiteSpace(jobject["data"].ToString()))
|
|
|
- {
|
|
|
- Debug.LogError($"加入房间:{jobject["data"].ToString()}");
|
|
|
- RTCRoomInfo mRTCRoomInfo = JsonConvert.DeserializeObject<RTCRoomInfo>(jobject["data"].ToString());
|
|
|
- Debug.LogError($"加入房间成功,房间ID:{mRTCRoomInfo.roomId}");
|
|
|
- Debug.LogError($"地址链接:https://{mRTCRoomInfo.host}");
|
|
|
- Debug.LogError($"Token:{mRTCRoomInfo.token}");
|
|
|
- GHZRtcManager.Instance.ConnectRoom(mRTCRoomInfo.host, mRTCRoomInfo.token);
|
|
|
- }
|
|
|
- }));
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void JoinChannel(string url, string token)
|
|
|
- {
|
|
|
- GHZRtcManager.Instance.ConnectRoom(url, token, false);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void LeaveChannel()
|
|
|
- {
|
|
|
- GHZRtcManager.Instance.DisconnectRoom();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void ShowViewRawImage(string uid, RawImage rawImage)
|
|
|
- {
|
|
|
- foreach (var i in GHZRtcManager.Instance.remoteParticipantViews.Keys)
|
|
|
- {
|
|
|
- if (i.sid == uid)
|
|
|
- {
|
|
|
- rawImage.texture = GHZRtcManager.Instance.remoteParticipantViews[i].VideoView;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void ShowViewMeshRenderer(string uid, MeshRenderer mesh)
|
|
|
- {
|
|
|
- foreach (var i in GHZRtcManager.Instance.remoteParticipantViews.Keys)
|
|
|
- {
|
|
|
- if (i.sid == uid)
|
|
|
- {
|
|
|
- mesh.material.mainTexture = GHZRtcManager.Instance.remoteParticipantViews[i].VideoView;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void MuteLocalAudioStream(bool isAudio)
|
|
|
- {
|
|
|
- GHZRtcManager.Instance.OnMicrophone(isAudio);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void MuteLocalVideoStream(bool isVideo)
|
|
|
- {
|
|
|
- GHZRtcManager.Instance.OnWebCam(isVideo);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void MuteRemoteAudioStream(string uid, bool isAudio)
|
|
|
- {
|
|
|
-
|
|
|
- foreach (var i in GHZRtcManager.Instance.remoteParticipantViews.Keys)
|
|
|
- {
|
|
|
- if (i.sid == uid)
|
|
|
- {
|
|
|
- if (i.audioTracks.Count > 0)
|
|
|
- {
|
|
|
- for (int j = 0; j < i.audioTracks.Count; j++)
|
|
|
- {
|
|
|
- string sid = i.audioTracks[j].sid;
|
|
|
- i.Room.engine.signalClient.SendMuteTrack(sid, !isAudio);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void MuteRemoteVideoStream(string uid, bool isVideo)
|
|
|
- {
|
|
|
-
|
|
|
- foreach (var i in GHZRtcManager.Instance.remoteParticipantViews.Keys)
|
|
|
- {
|
|
|
- if (i.sid == uid)
|
|
|
- {
|
|
|
- if (i.videoTracks.Count > 0)
|
|
|
- {
|
|
|
- for (int j = 0; j < i.videoTracks.Count; j++)
|
|
|
- {
|
|
|
- string sid = i.videoTracks[j].sid;
|
|
|
- i.Room.engine.signalClient.SendMuteTrack(sid, !isVideo);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- public delegate void OnRemoteAudioStateChangedEvent(string uid, REMOTE_AUIDO_STATE_REASON_RTC state);
|
|
|
- public static OnRemoteAudioStateChangedEvent OnRemoteAudioStateChanged;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void RemoteAudioStateChanged(string uid, REMOTE_AUIDO_STATE_REASON_RTC state)
|
|
|
- {
|
|
|
- Debug.Log("uid=RemoteAudioStateChanged=>" + state);
|
|
|
- OnRemoteAudioStateChanged?.Invoke(uid, state);
|
|
|
- }
|
|
|
- public delegate void OnRemoteVideoStateChangedEvent(string uid, REMOTE_VIDEO_STATE_REASON_RTC state);
|
|
|
- public static OnRemoteVideoStateChangedEvent OnRemoteVideoStateChanged;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void RemoteVideoStateChanged(string uid, REMOTE_VIDEO_STATE_REASON_RTC state)
|
|
|
- {
|
|
|
- Debug.Log("uid=RemoteVideoStateChanged=>" + state);
|
|
|
- OnRemoteVideoStateChanged?.Invoke(uid, state);
|
|
|
- }
|
|
|
-
|
|
|
- public delegate void OnUserJoinedEvent(string uid);
|
|
|
- public static OnUserJoinedEvent OnUserJoined;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void UserJoined(string uid)
|
|
|
- {
|
|
|
- Debug.Log("uid=UserJoined=>" + uid);
|
|
|
- OnUserJoined?.Invoke(uid);
|
|
|
- }
|
|
|
-
|
|
|
- public delegate void OnUserOfflineEvent(string uid);
|
|
|
- public static OnUserOfflineEvent OnUserOffline;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void UserOffline(string uid)
|
|
|
- {
|
|
|
- Debug.Log("uid=UserOffline=>" + uid);
|
|
|
- OnUserOffline?.Invoke(uid);
|
|
|
-
|
|
|
- }
|
|
|
-}
|