Skip to content

Commit

Permalink
fix: only respond to app that sent message
Browse files Browse the repository at this point in the history
We know the AppInstance ID of the app that sends a message to the
desktop. We now append this ID to the message. Therefore, when
responding to the message, we only send it if the AppInstance ID
matches the one on the PhaseApp component.

closes #136
  • Loading branch information
juancarlosfarah committed Jul 17, 2019
1 parent 180533d commit 19f9a3d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/actions/appInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const getAppInstance = async (

if (appInstance) {
callback({
appInstanceId: id,
type: GET_APP_INSTANCE_SUCCEEDED,
payload: appInstance,
});
Expand All @@ -42,6 +43,7 @@ const getAppInstance = async (
GET_APP_INSTANCE_CHANNEL,
async (event, response) => {
callback({
appInstanceId: id,
type: GET_APP_INSTANCE_SUCCEEDED,
payload: response,
});
Expand Down
5 changes: 5 additions & 0 deletions src/actions/appInstanceResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const getAppInstanceResources = async (
GET_APP_INSTANCE_RESOURCES_CHANNEL,
async (event, response) => {
callback({
// have to include the appInstanceId to avoid broadcasting
appInstanceId,
type: GET_APP_INSTANCE_RESOURCES_SUCCEEDED,
payload: response,
});
Expand Down Expand Up @@ -55,6 +57,8 @@ const postAppInstanceResource = async (
POST_APP_INSTANCE_RESOURCE_CHANNEL,
async (event, response) => {
callback({
// have to include the appInstanceId to avoid broadcasting
appInstanceId,
type: POST_APP_INSTANCE_RESOURCE_SUCCEEDED,
payload: response,
});
Expand Down Expand Up @@ -82,6 +86,7 @@ const patchAppInstanceResource = async (
PATCH_APP_INSTANCE_RESOURCE_CHANNEL,
async (event, response) => {
callback({
appInstanceId,
type: PATCH_APP_INSTANCE_RESOURCE_SUCCEEDED,
payload: response,
});
Expand Down
11 changes: 11 additions & 0 deletions src/components/phase/PhaseApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ class PhaseApp extends Component {
}

postMessage = data => {
// get component app instance id
const { appInstance } = this.props;
const { id: componentAppInstanceId } = appInstance || {};
// get app instance id in message
const { appInstanceId: messageAppInstanceId } = data;

// only post message to intended app instance
if (componentAppInstanceId !== messageAppInstanceId) {
return;
}

const message = JSON.stringify(data);

if (this.iframe.contentWindow.postMessage) {
Expand Down

0 comments on commit 19f9a3d

Please sign in to comment.