예제 #1
0
        public async Task CallEnd(string message)
        {
            try
            {
                JObject objMessage    = JObject.Parse(message);
                int     RoomId        = (int)objMessage["RoomId"];
                int     AppointmentId = (int)objMessage["AppointmentId"];
                string  Status        = (string)objMessage["Status"];
                await _providerManager.UpdateAppointmentEndTime(AppointmentId);

                var roomDetails = await _providerManager.GetRoomDetails(RoomId);

                var appointmentDetails = await _providerManager.GetAppointmentDetailsById(AppointmentId);

                await Groups.RemoveFromGroupAsync(roomDetails.RoomName, Context.ConnectionId);

                await Groups.RemoveFromGroupAsync(appointmentDetails.RoomSID, Context.ConnectionId);

                if (objMessage["Role"] != null && (string)objMessage["Role"] == "patient")
                {
                    int PatientId = (int)objMessage["ParticipantId"];
                    await _commonManager.UpdateParticipantStatus(new CallParticipantModel
                    {
                        AppointmentId = AppointmentId,
                        RoomId        = RoomId,
                        ParticipantId = PatientId,
                        Status        = Status,
                        Role          = "patient"
                    });

                    var socketids = await _providerManager.GetProviderToken(RoomId);

                    foreach (string socketid in socketids)
                    {
                        await Clients.Client(socketid).SendAsync("ParticipantDisconnected", new JObject
                        {
                            ["AppointmentId"] = objMessage["AppointmentId"],
                            ["PatientId"]     = PatientId,
                        }.ToString());
                    }
                }
                else
                {
                    await Clients.Group(roomDetails.RoomName).SendAsync("onDocStatusSchange", new JObject
                    {
                        ["status"] = "onlineGreen"
                    }.ToString());

                    var participants = await _commonManager.GetParticipantsByAppointmentId(AppointmentId);

                    foreach (CallParticipantModel participant in participants)
                    {
                        await Clients.Client(participant.SocketId).SendAsync("ParticipantDisconnected", new JObject
                        {
                            ["AppointmentId"] = objMessage["AppointmentId"],
                        }.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                await Clients.Caller.SendAsync("Exception", new JObject
                {
                    ["error"]      = ex.Message,
                    ["stackTrace"] = ex.StackTrace
                }.ToString());
            }
        }