Skip to content

extension subscription using sessionmanager #1098

Open

Description

@md-riaz

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

Activity

  1. Di0go commented on Jan 16, 2025

    @Di0go

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

    Any clues yet?

  2. Di0go commented on Jan 16, 2025

    @Di0go

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

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

  3. md-riaz commented on Jan 18, 2025

    @md-riaz
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions