Skip to content

Commit 965067c

Browse files
author
Igor Khomenko
committed
Video calling sample: send Push Notification when call users.
1 parent 998d226 commit 965067c

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

samples/webrtc/js/app.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@
393393
callParameters.callType = 2
394394
}
395395

396+
// Call to users
397+
//
398+
var pushRecipients = [];
396399
app.currentSession.call({}, function(error) {
397400
if(error) {
398401
console.warn(error.detail);
@@ -409,6 +412,7 @@
409412
'name': app.callees[id],
410413
'state': 'connecting'
411414
});
415+
pushRecipients.push(id);
412416
});
413417

414418
$('.j-callees').append(videoElems);
@@ -418,6 +422,27 @@
418422
app.helpers.setFooterPosition();
419423
}
420424
});
425+
426+
// and also send push notification about incoming call
427+
// (corrently only iOS/Android users will receive it)
428+
//
429+
var params = {
430+
notification_type: 'push',
431+
user: {ids: pushRecipients},
432+
environment: 'development', // environment, can be 'production' as well.
433+
message: QB.pushnotifications.base64Encode(app.caller.full_name + ' is calling you')
434+
};
435+
//
436+
QB.pushnotifications.events.create(params, function(err, response) {
437+
if (err) {
438+
console.log(err);
439+
} else {
440+
// success
441+
console.log("Push Notification is sent.");
442+
}
443+
});
444+
445+
421446
}
422447
});
423448
}
@@ -582,7 +607,7 @@
582607
}
583608
}
584609
});
585-
610+
586611
/** Video recording */
587612
$(document).on('click', '.j-record', function() {
588613
var $btn = $(this),
@@ -643,13 +668,13 @@
643668
* - onCallListener
644669
* - onCallStatsReport
645670
* - onUpdateCallListener
646-
*
671+
*
647672
* - onAcceptCallListener
648673
* - onRejectCallListener
649674
* - onUserNotAnswerListener
650-
*
675+
*
651676
* - onRemoteStreamListener
652-
*
677+
*
653678
* - onStopCallListener
654679
* - onSessionCloseListener
655680
* - onSessionConnectionStateChangedListener
@@ -681,7 +706,7 @@
681706
if(recorder) {
682707
recorder.pause();
683708
}
684-
709+
685710
app.helpers.toggleRemoteVideoView(userId, 'hide');
686711
$('.j-callee_status_' + userId).text('disconnected');
687712

@@ -692,7 +717,7 @@
692717
if(recorder) {
693718
recorder.resume();
694719
}
695-
720+
696721
if(ffHack.waitingReconnectTimer) {
697722
clearTimeout(ffHack.waitingReconnectTimer);
698723
ffHack.waitingReconnectTimer = null;

0 commit comments

Comments
 (0)