Skip to content

Commit

Permalink
Send WebrtcActionTypes.CANCEL to self (mattermost#120)
Browse files Browse the repository at this point in the history
To make WebRTC notification and ringing sound go away when a call has
been accepted or rejected in another session/window, this change sends
WebrtcActionTypes.CANCEL message to self and handles those kind of
messages to silently close call notification dialog when received and
still in ringing state.
  • Loading branch information
longsleep authored and hmhealey committed Oct 27, 2017
1 parent 1ee3c9f commit fad09d2
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions components/webrtc/components/webrtc_notification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,18 @@ export default class WebrtcNotification extends React.Component {
}

onCancelCall(message) {
if (message && message.action !== WebrtcActionTypes.CANCEL) {
return;
} else if (message && message.action === WebrtcActionTypes.CANCEL && this.state.userCalling && message.from_user_id !== this.state.userCalling.id) {
return;
if (message) {
if (message.action !== WebrtcActionTypes.CANCEL) {
return;
}
if (this.state.userCalling) {
if (message.from_user_uid === UserStore.getCurrentId() && message.calling_user_id === this.state.userCalling.id) {
// Allow cancel message from ourselves when the calling user_id matches our current state.
} else if (message.from_user_id !== this.state.userCalling.id) {
// Ignore cancel messages from user_ids which are not in our current state.
return;
}
}
}

WebrtcStore.setVideoCallWith(null);
Expand Down Expand Up @@ -175,6 +183,14 @@ export default class WebrtcNotification extends React.Component {
message.from_user_id = callerId;
message.to_user_id = currentUserId;
WebrtcActions.handle(message);

// Notify current users sessions.
WebSocketClient.sendMessage('webrtc', {
action: WebrtcActionTypes.CANCEL,
from_user_id: currentUserId,
to_user_id: currentUserId,
calling_user_id: callerId
});
}, 0);

this.closeNotification();
Expand All @@ -186,6 +202,14 @@ export default class WebrtcNotification extends React.Component {
e.preventDefault();
}
if (this.state.userCalling) {
// Notify current users sessions.
WebSocketClient.sendMessage('webrtc', {
action: WebrtcActionTypes.CANCEL,
from_user_id: UserStore.getCurrentId(),
to_user_id: UserStore.getCurrentId(),
calling_user_id: this.state.userCalling.id
});

WebSocketClient.sendMessage('webrtc', {
action: WebrtcActionTypes.DECLINE,
from_user_id: UserStore.getCurrentId(),
Expand Down

0 comments on commit fad09d2

Please sign in to comment.