You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to push notifications to clients who have connected to SignalR Hub based on related events are happening in PBX VOIP server.
I can get events using DeviceStateChangedEvent class from AsterNet using an event handler and want to push notification to clients related to their devices' state changes.
Also, SignalR connection is working as well and welcome message is showing on client web page.
But the problem is while sending notification by SendAsync method to caller client, my Hub goes to be disposed and below exception raised:
System.ObjectDisposedException: 'Cannot access a disposed object.
Object name: 'AgentHub'.'
Here is my Hub class.
using Microsoft.AspNetCore.SignalR;
using System;
using System.Threading.Tasks;
using AutoDialFinal.Models;
using AsterNET.ARI;
using AsterNET.ARI.Models;
namespace AutoDial.Hubs
{
public class AgentHub : Hub
{
public AgentHub()
{
AriClient ActionClient;
ActionClient = new AriClient(
new StasisEndpoint("voip", 8088, "root", "password"),
"HelloWorld",
true);
ActionClient.OnDeviceStateChangedEvent += ActionClientDeviceStateChangeEventAsync;
ActionClient.Connect();
void ActionClientDeviceStateChangeEventAsync(IAriClient sender, DeviceStateChangedEvent e)
{
var notification = new DeviceStateChangeNotification
{
NotificationText = e.Device_state.Name + "'s state changed to " + e.Device_state.State,
SentAt = DateTime.Now.ToString()
};
SendNotificationToAgentAsync(notification);
}
}
public override async Task OnConnectedAsync()
{
var notification = new DeviceStateChangeNotification
{
NotificationText = "Welcome!",
SentAt = DateTime.Now.ToString()
};
await Clients.Caller.SendAsync(
"ReceiveNotification",
notification.NotificationText,
notification.SentAt
);
await base.OnConnectedAsync();
}
public void SendNotificationToAgentAsync(DeviceStateChangeNotification notif)
{
Clients.Caller.SendAsync(
"ReceiveNotification",
notif.NotificationText,
notif.SentAt
);
}
}
}
Exception will raise in below method in ARIClient class while any device state change happening in PBX:
private void _eventProducer_OnMessageReceived(object sender, MessageEventArgs e)
{
Debug.WriteLine(e.Message);
// load the message
var jsonMsg = (JObject)JToken.Parse(e.Message);
var eventName = jsonMsg.SelectToken("type").Value<string>();
var type = Type.GetType("AsterNET.ARI.Models." + eventName + "Event");
var evnt =
(type != null)
? (Event)JsonConvert.DeserializeObject(e.Message, type)
: (Event)JsonConvert.DeserializeObject(e.Message, typeof(Event));
lock (_syncRoot)
{
if (_dispatcher == null)
return;
_dispatcher.QueueAction(() =>
{
try
{
FireEvent(evnt.Type, evnt, this);
}
catch(Exception ex)
{
**// HERE IS WERE EXCEPTION IS RAISING**
// Handle any exceptions that were thrown by the invoked event handler
if (!UnhandledException(this, ex))
{
Console.WriteLine("The event listener " + evnt.Type.ToString() + " cause an exeption: " + ex.Message);
}
}
});
}
}
How do I fix this problem?
Thank you
The text was updated successfully, but these errors were encountered:
I'm trying to push notifications to clients who have connected to SignalR Hub based on related events are happening in PBX VOIP server.
I can get events using DeviceStateChangedEvent class from AsterNet using an event handler and want to push notification to clients related to their devices' state changes.
Also, SignalR connection is working as well and welcome message is showing on client web page.
But the problem is while sending notification by SendAsync method to caller client, my Hub goes to be disposed and below exception raised:
Here is my Hub class.
Exception will raise in below method in ARIClient class while any device state change happening in PBX:
How do I fix this problem?
Thank you
The text was updated successfully, but these errors were encountered: