public static ARDSignalingMessage MessageFromJSONString(string json)
        {
            var values = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
            ARDSignalingMessage message = new ARDSignalingMessage();
            var type = values["type"];

            if (type == "candidate")
            {
                RTCICECandidate candidate = new RTCICECandidate(values["id"], nint.Parse(values["label"]), values["candidate"]);
                message = new ARDICECandidateMessage(candidate);
            }
            else if (type == "offer" || type == "answer")
            {
                RTCSessionDescription description = new RTCSessionDescription(type, values["sdp"]);
                message = new ARDSessionDescriptionMessage(description);
            }
            else if (type == "bye")
            {
                message = new ARDByeMessage();
            }
            else
            {
                System.Diagnostics.Debug.WriteLine($"Unexpected type: {type}");
            }
            return(message);
        }
示例#2
0
        public static ARDSignalingMessage MessageFromJSONString(string json)
        {
            var values = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
            ARDSignalingMessage message = new ARDSignalingMessage();
            var type = values["type"];

            switch (type)
            {
            case "candidate":
                nint.TryParse(values["label"], out nint label);
                RTCICECandidate candidate = new RTCICECandidate(values["id"], label, values["candidate"]);
                message = new ARDICECandidateMessage(candidate);
                break;

            case "offer":
            case "answer":
                RTCSessionDescription description = new RTCSessionDescription(type, values["sdp"]);
                message = new ARDSessionDescriptionMessage(description);
                break;

            case "bye":
                message = new ARDByeMessage();
                break;

            default:
                System.Diagnostics.Debug.WriteLine($"Unexpected type: {type}");
                break;
            }

            return(message);
        }
示例#3
0
        public static ARDSignalingMessage MessageFromJSONString(string json)
        {
            var values = JsonConvert.DeserializeObject <Dictionary <string, string> >(json);
            ARDSignalingMessage message = new ARDSignalingMessage();

            if (values.ContainsKey("type"))
            {
                var type = values["type"] ?? "";
                switch (type)
                {
                case "candidate":
                    int.TryParse(values["label"], out int label);
                    RTCIceCandidate candidate = new RTCIceCandidate(values["id"], label, values["candidate"]);
                    message = new ARDICECandidateMessage(candidate);
                    break;

                case "offer":
                    RTCSessionDescription description = new RTCSessionDescription(RTCSdpType.Offer, values["sdp"]);
                    message = new ARDSessionDescriptionMessage(description);
                    break;

                case "answer":
                    description = new RTCSessionDescription(RTCSdpType.Answer, values["sdp"]);
                    message     = new ARDSessionDescriptionMessage(description);
                    break;

                case "bye":
                    message = new ARDByeMessage();
                    break;

                default:
                    System.Diagnostics.Debug.WriteLine($"ARDSignalingMessage unexpected type: {type}");
                    break;
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine($"ARDSignalingMessage invalid json: {json}");
            }

            return(message);
        }