extension subscription using sessionmanager
`async function subscribeContactExt(contact, account) { try {
// get userAgent from sipAccounts
const sessionManager = sipAccounts[account.id].sessionManager;
const userAgent = sessionManager.userAgent;
// Create a new subscriber.
const targetURI = new URI("sip", contact.number, account.domain);
const eventType = "presence";
const subscriber = new Subscriber(userAgent, targetURI, eventType);
// Add delegate to handle event notifications.
subscriber.delegate = {
onNotify: (notification) => {
// send a response
notification.accept();
// handle notification here
console.log('Notification received:', notification);
updateContactPresence(contact, notification.request.body);
},
onSubscribe: (subscription) => {
console.log('Subscribed to contact:', contact);
updateContactPresence(contact, 'subscribed');
},
onRefresh: (subscription) => {
console.log('Refreshed subscription:', contact);
}
};
// Monitor subscription state changes.
subscriber.stateChange.addListener((newState) => {
switch (newState) {
case SubscriptionState.Terminated:
console.log('Subscription terminated');
updateContactPresence(contact, 'terminated');
break;
case SubscriptionState.Subscribed:
console.log('Subscription subscribed');
updateContactPresence(contact, 'subscribed');
break;
case SubscriptionState.NotifyWait:
console.log('Subscription notify wait');
updateContactPresence(contact, 'notify wait');
break;
default:
console.log('Subscription state changed:', newState);
break;
}
});
// Attempt to establish the subscription
await subscriber.subscribe();
// add subscriber to subscription
sipAccounts[account.id].subscribers[contact.number] = subscriber;
console.log('Subscription established:', contact.number);
} catch (error) { console.error('Error subscribing to contact:', error); } }`
after running this code i only get, console.log('Subscription notify wait');
console.log('Subscription established:', contact.number);
and after sometime, console.log('Subscription terminated');
does this work with userAgent of sessionManager?
Assalamu Alaikum @md-riaz, I am facing the same problem!
Any clues yet?
After some research, you might want to checkout this past issue.
Apparently Freeswitch has a hard time handling presence notifications with TLS/WSS.
https://github.com/signalwire/freeswitch/issues/398