How to add presence subscription?
Dear innovaphone forum,
How to add presence subscription for badgecounting in my js runtime?
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"); }); });
{
"javascript": {
"eval": [
"innovaphone-jsbadgeexampleservice.js"
]
},
"apis": {
"innovaphone-jsbadgeexample": {
"presence": true
}
}
}