Permalink
Browse files

Fix bug in video chat

Click event on accept/reject call button was triggered more than once
due to binding of event more than once in strem accept checker callback.
  • Loading branch information...
D-Ne0 committed Jun 14, 2014
1 parent e9d7488 commit 6ebb78ae2455c936f036d3cfee1da94f76468812
Showing with 11 additions and 17 deletions.
  1. +11 −17 app/client/chat/video_chat/lib/video_rtc.js
@@ -65,15 +65,11 @@ VideoChat = (function () {
$('.call-accept-label').text(acceptMsg);
- var _mediaSuccessCB = function () {
+ var mediaSuccessCB = function () {
CB(true);
Session.set('otherEasyrtcId', easyrtcId);
};
- var mediaSuccessCB = (function () {
- return _mediaSuccessCB;
- })(easyrtcId, CB);
-
var mediaErrorCB = function (errCode, errText) {
$('.errMsg').text(errText);
$('.errMsg').show().delay(5000).fadeOut();
@@ -85,9 +81,9 @@ VideoChat = (function () {
$('#video-server-link').click();
}
if (easyrtc.getLocalStream()) {
- _mediaSuccessCB();
+ mediaSuccessCB();
} else {
- easyrtc.initMediaSource(_mediaSuccessCB, mediaErrorCB);
+ easyrtc.initMediaSource(mediaSuccessCB, mediaErrorCB);
}
};
@@ -96,10 +92,12 @@ VideoChat = (function () {
CB(false);
};
- $('#call-accept-btn').click(function () {
+ // First unbind then bind again click event
+ // to prevent triggering it twice
+ $('#call-accept-btn').off('click').on('click', function () {
acceptTheCall();
});
- $('#call-reject-btn').click(function () {
+ $('#call-reject-btn').off('click').on('click', function () {
rejectTheCall();
});
};
@@ -169,15 +167,12 @@ VideoChat = (function () {
if (!hangout)
return;
+ easyrtc.hangupAll();
Session.set('videoCallingId', otherEasyrtcId);
- var _mediaSuccessCB = function () {
+ var mediaSuccessCB = function () {
easyrtc.call(otherEasyrtcId, successCB, errorCB, acceptedCB);
- }
-
- var mediaSuccessCB = (function () {
- return _mediaSuccessCB;
- })(otherEasyrtcId);
+ };
var mediaErrorCB = function (errCode, errText) {
$('.errMsg').text(errText);
@@ -187,9 +182,8 @@ VideoChat = (function () {
var enableCamera = Session.get('cameraEnabled') ? true : false;
easyrtc.enableCamera(enableCamera);
- easyrtc.hangupAll();
if (easyrtc.getLocalStream()) {
- _mediaSuccessCB();
+ mediaSuccessCB();
} else {
easyrtc.initMediaSource(mediaSuccessCB, mediaErrorCB);
}

0 comments on commit 6ebb78a

Please sign in to comment.