SIP.js icon indicating copy to clipboard operation
SIP.js copied to clipboard

extension subscription using sessionmanager

Open md-riaz opened this issue 1 year ago • 3 comments

`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?

md-riaz avatar Jan 08 '25 05:01 md-riaz

Assalamu Alaikum @md-riaz, I am facing the same problem!

Any clues yet?

Di0go avatar Jan 16 '25 02:01 Di0go

After some research, you might want to checkout this past issue.

Apparently Freeswitch has a hard time handling presence notifications with TLS/WSS.

Di0go avatar Jan 16 '25 02:01 Di0go

https://github.com/signalwire/freeswitch/issues/398

md-riaz avatar Jan 18 '25 17:01 md-riaz