Skip to content

Commit 47bf023

Browse files
author
Oleksandr Shvetsov
committed
Updated VoIP push notification payload
1 parent 92d8270 commit 47bf023

File tree

1 file changed

+48
-29
lines changed

1 file changed

+48
-29
lines changed

samples/webrtc/js/app.js

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -464,26 +464,24 @@
464464
}
465465

466466
// Call to users
467-
//
468-
var pushRecipients = [];
469467
app.currentSession.call({}, function() {
470468
if (!window.navigator.onLine) {
471469
app.currentSession.stop({});
472470
app.helpers.stateBoard.update({'title': 'connect_error', 'isError': 'qb-error'});
473471
} else {
472+
sendPushNotification();
474473
var compiled = _.template( $('#callee_video').html() );
475474

476475
app.helpers.stateBoard.update({'title': 'calling'});
477476

478477
document.getElementById(sounds.call).play();
479478

480-
Object.keys(app.callees).forEach(function(id, i, arr) {
479+
Object.keys(app.callees).forEach(function (id) {
481480
videoElems += compiled({
482481
'userID': id,
483482
'name': app.callees[id],
484483
'state': 'connecting'
485484
});
486-
pushRecipients.push(id);
487485
});
488486

489487
$('.j-callees').append(videoElems);
@@ -493,31 +491,6 @@
493491
app.helpers.setFooterPosition();
494492
}
495493
});
496-
497-
// and also send push notification about incoming call
498-
// (corrently only iOS/Android users will receive it)
499-
//
500-
var params = {
501-
notification_type: 'push',
502-
user: {ids: pushRecipients},
503-
environment: 'development', // environment, can be 'production' as well.
504-
message: QB.pushnotifications.base64Encode(JSON.stringify({
505-
"message": app.caller.full_name + " is calling you",
506-
"ios_voip": "1",
507-
"VOIPCall":"1"
508-
}))
509-
};
510-
//
511-
QB.pushnotifications.events.create(params, function(err, response) {
512-
if (err) {
513-
console.log(err);
514-
} else {
515-
// success
516-
console.log("Push Notification is sent.");
517-
}
518-
});
519-
520-
521494
}
522495
});
523496
}
@@ -1248,5 +1221,51 @@
12481221

12491222
app.currentSession.switchMediaTracks(deviceIds, callback);
12501223
}
1224+
1225+
function sendPushNotification() {
1226+
// and also send push notification about incoming call
1227+
// (currently only iOS/Android users will receive it)
1228+
var users = [app.caller].concat(app.users);
1229+
var opponentsIDsNumbers = app.currentSession
1230+
.opponentsIDs
1231+
.map(Number);
1232+
var opponentsIDs = [app.currentSession.initiatorID].concat(opponentsIDsNumbers);
1233+
var contactIdentifier = opponentsIDs
1234+
.map(function (userId) {
1235+
var user = users.find(function (usr) {
1236+
return usr.id === userId
1237+
});
1238+
return user ? user.full_name : undefined;
1239+
})
1240+
.filter(Boolean)
1241+
.join();
1242+
var pushPayload = {
1243+
message: app.caller.full_name + " is calling you",
1244+
ios_voip: 1,
1245+
VOIPCall: 1,
1246+
sessionID: app.currentSession.ID,
1247+
opponentsIDs: opponentsIDs.join(),
1248+
contactIdentifier: contactIdentifier,
1249+
conferenceType: app.currentSession.callType.toString(),
1250+
timestamp: Date.now().toString()
1251+
};
1252+
var params = {
1253+
notification_type: 'push',
1254+
user: {ids: opponentsIDsNumbers},
1255+
environment: 'development', // environment, can be 'production' as well.
1256+
message: QB.pushnotifications.base64Encode(
1257+
JSON.stringify(pushPayload)
1258+
)
1259+
};
1260+
//
1261+
QB.pushnotifications.events.create(params, function (error) {
1262+
if (error) {
1263+
console.log(error);
1264+
} else {
1265+
// success
1266+
console.log("Push Notification is sent.");
1267+
}
1268+
});
1269+
}
12511270
});
12521271
}(window, window.QB, window.app, window.CONFIG, jQuery, Backbone));

0 commit comments

Comments
 (0)