Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extension subscription using sessionmanager #1098

Open
md-riaz opened this issue Jan 8, 2025 · 3 comments
Open

extension subscription using sessionmanager #1098

md-riaz opened this issue Jan 8, 2025 · 3 comments

Comments

@md-riaz
Copy link

md-riaz commented Jan 8, 2025

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

@Di0go
Copy link

Di0go commented Jan 16, 2025

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

Any clues yet?

@Di0go
Copy link

Di0go commented Jan 16, 2025

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

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

@md-riaz
Copy link
Author

md-riaz commented Jan 18, 2025

signalwire/freeswitch#398

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants