hemaxox / sipml5

Automatically exported from code.google.com/p/sipml5
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Adds support for MWI #2

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

Please use labels and text to provide additional information.

Original issue reported on code.google.com by boss...@yahoo.fr on 29 Mar 2012 at 5:55

GoogleCodeExporter commented 8 years ago
While there is no simple built in solution to directly use MWI right now, you 
can easily just implement your own MWI subscription using the subscribe 
function. Tested this method with Asterisk and it works just fine. If someone 
feels like it they can just create wrapper functions in the sipml5 source code 
to use the below logic, but I'm sure testing is needed for use with other PBX 
platforms. The stuff in sip_caps is probably not needed.

function SubscribeMWI() {
    console.log("Softphone: Subscribing to MWI");
    var softphoneMWISession = softphoneSIPStack.newSession('subscribe', {
        expires: 300,
        events_listener: {
            events: '*', listener:
            function (e) {
                if (e.type == 'i_notify' && e.getContentType() == 'application/simple-message-summary') {
                    var matches = e.getContentString().match(/Voice\-Message: ([0-9]+)\/([0-9]+)/);
                    if (matches.length == 3) {
                        var newMessages = matches[1],
                            oldMessages = matches[2];
                        //TODO: Use newMessages and oldMessages however you please, you probably only care about newMessages
                    }
                } else if (e.type == 'connected') {
                    console.log('Softphone: Subscription to MWI successful');
                } else if (e.type == 'terminated') {
                    console.log('Softphone: Subscription to MWI failed');
                    //TODO: Attempt to subscribe again in a couple minutes? Or bail out.
                }
            }
        },
        sip_headers: [
            { name: 'Event', value: 'message-summary' },
            { name: 'Accept', value: 'application/simple-message-summary' }
        ],
        sip_caps: [
            { name: '+g.oma.sip-im', value: null },
            { name: '+audio', value: null },
            { name: 'language', value: '\"en\"' }
        ]
    });
    softphoneMWISession.subscribe('PUT_THE_CURRENT_USERS_AUTH_ID_OR_EXTENSION_HERE');
}

Original comment by CraigShe...@gmail.com on 8 Jan 2015 at 5:27