Picture of nickname
Registered 3 years 37 days
nickname Sunday, 1 May 2022, 01:21 AM
How to add presence subscription?
Dear innovaphone forum,

How to add presence subscription for badgecounting in my js runtime?


Andreas Fink
Moderator Registered 13 years 52 days
Andreas Fink (innovaphone) Monday, 2 May 2022, 12:17 PM
Re: How to add presence subscription?
Hello Nick,

few steps are required:

  • connect PbxSignal API
  • register to the PBX with NO_MEDIA_CALL flag
  • handle incoming Signaling requests with facility type "presence_subscribe"
    • connect this calls
    • store call id for later use
  • send Signaling request for particular call with facility type "presence_notify"

Please find below an example.

Best Regards
Andreas Fink




new PbxApi("PbxSignal").onconnected(function (conn) {
    log("PbxSignal: connected");

    connections.push(conn);

    conn.send(JSON.stringify({ "api": "PbxSignal", "mt": "Register", "flags": "NO_MEDIA_CALL" }));

    conn.onmessage(function (msg) {
        var obj = JSON.parse(msg);
        log(msg);

        if (obj.mt == "RegisterResult") {
            log("PBXSignal: registration result " + JSON.stringify(obj));
        }

        if (obj.mt == "Signaling") {
            if (obj.sig.type == "setup") {

                // handle incoming presence_subscribe call
                // the callid "obj.call" required later for sending badge notifications
                if (obj.sig.fty.some(function (v) { return v.type === "presence_subscribe"; })) {
                    log("PbxSignal: incoming presence subscription for user " + obj.sig.cg.sip);

                    // connect call
                    conn.send(JSON.stringify({ "mt": "Signaling", "api": "PbxSignal", "call": obj.call, "sig": { "type": "conn" } }));


                    // send notification with badge count 2
                    conn.send(JSON.stringify(
                        {
                            "api": "PbxSignal",
                            "mt": "Signaling",
                            "call": obj.call,
                            "sig": {
                                "fty": [
                                    {
                                        "contact": "app:",
                                        "note": "#badge:2",
                                        "status": "open",
                                        "type": "presence_notify"
                                    }
                                ],
                                "type": "facility"
                            },
                            "src": "badge"
                        }
                    ));
                    
                }
            }
            
        }
         
    });

    conn.onclose(function () {
        log("PbxSignal: disconnected");
    });
});






Picture of nickname
Registered 3 years 37 days
nickname Monday, 2 May 2022, 12:55 PM
Re: How to add presence subscription?
Thank you for the quick respond.

My goal is to get the signal trigger from the myapps client.
On c++ side we implemented like this:

void NewApp1::AppWebsocketAppInfo(const char * app, class json_io & msg, word base) {
// Enable App Service for presence Subscriptions
msg.add_bool(base, "presence", true);
}

How can i activate it in my js runtime?
Andreas Fink
Moderator Registered 13 years 52 days
Andreas Fink (innovaphone) Monday, 2 May 2022, 01:37 PM
Re: How to add presence subscription?
You have to set it in the config.json. See example below.


https://sdk.innovaphone.com/13r2/doc/appgeneric.htm#config-config


{
"javascript": {
"eval": [
"innovaphone-jsbadgeexampleservice.js"
]
},
"apis": {
"innovaphone-jsbadgeexample": {
"presence": true
}
}
}
Picture of nickname
Registered 3 years 37 days
nickname Monday, 2 May 2022, 02:16 PM
Re: How to add presence subscription?
Thank you. It works fine.

Is there any possibility to change the color of the badge or use the ✓ from your business hours app?
Andreas Fink
Moderator Registered 13 years 52 days
Andreas Fink (innovaphone) Monday, 2 May 2022, 09:25 PM
Re: How to add presence subscription?
No, red colour is by default. What exactly your use case?

Best regards
Andreas Fink
Picture of nickname
Registered 3 years 37 days
nickname Tuesday, 3 May 2022, 01:26 PM
Re: How to add presence subscription?
In my opinion the red color is for alerts or alarms...
A green color for a confirmation or if my app icon is red than a contrast would be nice for example.

← You can define your color theme preference here