Ejemplo n.º 1
0
        public void TestJson()
        {
//            SyncPosRotate syncPosRotateS = new SyncPosRotate();
//            syncPosRotateS.id = "ddddd";
//            syncPosRotateS.px = 1.0f;
//            syncPosRotateS.py = 1.0f;
//            syncPosRotateS.pz = 1.0f;
//            syncPosRotateS.rx = 1.0f;
//            syncPosRotateS.ry = 1.0f;
//            syncPosRotateS.rz = 1.0f;
//            syncPosRotateS.type = SyncType.VirtualMan;
//            syncPosRotateS.time = TimeHelper.GetTimestamp();
//
//
//            int structSize = Marshal.SizeOf(typeof(SyncPosRotate));
//            byte[] buffer = EncodeStruct<SyncPosRotate>(syncPosRotateS);
//
//            SyncPosRotate rs = DecodeStruct<SyncPosRotate>(buffer);



            JoinRoom join = new JoinRoom();

            join.id        = (int)NetCmdId.JoinRoom;
            join.data      = new JoinRoom.ResultBean();
            join.data.uid  = "";
            join.data.rid  = "";
            join.data.role = (int)ClientType.Hololens;

            string json = JsonConvert.SerializeObject(join);


            join = JsonConvert.DeserializeObject <JoinRoom>(json);


            JoinRoomRes joinRes = new JoinRoomRes();

            joinRes.id             = (int)NetCmdId.JoinRoomRes;
            joinRes.data           = new JoinRoomRes.ResultBean();
            joinRes.data.isCreator = 1;
            joinRes.data.roomCache = new Dictionary <string, string[]>();
            string[] values = { "anchor1", "anchor2" };
            joinRes.data.roomCache.Add(RoomCacheKey.RoomCacheKeyAnchor, values);

            json = JsonConvert.SerializeObject(joinRes);



            Debug.Log("");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加入房间
        /// </summary>
        /// <param name="uid">用户id</param>
        /// <param name="rid">房间id</param>
        /// <param name="clientType">客户端类型</param>
        /// <param name="roomType">房间类型</param>
        public void JoinRoom(string uid, string rid, ClientType clientType, RoomType roomType)
        {
            this.uid = uid;
            MqttHelper mqtt     = null;
            string     sip      = "";
            int        sport    = 0;
            string     clientid = "";

            if (roomType == RoomType.SpeactorView)
            {
                this.spectatorViewRid = rid;
                sip      = SyncInterface.Instance.MrServerAddress;
                sport    = ServerUrls.MqttPort;
                clientid = "_sv";
                if (spectatorViewNetState == NetState.Connect)
                {
                    return;
                }
                if (spectatorViewMqtt != null)
                {
                    spectatorViewMqtt = null;
                }

                spectatorViewMqtt = new MqttHelper();

                mqtt = spectatorViewMqtt;
            }
            else if (roomType == RoomType.VirtualMan)
            {
                this.virtualManRid = rid;
                sip      = SyncInterface.Instance.MrServerAddress;
                sport    = ServerUrls.MqttPort;
                clientid = "_vm";

                if (virtualManNetState == NetState.Connect)
                {
                    return;
                }
                if (virtualManMqtt != null)
                {
                    virtualManMqtt = null;
                }

                virtualManMqtt = new MqttHelper();

                mqtt = virtualManMqtt;
            }
            if (mqtt == null)
            {
                onJoinRoom?.Invoke(rid, false, false, null, null);
                return;
            }
            mqtt.onConnectStateChange += Mqtt_onConnectStateChange;
            mqtt.OnReceiveMsg         += Mqtt_OnReceiveMsg;
            mqtt.OnReceiveByteMsg     += Mqtt_OnReceiveCmdMsg;

            mqtt.Connect(sip, sport, uid, "111", uid + clientid, new MqttConnectDelegate(
                             (MqttHelper t, bool result) =>
            {
                if (result)
                {
                    mqtt.SubscribeMsg(rid, new ResultDelegate <bool>((bool subResult) => { }));
                    mqtt.SubscribeMsg(uid, new ResultDelegate <bool>((bool subResult) => { }));

                    if (roomType == RoomType.SpeactorView)
                    {
                        spectatorViewNetState = NetState.Connect;
                    }
                    else
                    {
                        virtualManNetState = NetState.Connect;
                    }

                    // TODO: send join room
                    JoinRoom join  = new JoinRoom();
                    join.id        = (int)NetCmdId.JoinRoom;
                    join.data      = new JoinRoom.ResultBean();
                    join.data.uid  = uid;
                    join.data.rid  = rid;
                    join.data.role = (int)clientType;
                    string json    = JsonConvert.SerializeObject(join);

                    t.PublishMsg(MessageType.System, SystemTargetId, json, new MqttSendMsgDelegate((bool res) => {
                        //int i = 0;
                    }));
                }
                else
                {
                    onJoinRoom?.Invoke(rid, false, false, null, null);
                }
            }));
        }