|
464 | 464 | }
|
465 | 465 |
|
466 | 466 | // Call to users
|
467 |
| - // |
468 |
| - var pushRecipients = []; |
469 | 467 | app.currentSession.call({}, function() {
|
470 | 468 | if (!window.navigator.onLine) {
|
471 | 469 | app.currentSession.stop({});
|
472 | 470 | app.helpers.stateBoard.update({'title': 'connect_error', 'isError': 'qb-error'});
|
473 | 471 | } else {
|
| 472 | + sendPushNotification(); |
474 | 473 | var compiled = _.template( $('#callee_video').html() );
|
475 | 474 |
|
476 | 475 | app.helpers.stateBoard.update({'title': 'calling'});
|
477 | 476 |
|
478 | 477 | document.getElementById(sounds.call).play();
|
479 | 478 |
|
480 |
| - Object.keys(app.callees).forEach(function(id, i, arr) { |
| 479 | + Object.keys(app.callees).forEach(function (id) { |
481 | 480 | videoElems += compiled({
|
482 | 481 | 'userID': id,
|
483 | 482 | 'name': app.callees[id],
|
484 | 483 | 'state': 'connecting'
|
485 | 484 | });
|
486 |
| - pushRecipients.push(id); |
487 | 485 | });
|
488 | 486 |
|
489 | 487 | $('.j-callees').append(videoElems);
|
|
493 | 491 | app.helpers.setFooterPosition();
|
494 | 492 | }
|
495 | 493 | });
|
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 |
| - |
521 | 494 | }
|
522 | 495 | });
|
523 | 496 | }
|
|
1248 | 1221 |
|
1249 | 1222 | app.currentSession.switchMediaTracks(deviceIds, callback);
|
1250 | 1223 | }
|
| 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 | + } |
1251 | 1270 | });
|
1252 | 1271 | }(window, window.QB, window.app, window.CONFIG, jQuery, Backbone));
|
0 commit comments