@wildix/xbees-connect 1.1.2-alpha.0 → 1.1.2-alpha.3

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-connect",
3
- "version": "1.1.1",
3
+ "version": "1.1.2-alpha.2",
4
4
  "description": "This library provides easy communication between x-bees and integrated web applications",
5
5
  "author": "dimitri.chernykh <dimitri.chernykh@wildix.com>",
6
6
  "homepage": "",
@@ -187,6 +187,7 @@ export class Client {
187
187
  }
188
188
  }
189
189
  off(callback) {
190
+ this.localStorageManager.removeOnStorage(callback);
190
191
  this.removeEventListener(null, callback);
191
192
  }
192
193
  onCallEnded(callback) {
@@ -247,4 +248,7 @@ export class Client {
247
248
  saveToStorage(key, value) {
248
249
  this.localStorageManager.save(key, value);
249
250
  }
251
+ onStorage(listener) {
252
+ this.localStorageManager.onStorage(listener);
253
+ }
250
254
  }
@@ -6,7 +6,7 @@ class LocalStorageManager {
6
6
  }
7
7
  return this.instance;
8
8
  }
9
- listeners = [];
9
+ listeners = new Set();
10
10
  integrationKey = '';
11
11
  getStorageKey(key) {
12
12
  return !this.integrationKey ? key : `${this.integrationKey}_${key}`;
@@ -59,7 +59,10 @@ class LocalStorageManager {
59
59
  return localStorage.getItem(this.getStorageKey(key));
60
60
  }
61
61
  onStorage(listener) {
62
- this.listeners.push(listener);
62
+ this.listeners.add(listener);
63
+ }
64
+ removeOnStorage(listener) {
65
+ this.listeners.delete(listener);
63
66
  }
64
67
  }
65
68
  export default LocalStorageManager;
@@ -1,4 +1,4 @@
1
- import { Callback, ConnectClient, Contact, ContactQuery, IPayloadAutoSuggestResult, IPayloadContactMatchResult, IPayloadViewPort, LookupAndMatchContactsResolver, Message, Reject, RemoveEventListener, ResponseMessage, SuggestContactsResolver } from '../types';
1
+ import { Callback, ConnectClient, Contact, ContactQuery, IPayloadAutoSuggestResult, IPayloadContactMatchResult, IPayloadViewPort, LookupAndMatchContactsResolver, Message, Reject, RemoveEventListener, ResponseMessage, StorageEventCallback, SuggestContactsResolver } from '../types';
2
2
  import { ClientEventType, EventType } from './enums';
3
3
  /**
4
4
  * Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
@@ -44,7 +44,7 @@ export declare class Client implements ConnectClient {
44
44
  sendContactMatch(payload: IPayloadContactMatchResult): Promise<Message<ClientEventType.CONTACT_LOOKUP_AND_MATCH>>;
45
45
  addEventListener<T extends EventType = EventType>(eventName: T, callback: Callback<T>): RemoveEventListener;
46
46
  removeEventListener<T extends EventType = EventType>(eventName: T | null, callback: Callback<T>): void;
47
- off(callback: Callback): void;
47
+ off(callback: Callback | StorageEventCallback): void;
48
48
  onCallEnded(callback: Callback<EventType.TERMINATE_CALL>): void;
49
49
  onCallStarted(callback: Callback<EventType.ADD_CALL>): void;
50
50
  onPbxTokenChange(callback: Callback<EventType.PBX_TOKEN>): void;
@@ -53,4 +53,5 @@ export declare class Client implements ConnectClient {
53
53
  onThemeChange(callback: Callback<EventType.USE_THEME>): void;
54
54
  getFromStorage(key: string): void;
55
55
  saveToStorage(key: string, value: any): void;
56
+ onStorage(listener: StorageEventCallback): void;
56
57
  }
@@ -1,3 +1,4 @@
1
+ import { StorageEventCallback } from '../../types';
1
2
  declare class LocalStorageManager {
2
3
  private static instance;
3
4
  static getInstance(): LocalStorageManager;
@@ -11,6 +12,7 @@ declare class LocalStorageManager {
11
12
  save(key: string, value: any): void;
12
13
  retrieve(key: string): any;
13
14
  get(key: string): any;
14
- onStorage(listener: (event: StorageEvent) => void): void;
15
+ onStorage(listener: StorageEventCallback): void;
16
+ removeOnStorage(listener: StorageEventCallback): void;
15
17
  }
16
18
  export default LocalStorageManager;
@@ -85,6 +85,7 @@ export type EventCallbackMap = {
85
85
  [EventType.USE_THEME]: (theme: EventPayloadMap[EventType.USE_THEME]) => void;
86
86
  [EventType.PBX_TOKEN]: (token: EventPayloadMap[EventType.PBX_TOKEN]) => void;
87
87
  };
88
+ export type StorageEventCallback = (event: StorageEvent) => void;
88
89
  export type Callback<T extends EventType = EventType> = T extends keyof EventCallbackMap ? EventCallbackMap[T] : DefaultCallback;
89
90
  export interface Listener<T extends EventType = EventType> {
90
91
  eventName: T;
@@ -189,12 +190,15 @@ export interface ConnectClient {
189
190
  onCallEnded: (callback: Callback<EventType.TERMINATE_CALL>) => void;
190
191
  /**
191
192
  * Removes particular callback from handling events */
192
- off: (callback: Callback) => void;
193
+ off: (callback: Callback | StorageEventCallback) => void;
193
194
  /**
194
195
  * saves data to localStorage */
195
196
  saveToStorage: (key: string, value: any) => void;
196
197
  /**
197
198
  * Retrieves data from localStorage */
198
199
  getFromStorage: (key: string) => void;
200
+ /**
201
+ * listens on localStorage */
202
+ onStorage: (listener: StorageEventCallback) => void;
199
203
  }
200
204
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildix/xbees-connect",
3
- "version": "1.1.2-alpha.0",
3
+ "version": "1.1.2-alpha.3",
4
4
  "description": "This library provides easy communication between x-bees and integrated web applications",
5
5
  "author": "dimitri.chernykh <dimitri.chernykh@wildix.com>",
6
6
  "homepage": "",
@@ -42,5 +42,5 @@
42
42
  "engines": {
43
43
  "node": ">=16"
44
44
  },
45
- "gitHead": "72065c36cfbb65edbadec8a73718af7324f62e14"
45
+ "gitHead": "7c880b978a6db592446cd5fba59f3b4bf1f94996"
46
46
  }