Exemple #1
0
        static void ApiReceived(byte[] bytes, ref int offset, int count)
        {
            while (MessageFactory.TryUnpack(bytes, ref offset, count, out var message))
            {
                Console.WriteLine(" < " + message.Payload);

                switch (message.Payload)
                {
                case CallResponse response:
                    if (!CallController.TryGet(response.SessionId, out _))
                    {
                        SessionId = response.SessionId;

                        CallController.Append(response.SessionId, response.RouteId);
                        Console.WriteLine($" < Call routeID: {response.RouteId}");
                    }
                    break;

                case CallBroadcast broadcast:
                    if (!CallController.TryGet(broadcast.SessionId, out var callSession) && broadcast.State == CallState.Calling)
                    {
                        SessionId = broadcast.SessionId;

                        Send(new CallInviteRequest {
                            SessionId = broadcast.SessionId, RoutePort = CallSocket.Local.Port
                        });
                        Console.WriteLine($" < Call sessionID: {broadcast.SessionId}");
                    }
                    callSession?.RaiseState(broadcast.State);
                    break;

                default:
                    break;
                }
            }
        }