@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 CHANGED
@@ -32,7 +32,7 @@ import {
32
32
 
33
33
  ```javascript
34
34
  const communicator = new CommunicatorSender({
35
- targetOrigin: 'google.com',
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;
@@ -1,6 +1,7 @@
1
1
  import { TReceiverProps } from '../types';
2
2
  export declare class CommunicatorReceiver {
3
3
  private readonly callback;
4
+ private readonly senderOrigin;
4
5
  constructor(props: TReceiverProps);
5
6
  watch(): void;
6
7
  private onMessage;
@@ -12,7 +12,7 @@ export class CommunicatorReceiver {
12
12
  console.log('PostMessage read error');
13
13
  return;
14
14
  }
15
- if (window.origin !== event.origin) {
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 targetOrigin;
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.targetOrigin = modifyUrl(props.targetOrigin);
6
+ this.receiverOrigin = modifyUrl(props.receiverOrigin);
7
7
  }
8
8
  sendMessage(message) {
9
- if (!this.targetOrigin ||
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.targetOrigin);
14
+ this.otherWindow.postMessage(jsonMessage, this.receiverOrigin);
15
15
  }
16
16
  }
@@ -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
- targetOrigin: string;
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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.6",
2
+ "version": "0.0.7",
3
3
  "name": "@maxzima/wa-communicator",
4
4
  "description": "",
5
5
  "author": "Noname",
@@ -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 (window.origin !== event.origin) {
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 targetOrigin: string;
7
+ private readonly receiverOrigin: string;
8
8
 
9
9
  constructor(props: TSenderProps) {
10
10
  this.otherWindow = props.otherWindow;
11
- this.targetOrigin = modifyUrl(props.targetOrigin);
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.targetOrigin ||
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.targetOrigin);
27
+ this.otherWindow.postMessage(jsonMessage, this.receiverOrigin);
28
28
  }
29
29
  }
30
30
 
@@ -2,12 +2,13 @@ import {CommunicatorActionEnum} from "../enums/CommunicatorActionEnum";
2
2
  import {CommunicatorTargetEnum} from "../enums/CommunicatorTargetEnum";
3
3
 
4
4
  export type TSenderProps = {
5
- targetOrigin: string,
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;