@wildix/xbees-connect 1.0.4-alpha.1 → 1.0.4-alpha.10
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 +5 -0
- package/dist-es/index.js +0 -4
- package/dist-es/package.json +16 -8
- package/dist-es/src/Client.js +54 -37
- package/dist-es/src/{PostMessageControllerNative.js → helpers/PostMessageControllerNative.js} +13 -12
- package/dist-es/src/{PostMessageControllerWeb.js → helpers/PostMessageControllerWeb.js} +8 -7
- package/dist-types/src/Client.d.ts +4 -7
- package/dist-types/src/helpers/PostMessageControllerNative.d.ts +8 -0
- package/dist-types/src/helpers/PostMessageControllerWeb.d.ts +8 -0
- package/dist-types/src/types.d.ts +53 -36
- package/package.json +13 -2
- package/dist-types/src/PostMessageControllerNative.d.ts +0 -8
- package/dist-types/src/PostMessageControllerWeb.d.ts +0 -8
package/README.md
CHANGED
|
@@ -7,14 +7,19 @@ This package is the Community plan edition of the client for UI integration appl
|
|
|
7
7
|
Install the package in your project directory with:
|
|
8
8
|
|
|
9
9
|
yarn
|
|
10
|
+
|
|
10
11
|
```bash
|
|
11
12
|
yarn add @wildix/xbees-connect
|
|
12
13
|
```
|
|
14
|
+
|
|
13
15
|
npm
|
|
16
|
+
|
|
14
17
|
```bash
|
|
15
18
|
npm install @wildix/xbees-connect
|
|
16
19
|
```
|
|
20
|
+
|
|
17
21
|
## Usage
|
|
22
|
+
|
|
18
23
|
```
|
|
19
24
|
import Client from "@wildix/xbees-connect";
|
|
20
25
|
|
package/dist-es/index.js
CHANGED
package/dist-es/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "xbees-connect",
|
|
3
|
-
"version": "1.0.
|
|
2
|
+
"name": "@wildix/xbees-connect",
|
|
3
|
+
"version": "1.0.4-alpha.1",
|
|
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": "",
|
|
7
|
-
"
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"license": "MIT",
|
|
8
9
|
"main": "./dist-cjs/index.js",
|
|
9
10
|
"types": "./dist-types/index.d.ts",
|
|
10
11
|
"module": "./dist-es/index.js",
|
|
@@ -13,6 +14,8 @@
|
|
|
13
14
|
"build:es": "tsc -p tsconfig.es.json",
|
|
14
15
|
"build:types": "tsc -p tsconfig.types.json",
|
|
15
16
|
"build:docs": "typedoc",
|
|
17
|
+
"lint": "eslint .",
|
|
18
|
+
"lint:fix": "eslint . --fix",
|
|
16
19
|
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo"
|
|
17
20
|
},
|
|
18
21
|
"files": [
|
|
@@ -22,13 +25,18 @@
|
|
|
22
25
|
"type": "git",
|
|
23
26
|
"url": "git@git.wildix.com:dimitri.chernykh/sdk-ui.git"
|
|
24
27
|
},
|
|
25
|
-
"
|
|
26
|
-
"
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
27
30
|
},
|
|
28
|
-
"
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"eslint": "^8.53.0",
|
|
33
|
+
"rimraf": "^5.0.5",
|
|
29
34
|
"typescript": "^5.2.2"
|
|
30
35
|
},
|
|
31
|
-
"
|
|
32
|
-
"
|
|
36
|
+
"parserOptions": {
|
|
37
|
+
"project": ["./tsconfig.json"]
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=16"
|
|
33
41
|
}
|
|
34
42
|
}
|
package/dist-es/src/Client.js
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
import { ClientEventType, EventType, } from './types';
|
|
2
|
-
import PostMessageControllerNative from './PostMessageControllerNative';
|
|
3
|
-
import PostMessageControllerWeb from './PostMessageControllerWeb';
|
|
4
1
|
import packageJson from '../package.json';
|
|
2
|
+
import PostMessageControllerNative from './helpers/PostMessageControllerNative';
|
|
3
|
+
import PostMessageControllerWeb from './helpers/PostMessageControllerWeb';
|
|
4
|
+
import { ClientEventType, EventType, } from './types';
|
|
5
5
|
/**
|
|
6
6
|
* Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
|
|
7
7
|
* integration creates na instance with new Client()
|
|
8
8
|
* */
|
|
9
9
|
export class Client {
|
|
10
|
+
static instance = null;
|
|
10
11
|
static getInstance() {
|
|
11
12
|
if (!this.instance) {
|
|
12
13
|
this.instance = new Client();
|
|
13
14
|
}
|
|
14
15
|
return this.instance;
|
|
15
16
|
}
|
|
17
|
+
worker;
|
|
18
|
+
listeners = [];
|
|
19
|
+
useSubscription = false;
|
|
20
|
+
iframeId;
|
|
21
|
+
variant = null;
|
|
16
22
|
constructor() {
|
|
17
|
-
this.listeners = [];
|
|
18
|
-
this.useSubscription = false;
|
|
19
|
-
this.iframeId = null;
|
|
20
|
-
this.variant = null;
|
|
21
23
|
const params = new URLSearchParams(window.location.search);
|
|
22
|
-
this.iframeId = params.get('iframeId');
|
|
24
|
+
this.iframeId = params.get('iframeId') ?? undefined;
|
|
23
25
|
this.variant = params.get('variant');
|
|
24
26
|
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
25
|
-
this.worker = window.ReactNativeWebView
|
|
27
|
+
this.worker = window.ReactNativeWebView
|
|
28
|
+
? new PostMessageControllerNative()
|
|
29
|
+
: new PostMessageControllerWeb();
|
|
26
30
|
}
|
|
27
|
-
|
|
31
|
+
sendAsync(data) {
|
|
28
32
|
return this.worker.sendAsync({
|
|
29
33
|
...data,
|
|
30
34
|
iframeId: this.iframeId,
|
|
@@ -38,7 +42,8 @@ export class Client {
|
|
|
38
42
|
}
|
|
39
43
|
return data;
|
|
40
44
|
}
|
|
41
|
-
catch (
|
|
45
|
+
catch (error) {
|
|
46
|
+
console.error('parse message error', error);
|
|
42
47
|
return null;
|
|
43
48
|
}
|
|
44
49
|
}
|
|
@@ -51,19 +56,22 @@ export class Client {
|
|
|
51
56
|
this.listeners.forEach(({ eventName, callback }) => {
|
|
52
57
|
if (eventName === type) {
|
|
53
58
|
if (type === EventType.ADD_CALL) {
|
|
54
|
-
const
|
|
55
|
-
|
|
59
|
+
const callbackFn = callback;
|
|
60
|
+
callbackFn(payload);
|
|
56
61
|
}
|
|
57
62
|
else {
|
|
58
63
|
// @ts-expect-error TODO: check the type for Callback<?>
|
|
59
|
-
const
|
|
60
|
-
|
|
64
|
+
const callbackFn = callback;
|
|
65
|
+
callbackFn(payload);
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
});
|
|
64
69
|
}
|
|
65
|
-
|
|
66
|
-
return this.sendAsync({
|
|
70
|
+
ready() {
|
|
71
|
+
return this.sendAsync({
|
|
72
|
+
type: ClientEventType.READY,
|
|
73
|
+
payload: { version: this.version() },
|
|
74
|
+
});
|
|
67
75
|
}
|
|
68
76
|
version() {
|
|
69
77
|
return packageJson.version;
|
|
@@ -74,40 +82,43 @@ export class Client {
|
|
|
74
82
|
showsUi() {
|
|
75
83
|
return !this.isDaemon();
|
|
76
84
|
}
|
|
77
|
-
|
|
85
|
+
getContext() {
|
|
78
86
|
return this.sendAsync({ type: ClientEventType.CONTEXT });
|
|
79
87
|
}
|
|
80
|
-
|
|
88
|
+
getCurrentContact() {
|
|
81
89
|
return this.sendAsync({ type: ClientEventType.CURRENT_CONTACT });
|
|
82
90
|
}
|
|
83
|
-
|
|
91
|
+
getThemeMode() {
|
|
84
92
|
return this.sendAsync({ type: ClientEventType.THEME_MODE });
|
|
85
93
|
}
|
|
86
|
-
|
|
94
|
+
getTheme() {
|
|
87
95
|
return this.sendAsync({ type: ClientEventType.THEME });
|
|
88
96
|
}
|
|
89
|
-
|
|
90
|
-
return this.sendAsync({
|
|
97
|
+
startCall(phoneNumber) {
|
|
98
|
+
return this.sendAsync({
|
|
99
|
+
type: ClientEventType.START_CALL,
|
|
100
|
+
payload: { phoneNumber },
|
|
101
|
+
});
|
|
91
102
|
}
|
|
92
|
-
|
|
103
|
+
reboot() {
|
|
93
104
|
return this.sendAsync({ type: ClientEventType.REBOOT });
|
|
94
105
|
}
|
|
95
|
-
|
|
106
|
+
setViewport(payload) {
|
|
96
107
|
return this.sendAsync({ type: ClientEventType.VIEW_PORT, payload });
|
|
97
108
|
}
|
|
98
|
-
|
|
109
|
+
toClipboard(payload) {
|
|
99
110
|
return this.sendAsync({ type: ClientEventType.TO_CLIPBOARD, payload });
|
|
100
111
|
}
|
|
101
|
-
|
|
112
|
+
isNotAuthorized(payload) {
|
|
102
113
|
return this.sendAsync({ type: ClientEventType.NOT_AUTHORIZED, payload });
|
|
103
114
|
}
|
|
104
|
-
|
|
115
|
+
isAuthorized(payload) {
|
|
105
116
|
return this.sendAsync({ type: ClientEventType.AUTHORIZED, payload });
|
|
106
117
|
}
|
|
107
|
-
|
|
118
|
+
getContactsAutoSuggest(payload) {
|
|
108
119
|
return this.sendAsync({
|
|
109
120
|
type: ClientEventType.CONTACTS_AUTO_SUGGEST,
|
|
110
|
-
payload
|
|
121
|
+
payload,
|
|
111
122
|
});
|
|
112
123
|
}
|
|
113
124
|
addEventListener(eventName, callback) {
|
|
@@ -115,14 +126,21 @@ export class Client {
|
|
|
115
126
|
this.useSubscription = true;
|
|
116
127
|
window.addEventListener('message', this.onMessage.bind(this));
|
|
117
128
|
}
|
|
118
|
-
const foundThisEvent = this.listeners.find(({ eventName: _eventName, callback: _callback }) =>
|
|
129
|
+
const foundThisEvent = this.listeners.find(({ eventName: _eventName, callback: _callback }) => {
|
|
130
|
+
return eventName === _eventName && Object.is(callback, _callback);
|
|
131
|
+
});
|
|
119
132
|
if (!foundThisEvent) {
|
|
120
133
|
this.listeners.push({ eventName, callback });
|
|
121
134
|
}
|
|
122
|
-
return () => {
|
|
135
|
+
return () => {
|
|
136
|
+
this.removeEventListener(eventName, callback);
|
|
137
|
+
};
|
|
123
138
|
}
|
|
124
139
|
removeEventListener(eventName, callback) {
|
|
125
|
-
this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) =>
|
|
140
|
+
this.listeners = this.listeners.filter(({ eventName: _eventName, callback: _callback }) => {
|
|
141
|
+
return !(Object.is(callback, _callback) &&
|
|
142
|
+
(!eventName ? true : eventName === _eventName));
|
|
143
|
+
});
|
|
126
144
|
if (this.useSubscription && !this.listeners.length) {
|
|
127
145
|
this.useSubscription = false;
|
|
128
146
|
window.removeEventListener('message', this.onMessage.bind(this));
|
|
@@ -147,7 +165,7 @@ export class Client {
|
|
|
147
165
|
type: ClientEventType.CONTACTS_AUTO_SUGGEST,
|
|
148
166
|
payload: {
|
|
149
167
|
contacts,
|
|
150
|
-
query
|
|
168
|
+
query,
|
|
151
169
|
},
|
|
152
170
|
});
|
|
153
171
|
};
|
|
@@ -157,8 +175,8 @@ export class Client {
|
|
|
157
175
|
try {
|
|
158
176
|
callback(query, resolve, reject);
|
|
159
177
|
}
|
|
160
|
-
catch (
|
|
161
|
-
reject(
|
|
178
|
+
catch (error) {
|
|
179
|
+
reject(`${error}`);
|
|
162
180
|
}
|
|
163
181
|
});
|
|
164
182
|
}
|
|
@@ -166,4 +184,3 @@ export class Client {
|
|
|
166
184
|
this.addEventListener(EventType.USE_THEME, callback);
|
|
167
185
|
}
|
|
168
186
|
}
|
|
169
|
-
Client.instance = null;
|
package/dist-es/src/{PostMessageControllerNative.js → helpers/PostMessageControllerNative.js}
RENAMED
|
@@ -1,43 +1,44 @@
|
|
|
1
1
|
export default class PostMessageControllerNative {
|
|
2
|
+
target;
|
|
3
|
+
timeout = 10000;
|
|
2
4
|
constructor() {
|
|
3
|
-
this.timeout = 10000;
|
|
4
5
|
// @ts-expect-error window.ReactNativeWebView will be provided by ReactNative WebView
|
|
5
6
|
this.target = window.ReactNativeWebView;
|
|
6
7
|
}
|
|
7
|
-
|
|
8
|
+
sendAsync(data) {
|
|
8
9
|
if (!this.target) {
|
|
9
|
-
return Promise.reject('
|
|
10
|
+
return Promise.reject('your application should be wrapped within iframe to xbees-connect perform the connection');
|
|
10
11
|
}
|
|
11
12
|
return this.send(this.target, data);
|
|
12
13
|
}
|
|
13
|
-
send(target,
|
|
14
|
-
return new Promise((
|
|
14
|
+
send(target, message) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
15
16
|
const channel = new MessageChannel();
|
|
16
17
|
const listener = (event) => {
|
|
17
18
|
try {
|
|
18
19
|
const parsedData = JSON.parse(event.data);
|
|
19
|
-
if (parsedData?.type ===
|
|
20
|
+
if (parsedData?.type === message.type) {
|
|
20
21
|
clearTimeout(timeout);
|
|
21
22
|
window.removeEventListener('message', listener);
|
|
22
23
|
if (!parsedData.errorMessage) {
|
|
23
|
-
|
|
24
|
+
resolve(parsedData);
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
|
-
|
|
27
|
+
reject(parsedData);
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
|
-
catch (
|
|
31
|
-
console.error(
|
|
31
|
+
catch (error) {
|
|
32
|
+
console.error('on receive response Error', error);
|
|
32
33
|
}
|
|
33
34
|
};
|
|
34
35
|
window.addEventListener('message', listener);
|
|
35
36
|
const timeout = setTimeout(() => {
|
|
36
37
|
channel.port1.close();
|
|
37
38
|
window.removeEventListener('message', listener);
|
|
38
|
-
|
|
39
|
+
reject({ errorMessage: 'timeout', type: message.type });
|
|
39
40
|
}, this.timeout);
|
|
40
|
-
target.postMessage(JSON.stringify(
|
|
41
|
+
target.postMessage(JSON.stringify(message));
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
}
|
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
export default class PostMessageControllerWeb {
|
|
2
|
+
target;
|
|
3
|
+
timeout = 10000;
|
|
2
4
|
constructor() {
|
|
3
|
-
this.timeout = 10000;
|
|
4
5
|
this.target = parent;
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
+
sendAsync(data) {
|
|
7
8
|
if (!this.target || this.target === window) {
|
|
8
|
-
return Promise.reject('
|
|
9
|
+
return Promise.reject('your application should be wrapped within iframe to xbees-connect perform the connection');
|
|
9
10
|
}
|
|
10
11
|
return this.send(this.target, data);
|
|
11
12
|
}
|
|
12
13
|
send(target, payload) {
|
|
13
|
-
return new Promise((
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
14
15
|
const channel = new MessageChannel();
|
|
15
16
|
const timeout = setTimeout(() => {
|
|
16
17
|
channel.port1.close();
|
|
17
|
-
|
|
18
|
+
reject({ errorMessage: 'timeout', type: payload.type });
|
|
18
19
|
}, this.timeout);
|
|
19
20
|
channel.port1.onmessage = ({ data }) => {
|
|
20
21
|
clearTimeout(timeout);
|
|
21
22
|
channel.port1.close();
|
|
22
23
|
if (!data.errorMessage) {
|
|
23
|
-
|
|
24
|
+
resolve(data);
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
|
-
|
|
27
|
+
reject(data);
|
|
27
28
|
}
|
|
28
29
|
};
|
|
29
30
|
target.postMessage(payload, '*', [channel.port2]);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { AutoSuggestResult, Callback, ConnectClient, EventType, Reject, RemoveEventListener, Resolve, Response } from './types';
|
|
1
|
+
import { AutoSuggestResult, Callback, ConnectClient, EventType, Reject, RemoveEventListener, Resolve, Response, ViewPortSize } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Client provides functionality of communication between xBees and integrated web applications via iFrame or ReactNative WebView
|
|
4
4
|
* integration creates na instance with new Client()
|
|
5
5
|
* */
|
|
6
6
|
export declare class Client implements ConnectClient {
|
|
7
7
|
private static instance;
|
|
8
|
-
static getInstance():
|
|
8
|
+
static getInstance(): ConnectClient;
|
|
9
9
|
private worker;
|
|
10
10
|
private listeners;
|
|
11
11
|
private useSubscription;
|
|
12
|
-
private readonly iframeId
|
|
12
|
+
private readonly iframeId?;
|
|
13
13
|
private readonly variant;
|
|
14
14
|
constructor();
|
|
15
15
|
private sendAsync;
|
|
@@ -25,10 +25,7 @@ export declare class Client implements ConnectClient {
|
|
|
25
25
|
getTheme(): Promise<Response>;
|
|
26
26
|
startCall(phoneNumber: string): Promise<Response>;
|
|
27
27
|
reboot(): Promise<Response>;
|
|
28
|
-
setViewport(payload:
|
|
29
|
-
height: number;
|
|
30
|
-
width: number;
|
|
31
|
-
}): Promise<Response>;
|
|
28
|
+
setViewport(payload: ViewPortSize): Promise<Response>;
|
|
32
29
|
toClipboard(payload: string): Promise<Response>;
|
|
33
30
|
isNotAuthorized(payload: string): Promise<Response>;
|
|
34
31
|
isAuthorized(payload: string): Promise<Response>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MessageResponse, PostMessageController, Response } from '../types';
|
|
2
|
+
export default class PostMessageControllerNative implements PostMessageController {
|
|
3
|
+
private readonly target;
|
|
4
|
+
private timeout;
|
|
5
|
+
constructor();
|
|
6
|
+
sendAsync(data: MessageResponse): Promise<Response>;
|
|
7
|
+
private send;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MessageResponse, PostMessageController, Response } from '../types';
|
|
2
|
+
export default class PostMessageControllerWeb implements PostMessageController {
|
|
3
|
+
private readonly target;
|
|
4
|
+
private timeout;
|
|
5
|
+
constructor();
|
|
6
|
+
sendAsync(data: MessageResponse): Promise<Response>;
|
|
7
|
+
private send;
|
|
8
|
+
}
|
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
export declare enum EventType {
|
|
2
|
+
GET_CONTACTS_AUTO_SUGGEST = "xBeesGetContactsAutoSuggest",
|
|
3
|
+
ADD_CALL = "xBeesAddCall",
|
|
4
|
+
TERMINATE_CALL = "xBeesTerminateCall",
|
|
5
|
+
USE_THEME = "xBeesUseTheme",
|
|
6
|
+
PBX_TOKEN = "xBeesPbxToken"
|
|
7
|
+
}
|
|
8
|
+
export declare enum ClientEventType {
|
|
9
|
+
READY = "xBeesReady",
|
|
10
|
+
CONTEXT = "xBeesContext",
|
|
11
|
+
CURRENT_CONTACT = "xBeesCurrentContact",
|
|
12
|
+
THEME_MODE = "xBeesThemeMode",
|
|
13
|
+
THEME = "xBeesTheme",
|
|
14
|
+
START_CALL = "xBeesStartCall",
|
|
15
|
+
VIEW_PORT = "xBeesViewPort",
|
|
16
|
+
REBOOT = "xBeesReboot",
|
|
17
|
+
TO_CLIPBOARD = "xBeesToClipboard",
|
|
18
|
+
NOT_AUTHORIZED = "xBeesNotAuthorized",
|
|
19
|
+
AUTHORIZED = "xBeesAuthorized",
|
|
20
|
+
CONTACTS_AUTO_SUGGEST = "xBeesContactsAutoSuggest"
|
|
21
|
+
}
|
|
22
|
+
export type MessageType = ClientEventType | EventType;
|
|
1
23
|
interface ContactShape {
|
|
2
24
|
id: string;
|
|
3
25
|
name: string;
|
|
@@ -11,45 +33,41 @@ interface ContactShape {
|
|
|
11
33
|
extension?: string;
|
|
12
34
|
organization?: string;
|
|
13
35
|
}
|
|
14
|
-
export type Contact = ContactShape & {
|
|
36
|
+
export type Contact = (ContactShape & {
|
|
15
37
|
email: string;
|
|
16
|
-
} | ContactShape & {
|
|
38
|
+
}) | (ContactShape & {
|
|
17
39
|
phone: string;
|
|
40
|
+
});
|
|
41
|
+
export type ViewPortSize = {
|
|
42
|
+
height: number;
|
|
43
|
+
width: number;
|
|
18
44
|
};
|
|
19
|
-
|
|
45
|
+
type EventPayload<T extends MessageType> = T extends EventType.GET_CONTACTS_AUTO_SUGGEST ? string : T extends ClientEventType.CONTACTS_AUTO_SUGGEST ? AutoSuggestResult : T extends EventType.ADD_CALL ? CallStartInfo : T extends ClientEventType.START_CALL ? StartCallPayload : T extends ClientEventType.READY ? {
|
|
46
|
+
version: string;
|
|
47
|
+
} : T extends ClientEventType.VIEW_PORT ? ViewPortSize : T extends EventType.USE_THEME ? string : T extends EventType.PBX_TOKEN ? string : never;
|
|
48
|
+
export type Message<T extends MessageType = MessageType> = {
|
|
20
49
|
type: T;
|
|
21
|
-
payload
|
|
50
|
+
payload?: EventPayload<T>;
|
|
22
51
|
};
|
|
23
|
-
export type
|
|
52
|
+
export type MessageResponse<T extends MessageType = MessageType> = Message<T> & {
|
|
53
|
+
iframeId?: string;
|
|
54
|
+
};
|
|
55
|
+
export type Payload = string | Record<string, string> | ThemeChangePayload;
|
|
56
|
+
export type Response<T extends Payload = Payload> = {
|
|
24
57
|
type?: string;
|
|
25
58
|
message?: string;
|
|
26
59
|
errorMessage?: string;
|
|
60
|
+
payload?: T;
|
|
61
|
+
};
|
|
62
|
+
export type RawMessage = {
|
|
63
|
+
data?: string;
|
|
64
|
+
};
|
|
65
|
+
export type SendPayload = {
|
|
66
|
+
type: ClientEventType;
|
|
27
67
|
payload?: any;
|
|
28
68
|
};
|
|
29
|
-
export declare enum EventType {
|
|
30
|
-
GET_CONTACTS_AUTO_SUGGEST = "xBeesGetContactsAutoSuggest",
|
|
31
|
-
ADD_CALL = "xBeesAddCall",
|
|
32
|
-
TERMINATE_CALL = "xBeesTerminateCall",
|
|
33
|
-
USE_THEME = "xBeesUseTheme",
|
|
34
|
-
PBX_TOKEN = "xBeesPbxToken"
|
|
35
|
-
}
|
|
36
|
-
export declare enum ClientEventType {
|
|
37
|
-
READY = "xBeesReady",
|
|
38
|
-
CONTEXT = "xBeesContext",
|
|
39
|
-
CURRENT_CONTACT = "xBeesCurrentContact",
|
|
40
|
-
THEME_MODE = "xBeesThemeMode",
|
|
41
|
-
THEME = "xBeesTheme",
|
|
42
|
-
START_CALL = "xBeesStartCall",
|
|
43
|
-
VIEW_PORT = "xBeesViewPort",
|
|
44
|
-
REBOOT = "xBeesReboot",
|
|
45
|
-
TO_CLIPBOARD = "xBeesToClipboard",
|
|
46
|
-
NOT_AUTHORIZED = "xBeesNotAuthorized",
|
|
47
|
-
AUTHORIZED = "xBeesAuthorized",
|
|
48
|
-
CONTACTS_AUTO_SUGGEST = "xBeesContactsAutoSuggest"
|
|
49
|
-
}
|
|
50
|
-
export type MessageType = ClientEventType | EventType;
|
|
51
69
|
export type ThemeChangePayload = {
|
|
52
|
-
mode:
|
|
70
|
+
mode: 'light' | 'dark';
|
|
53
71
|
themeOptions?: {
|
|
54
72
|
typography?: unknown;
|
|
55
73
|
palette?: unknown;
|
|
@@ -61,7 +79,9 @@ type CallStartInfo = {
|
|
|
61
79
|
destination: string;
|
|
62
80
|
video: boolean;
|
|
63
81
|
};
|
|
64
|
-
type
|
|
82
|
+
type StartCallPayload = {
|
|
83
|
+
phoneNumber: string;
|
|
84
|
+
};
|
|
65
85
|
export type EventPayloadMap = {
|
|
66
86
|
[EventType.GET_CONTACTS_AUTO_SUGGEST]: string;
|
|
67
87
|
[EventType.ADD_CALL]: CallStartInfo;
|
|
@@ -88,6 +108,7 @@ export type ClientEventCallbackMap = {
|
|
|
88
108
|
export interface ReactNativeWebView {
|
|
89
109
|
postMessage: (payload: unknown, origin?: string, d?: unknown[]) => void;
|
|
90
110
|
}
|
|
111
|
+
export type Callback<T extends EventType = EventType> = T extends keyof EventCallbackMap ? EventCallbackMap[T] : DefaultCallback;
|
|
91
112
|
export interface Listener<T extends EventType = EventType> {
|
|
92
113
|
eventName: T;
|
|
93
114
|
callback: Callback<T>;
|
|
@@ -97,12 +118,11 @@ export interface AutoSuggestResult {
|
|
|
97
118
|
contacts: Contact[];
|
|
98
119
|
query: string;
|
|
99
120
|
}
|
|
100
|
-
export interface
|
|
101
|
-
sendAsync(data:
|
|
121
|
+
export interface PostMessageController {
|
|
122
|
+
sendAsync(data: MessageResponse): Promise<Response>;
|
|
102
123
|
}
|
|
103
124
|
export type Resolve = (contacts: Contact[]) => void;
|
|
104
125
|
export type Reject = (reason: string) => void;
|
|
105
|
-
export type Callback<T extends EventType = EventType> = T extends keyof EventCallbackMap ? EventCallbackMap[T] : DefaultCallback;
|
|
106
126
|
export type RemoveEventListener = () => void;
|
|
107
127
|
export interface ConnectClient {
|
|
108
128
|
/**
|
|
@@ -138,10 +158,7 @@ export interface ConnectClient {
|
|
|
138
158
|
reboot: () => Promise<Response>;
|
|
139
159
|
/**
|
|
140
160
|
* Sends request to x-bees about current frame size change */
|
|
141
|
-
setViewport: (payload:
|
|
142
|
-
height: number;
|
|
143
|
-
width: number;
|
|
144
|
-
}) => Promise<Response>;
|
|
161
|
+
setViewport: (payload: ViewPortSize) => Promise<Response>;
|
|
145
162
|
/**
|
|
146
163
|
* Sends request to x-bees to put string to the users clipboard */
|
|
147
164
|
toClipboard: (payload: string) => Promise<Response>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildix/xbees-connect",
|
|
3
|
-
"version": "1.0.4-alpha.
|
|
3
|
+
"version": "1.0.4-alpha.10",
|
|
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": "",
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
"build:es": "tsc -p tsconfig.es.json",
|
|
15
15
|
"build:types": "tsc -p tsconfig.types.json",
|
|
16
16
|
"build:docs": "typedoc",
|
|
17
|
+
"lint": "eslint .",
|
|
18
|
+
"lint:fix": "eslint . --fix",
|
|
17
19
|
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo"
|
|
18
20
|
},
|
|
19
21
|
"files": [
|
|
@@ -27,8 +29,17 @@
|
|
|
27
29
|
"access": "public"
|
|
28
30
|
},
|
|
29
31
|
"devDependencies": {
|
|
32
|
+
"eslint": "^8.53.0",
|
|
30
33
|
"rimraf": "^5.0.5",
|
|
31
34
|
"typescript": "^5.2.2"
|
|
32
35
|
},
|
|
33
|
-
"
|
|
36
|
+
"parserOptions": {
|
|
37
|
+
"project": [
|
|
38
|
+
"./tsconfig.json"
|
|
39
|
+
]
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=16"
|
|
43
|
+
},
|
|
44
|
+
"gitHead": "2a4305e68084729846257fbee0d565c4beb0272c"
|
|
34
45
|
}
|