@maxzima/wa-communicator 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/engine/CommunicatorReceiver.d.ts +1 -0
- package/dist/engine/CommunicatorReceiver.js +2 -1
- package/dist/engine/CommunicatorSender.d.ts +1 -1
- package/dist/engine/CommunicatorSender.js +3 -3
- package/dist/types/index.d.ts +2 -1
- package/package.json +1 -1
- package/src/engine/CommunicatorReceiver.ts +3 -1
- package/src/engine/CommunicatorSender.ts +4 -4
- package/src/types/index.ts +2 -1
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
|
|
33
33
|
```javascript
|
|
34
34
|
const communicator = new CommunicatorSender({
|
|
35
|
-
|
|
35
|
+
receiverOrigin: 'google.com',
|
|
36
36
|
otherWindow: window.parent,
|
|
37
37
|
});
|
|
38
38
|
|
|
@@ -52,6 +52,7 @@ communicator.sendMessage({
|
|
|
52
52
|
|
|
53
53
|
```javascript
|
|
54
54
|
const communicator = new CommunicatorReceiver({
|
|
55
|
+
senderOrigin: 'clients.google.com',
|
|
55
56
|
callback: (message) => {
|
|
56
57
|
if (message.target === CommunicatorTargetEnum.SIGN_UP && message.action[CommunicatorActionEnum.GOTO]) {
|
|
57
58
|
window.location.href = message.action[CommunicatorActionEnum.GOTO].url;
|
|
@@ -12,7 +12,7 @@ export class CommunicatorReceiver {
|
|
|
12
12
|
console.log('PostMessage read error');
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
if (
|
|
15
|
+
if (this.senderOrigin !== event.origin) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
if (typeof this.callback !== 'function') {
|
|
@@ -21,6 +21,7 @@ export class CommunicatorReceiver {
|
|
|
21
21
|
this.callback(message);
|
|
22
22
|
};
|
|
23
23
|
this.callback = props.callback;
|
|
24
|
+
this.senderOrigin = props.senderOrigin;
|
|
24
25
|
}
|
|
25
26
|
watch() {
|
|
26
27
|
window.addEventListener('message', this.onMessage, false);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TCommunicatorMessage, TSenderProps } from '../types';
|
|
2
2
|
export declare class CommunicatorSender {
|
|
3
3
|
private readonly otherWindow;
|
|
4
|
-
private readonly
|
|
4
|
+
private readonly receiverOrigin;
|
|
5
5
|
constructor(props: TSenderProps);
|
|
6
6
|
sendMessage(message: TCommunicatorMessage): void;
|
|
7
7
|
}
|
|
@@ -3,14 +3,14 @@ import { CommunicatorTargetEnum_isCorrect } from '../enums/CommunicatorTargetEnu
|
|
|
3
3
|
export class CommunicatorSender {
|
|
4
4
|
constructor(props) {
|
|
5
5
|
this.otherWindow = props.otherWindow;
|
|
6
|
-
this.
|
|
6
|
+
this.receiverOrigin = modifyUrl(props.receiverOrigin);
|
|
7
7
|
}
|
|
8
8
|
sendMessage(message) {
|
|
9
|
-
if (!this.
|
|
9
|
+
if (!this.receiverOrigin ||
|
|
10
10
|
!CommunicatorTargetEnum_isCorrect(message.target)) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
const jsonMessage = JSON.stringify(message);
|
|
14
|
-
this.otherWindow.postMessage(jsonMessage, this.
|
|
14
|
+
this.otherWindow.postMessage(jsonMessage, this.receiverOrigin);
|
|
15
15
|
}
|
|
16
16
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { CommunicatorActionEnum } from "../enums/CommunicatorActionEnum";
|
|
2
2
|
import { CommunicatorTargetEnum } from "../enums/CommunicatorTargetEnum";
|
|
3
3
|
export declare type TSenderProps = {
|
|
4
|
-
|
|
4
|
+
receiverOrigin: string;
|
|
5
5
|
otherWindow: Window;
|
|
6
6
|
};
|
|
7
7
|
export declare type TReceiverProps = {
|
|
8
8
|
callback: TReceiverCallback;
|
|
9
|
+
senderOrigin: string;
|
|
9
10
|
};
|
|
10
11
|
export declare type TReceiverCallback = (message: TCommunicatorMessage) => void;
|
|
11
12
|
export declare type TCommunicatorActionResizeParams = {
|
package/package.json
CHANGED
|
@@ -2,9 +2,11 @@ import {TCommunicatorMessage, TReceiverCallback, TReceiverProps} from '../types'
|
|
|
2
2
|
|
|
3
3
|
export class CommunicatorReceiver {
|
|
4
4
|
private readonly callback: TReceiverCallback;
|
|
5
|
+
private readonly senderOrigin: string;
|
|
5
6
|
|
|
6
7
|
constructor(props: TReceiverProps) {
|
|
7
8
|
this.callback = props.callback;
|
|
9
|
+
this.senderOrigin = props.senderOrigin;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -32,7 +34,7 @@ export class CommunicatorReceiver {
|
|
|
32
34
|
return;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
if (
|
|
37
|
+
if (this.senderOrigin !== event.origin) {
|
|
36
38
|
return;
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -4,11 +4,11 @@ import {CommunicatorTargetEnum_isCorrect} from '../enums/CommunicatorTargetEnum'
|
|
|
4
4
|
|
|
5
5
|
export class CommunicatorSender {
|
|
6
6
|
private readonly otherWindow: Window;
|
|
7
|
-
private readonly
|
|
7
|
+
private readonly receiverOrigin: string;
|
|
8
8
|
|
|
9
9
|
constructor(props: TSenderProps) {
|
|
10
10
|
this.otherWindow = props.otherWindow;
|
|
11
|
-
this.
|
|
11
|
+
this.receiverOrigin = modifyUrl(props.receiverOrigin);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -17,14 +17,14 @@ export class CommunicatorSender {
|
|
|
17
17
|
*/
|
|
18
18
|
public sendMessage(message: TCommunicatorMessage) {
|
|
19
19
|
if (
|
|
20
|
-
!this.
|
|
20
|
+
!this.receiverOrigin ||
|
|
21
21
|
!CommunicatorTargetEnum_isCorrect(message.target)
|
|
22
22
|
) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
const jsonMessage = JSON.stringify(message);
|
|
27
|
-
this.otherWindow.postMessage(jsonMessage, this.
|
|
27
|
+
this.otherWindow.postMessage(jsonMessage, this.receiverOrigin);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
package/src/types/index.ts
CHANGED
|
@@ -2,12 +2,13 @@ import {CommunicatorActionEnum} from "../enums/CommunicatorActionEnum";
|
|
|
2
2
|
import {CommunicatorTargetEnum} from "../enums/CommunicatorTargetEnum";
|
|
3
3
|
|
|
4
4
|
export type TSenderProps = {
|
|
5
|
-
|
|
5
|
+
receiverOrigin: string,
|
|
6
6
|
otherWindow: Window,
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export type TReceiverProps = {
|
|
10
10
|
callback: TReceiverCallback,
|
|
11
|
+
senderOrigin: string,
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export type TReceiverCallback = (message: TCommunicatorMessage) => void;
|