@monterosa/sdk-connect-kit 2.0.0-rc.1 → 2.0.0-rc.2
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/dist/connect.d.ts +20 -3
- package/dist/index.d.ts +5 -5
- package/dist/{index.esm.js → index.js} +26 -7
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +15 -10
- package/package.json +19 -17
- package/dist/index.cjs.js +0 -645
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js.map +0 -1
package/dist/connect.d.ts
CHANGED
|
@@ -17,7 +17,8 @@ declare const getConnectMemoized: (...args: any[]) => Promise<Connect>;
|
|
|
17
17
|
* host. If host is not provided, it returns Connect instance for
|
|
18
18
|
* the host associated with the default sdk.
|
|
19
19
|
*
|
|
20
|
-
* @param
|
|
20
|
+
* @param host - The host URL. If not provided, uses the host
|
|
21
|
+
* from the default SDK instance.
|
|
21
22
|
*/
|
|
22
23
|
declare function getConnect(host?: string): Promise<Connect>;
|
|
23
24
|
/**
|
|
@@ -33,7 +34,7 @@ declare function onConnected(conn: Connect, callback: (timestamp: number) => voi
|
|
|
33
34
|
*
|
|
34
35
|
* @param conn - The {@link Connect} instance
|
|
35
36
|
* @param callback - callback triggered on connecting state. Two parameters
|
|
36
|
-
* are provided: `attempt
|
|
37
|
+
* are provided: `attempt`, the sequential number of connect attempt, and
|
|
37
38
|
* `delay` - delay in seconds before the next attempt
|
|
38
39
|
*/
|
|
39
40
|
declare function onConnecting(conn: Connect, callback: (attempt: number, delay: number) => void): Unsubscribe;
|
|
@@ -59,7 +60,10 @@ declare function onDisconnected(conn: Connect, callback: () => void): Unsubscrib
|
|
|
59
60
|
*/
|
|
60
61
|
declare function onMessage(conn: Connect, callback: (message: Message) => void): Unsubscribe;
|
|
61
62
|
/**
|
|
62
|
-
* Starts a connection process.
|
|
63
|
+
* Starts a connection process.
|
|
64
|
+
*
|
|
65
|
+
* @remarks
|
|
66
|
+
* If connect is successful a promise resolved by
|
|
63
67
|
* and {@link onConnected} is triggered, otherwise a next attempt will be
|
|
64
68
|
* automatically invoked and {@link onConnecting} is triggered.
|
|
65
69
|
*
|
|
@@ -108,6 +112,7 @@ declare const subscribeMemoized: (...args: any[]) => Promise<void>;
|
|
|
108
112
|
/**
|
|
109
113
|
* Subscribe to the server channel.
|
|
110
114
|
*
|
|
115
|
+
* @remarks
|
|
111
116
|
* Any message published to a channel is {@link onMessage | received}
|
|
112
117
|
* only by subscribers to that channel. The sdk out of the box handles
|
|
113
118
|
* all required subscriptions internally and {@link onMessage | handles messages}
|
|
@@ -122,6 +127,7 @@ declare function subscribe(conn: Connect, channel: string): Promise<void>;
|
|
|
122
127
|
/**
|
|
123
128
|
* Unsubscribe from the server channel.
|
|
124
129
|
*
|
|
130
|
+
* @remarks
|
|
125
131
|
* Removes subscription to the channel so that recipient no longer receive
|
|
126
132
|
* messages from that channel.
|
|
127
133
|
*
|
|
@@ -132,6 +138,7 @@ declare function unsubscribe(conn: Connect, channel: string): void;
|
|
|
132
138
|
/**
|
|
133
139
|
* Send message to the server.
|
|
134
140
|
*
|
|
141
|
+
* @remarks
|
|
135
142
|
* The sdk out of the box provides more high level functions that uses
|
|
136
143
|
* this function to send data to the server. Though a developer still can
|
|
137
144
|
* use it if he knows a message protocol (klass and body) and a channel
|
|
@@ -144,6 +151,16 @@ declare function unsubscribe(conn: Connect, channel: string): void;
|
|
|
144
151
|
* @param body - Message payload
|
|
145
152
|
*/
|
|
146
153
|
declare function send(conn: Connect, channel: string, klass: Klass | string, body: (string | number)[]): void;
|
|
154
|
+
/**
|
|
155
|
+
* Authenticates the connection with user credentials.
|
|
156
|
+
*
|
|
157
|
+
* @param conn - The Connect instance
|
|
158
|
+
* @param userId - The user identifier
|
|
159
|
+
* @param timestamp - The signature timestamp in seconds
|
|
160
|
+
* @param signature - The session signature string
|
|
161
|
+
*
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
147
164
|
declare function login(conn: Connect, userId: string, timestamp: number, signature: string): Promise<void>;
|
|
148
165
|
declare function logout(conn: Connect): Promise<void>;
|
|
149
166
|
export { onConnected, onConnecting, onDisconnected, onMessage, disconnect, unsubscribe, send, getConnect, getConnectMemoized, connect, subscribe, subscribeMemoized, login, logout, };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Establishes real-time connections to events and projects.
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* @license
|
|
3
8
|
* @monterosa/sdk-connect-kit
|
|
@@ -6,11 +11,6 @@
|
|
|
6
11
|
*
|
|
7
12
|
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
8
13
|
*/
|
|
9
|
-
/**
|
|
10
|
-
* Monterosa SDK / Connect Kit
|
|
11
|
-
*
|
|
12
|
-
* @packageDocumentation
|
|
13
|
-
*/
|
|
14
14
|
export * from './connect';
|
|
15
15
|
export * from './connect_impl';
|
|
16
16
|
export * from './types';
|
|
@@ -24,8 +24,10 @@ var InitState;
|
|
|
24
24
|
InitState["Initialising"] = "initialising";
|
|
25
25
|
})(InitState || (InitState = {}));
|
|
26
26
|
/**
|
|
27
|
-
* A list of possible connection states.
|
|
28
|
-
*
|
|
27
|
+
* A list of possible connection states.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* Can be used with {@link Connect | Connect.state} to determine the current state.
|
|
29
31
|
*
|
|
30
32
|
* By default {@link Connect} is in the disconnected state.
|
|
31
33
|
* When {@link connect} invoked `Connect` state switches to
|
|
@@ -223,7 +225,7 @@ class ConnectImpl extends Emitter {
|
|
|
223
225
|
return this.connectPromise;
|
|
224
226
|
}
|
|
225
227
|
// This should never happen - indicates a bug in state management
|
|
226
|
-
return Promise.reject(new Error('BUG: Connection state is Connecting but connectPromise is null
|
|
228
|
+
return Promise.reject(new Error('BUG: Connection state is Connecting but connectPromise is null - ' +
|
|
227
229
|
'this indicates an internal inconsistency'));
|
|
228
230
|
}
|
|
229
231
|
this.connectPromise = new Promise((resolve, reject) => {
|
|
@@ -307,7 +309,8 @@ const getConnectMemoized = memoizePromise(async (host) => {
|
|
|
307
309
|
* host. If host is not provided, it returns Connect instance for
|
|
308
310
|
* the host associated with the default sdk.
|
|
309
311
|
*
|
|
310
|
-
* @param
|
|
312
|
+
* @param host - The host URL. If not provided, uses the host
|
|
313
|
+
* from the default SDK instance.
|
|
311
314
|
*/
|
|
312
315
|
function getConnect(host) {
|
|
313
316
|
if (host === undefined) {
|
|
@@ -331,7 +334,7 @@ function onConnected(conn, callback) {
|
|
|
331
334
|
*
|
|
332
335
|
* @param conn - The {@link Connect} instance
|
|
333
336
|
* @param callback - callback triggered on connecting state. Two parameters
|
|
334
|
-
* are provided: `attempt
|
|
337
|
+
* are provided: `attempt`, the sequential number of connect attempt, and
|
|
335
338
|
* `delay` - delay in seconds before the next attempt
|
|
336
339
|
*/
|
|
337
340
|
function onConnecting(conn, callback) {
|
|
@@ -367,7 +370,10 @@ function onMessage(conn, callback) {
|
|
|
367
370
|
return () => conn.off('message', handler);
|
|
368
371
|
}
|
|
369
372
|
/**
|
|
370
|
-
* Starts a connection process.
|
|
373
|
+
* Starts a connection process.
|
|
374
|
+
*
|
|
375
|
+
* @remarks
|
|
376
|
+
* If connect is successful a promise resolved by
|
|
371
377
|
* and {@link onConnected} is triggered, otherwise a next attempt will be
|
|
372
378
|
* automatically invoked and {@link onConnecting} is triggered.
|
|
373
379
|
*
|
|
@@ -422,6 +428,7 @@ const subscribeMemoized = memoizePromise(async (conn, channel) => conn.subscribe
|
|
|
422
428
|
/**
|
|
423
429
|
* Subscribe to the server channel.
|
|
424
430
|
*
|
|
431
|
+
* @remarks
|
|
425
432
|
* Any message published to a channel is {@link onMessage | received}
|
|
426
433
|
* only by subscribers to that channel. The sdk out of the box handles
|
|
427
434
|
* all required subscriptions internally and {@link onMessage | handles messages}
|
|
@@ -438,6 +445,7 @@ function subscribe(conn, channel) {
|
|
|
438
445
|
/**
|
|
439
446
|
* Unsubscribe from the server channel.
|
|
440
447
|
*
|
|
448
|
+
* @remarks
|
|
441
449
|
* Removes subscription to the channel so that recipient no longer receive
|
|
442
450
|
* messages from that channel.
|
|
443
451
|
*
|
|
@@ -450,6 +458,7 @@ function unsubscribe(conn, channel) {
|
|
|
450
458
|
/**
|
|
451
459
|
* Send message to the server.
|
|
452
460
|
*
|
|
461
|
+
* @remarks
|
|
453
462
|
* The sdk out of the box provides more high level functions that uses
|
|
454
463
|
* this function to send data to the server. Though a developer still can
|
|
455
464
|
* use it if he knows a message protocol (klass and body) and a channel
|
|
@@ -464,6 +473,16 @@ function unsubscribe(conn, channel) {
|
|
|
464
473
|
function send(conn, channel, klass, body) {
|
|
465
474
|
conn.send(channel, klass, body);
|
|
466
475
|
}
|
|
476
|
+
/**
|
|
477
|
+
* Authenticates the connection with user credentials.
|
|
478
|
+
*
|
|
479
|
+
* @param conn - The Connect instance
|
|
480
|
+
* @param userId - The user identifier
|
|
481
|
+
* @param timestamp - The signature timestamp in seconds
|
|
482
|
+
* @param signature - The session signature string
|
|
483
|
+
*
|
|
484
|
+
* @public
|
|
485
|
+
*/
|
|
467
486
|
async function login(conn, userId, timestamp, signature) {
|
|
468
487
|
const result = await conn.login(userId, timestamp, signature);
|
|
469
488
|
return result;
|
|
@@ -474,4 +493,4 @@ async function logout(conn) {
|
|
|
474
493
|
}
|
|
475
494
|
|
|
476
495
|
export { ConnState, ConnectImpl, InitState, KIT_NAME, Klass, connect, disconnect, getConnect, getConnectMemoized, login, logout, onConnected, onConnecting, onDisconnected, onMessage, send, subscribe, subscribeMemoized, unsubscribe };
|
|
477
|
-
//# sourceMappingURL=index.
|
|
496
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/types.ts","../src/helpers.ts","../src/connect_impl.ts","../src/connect.ts"],"sourcesContent":["/**\n * @license\n * @monterosa/sdk-connect-kit\n *\n * Copyright © 2022 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaKit } from '@monterosa/sdk-core';\nimport { Emitter } from '@monterosa/sdk-util';\n\n/**\n * @internal\n */\nexport const KIT_NAME = 'connect';\n\n/**\n * Represents a Connect Kit instance. Obtain one via {@link getConnect}.\n */\nexport interface Connect extends MonterosaKit, Emitter {\n /**\n * Connection state\n */\n state: ConnState;\n\n /**\n * Session ID\n */\n sessionId: string | null;\n\n /**\n * @internal\n */\n initState: InitState;\n\n /**\n * @internal\n */\n init(host: string): Promise<void>;\n\n /**\n * @internal\n */\n connect(): Promise<void>;\n\n /**\n * @internal\n */\n disconnect(): void;\n\n /**\n * @internal\n */\n subscribe(channel: string): Promise<void>;\n\n /**\n * @internal\n */\n unsubscribe(channel: string): void;\n\n /**\n * @internal\n */\n send(channel: string, klass: string, body: (string | number)[]): void;\n\n /**\n * @internal\n */\n login(userId: string, timestamp: number, signature: string): Promise<void>;\n\n logout(): void;\n}\n\n/**\n * @internal\n */\nexport enum InitState {\n NotInitialised = 'not_initialised',\n Initialised = 'initialised',\n Initialising = 'initialising',\n}\n\n/**\n * A list of possible connection states.\n *\n * @remarks\n * Can be used with {@link Connect | Connect.state} to determine the current state.\n *\n * By default {@link Connect} is in the disconnected state.\n * When {@link connect} invoked `Connect` state switches to\n * `ConnState.Connecting` and connection is maintained permanently until\n * {@link disconnect} method is invoked. If connection was unsucessful,\n * a new attempt will start after a short delay and `ConnState.connecting`\n * is triggered. Delays between attempts increased based on this sequence:\n * 0, 3, 5, 10, 20, 30, 45, 60 where 60 seconds is the max.\n *\n * If `Connect` was previously connected and for any reason connection is lost,\n * the state changed to `ConnState.Connecting` again and the connection process\n * starts again automatically.\n *\n * @example\n * ```javascript\n * if (conn.state === ConnState.Connecting) {\n * // display \"connecting\" message\n * }\n * ```\n */\nexport enum ConnState {\n /**\n * Disconnected state\n */\n Disconnected = 'disconnected',\n /**\n * Connecting state\n */\n Connecting = 'connecting',\n /**\n * Connected state\n */\n Connected = 'connected',\n}\n\n/**\n * Class of the {@link Message}\n */\nexport enum Klass {\n /**\n * Authentication request. Sent by server on client connection.\n */\n Authenticate = 'auth',\n /**\n * Authentication response. Sent by client as response\n * to authentication request.\n */\n AuthenticateResponse = 'authr',\n /**\n * Authentication acknowledgement. Sent by the server as confirmation\n * of successful authentication.\n */\n AuthenticateSuccess = 'authok',\n /**\n * Ping message is sent by server periodically as a keep-alive.\n * Ping message is only sent if no messages are sent for specific time\n * period, meaning if there are other messages sent frequently enough\n * then ping messages are not sent at all.\n */\n Ping = 'ping',\n /**\n * Subscribe to a channel. Sent by the client to subscribe to a channel\n */\n Subscribe = 'sub',\n /**\n * Unsubscribe from a channel. Sent by the client to unsubscribe from a channel\n */\n Unsububscribe = 'unsub',\n /**\n * End of cache. Sent by the server to notify that all messages are sent from\n * a channel cache\n */\n EndOfCache = 'eoc',\n /**\n * User login. Sent by client to supply verified user identity to the server.\n */\n Login = 'login',\n /**\n * User login success\n */\n LoginSuccess = 'login_ok',\n /**\n * User login failure\n */\n LoginFail = 'login_fail',\n /**\n * Averages counters. Client can submit a counter which is processed together\n * with other counters to determine the average of all counters within specific\n * demographics segment.\n */\n Counter = 'counter',\n /**\n * Client votes. Sents by a user to vote for a poll option\n */\n Vote = 'v',\n}\n\n/**\n * Represents a message received from or sent to the server.\n * Subscribe via {@link onMessage} to receive messages.\n */\nexport interface Message {\n /**\n * The channel on which this message was received. You must\n * {@link subscribe} to a channel to start receiving messages.\n */\n channel: string;\n /**\n * The class indicates the desired action to be performed or the result of\n * the action. E.g. in order to authenticate a developer should {@link send}\n * {@link Klass | Klass.AuthenticateResponse} klass message as a response on\n * a received {@link Klass | Klass.Authenticate} message\n */\n klass: Klass | string;\n /**\n * The timestamp (in seconds) when this message was sent\n */\n sent_at: number;\n /**\n * The message payload. Each piece of data is a `string`\n */\n body: string[];\n}\n","/**\n * @license\n * @monterosa/sdk-connect-kit\n *\n * Copyright © 2022 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Unsubscribe } from '@monterosa/sdk-util';\n\nimport { Connect, ConnState } from './types';\n\nexport function onState(\n conn: Connect,\n needle: ConnState,\n callback: Function,\n): Unsubscribe {\n const handler = (state: ConnState, ...rest: unknown[]) => {\n if (state === needle) {\n callback(...rest);\n }\n };\n\n conn.on('state', handler);\n\n return () => conn.off('state', handler);\n}\n","/* eslint class-methods-use-this: \"off\" */\n\n/**\n * @license\n * @monterosa/sdk-connect-kit\n *\n * Copyright © 2022 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport Enmasse from '@monterosa/sdk-enmasse-kit';\nimport { Emitter, setTimestamp } from '@monterosa/sdk-util';\n\nimport { Connect, ConnState, InitState, Message } from './types';\n\n/**\n * @internal\n */\nexport class ConnectImpl extends Emitter implements Connect {\n private static instance: ConnectImpl;\n public initState: InitState = InitState.NotInitialised;\n private initPromise: Promise<void> = Promise.resolve();\n private connectPromise: Promise<void> | null = null;\n\n private constructor() {\n super();\n\n Enmasse.bind(\n Enmasse.ON_STATE,\n (state: Enmasse.States, ...rest: unknown[]) => {\n if (state === Enmasse.STATE_CONNECTED) {\n const [timestamp] = rest as [number];\n\n setTimestamp(timestamp);\n }\n\n this.emit('state', ConnectImpl.toConnState(state), ...rest);\n },\n );\n\n Enmasse.bind(Enmasse.ON_MESSAGE, (message: Enmasse.Message) => {\n this.emit('message', <Message>message);\n });\n }\n\n get state() {\n return ConnectImpl.toConnState(Enmasse.getState());\n }\n\n get sessionId() {\n return Enmasse.getSessionId();\n }\n\n public static getInstance(): ConnectImpl {\n if (!ConnectImpl.instance) {\n ConnectImpl.instance = new ConnectImpl();\n }\n\n return ConnectImpl.instance;\n }\n\n static toConnState(state: Enmasse.States): ConnState {\n switch (state) {\n default:\n case Enmasse.STATE_DISCONNECTED:\n return ConnState.Disconnected;\n case Enmasse.STATE_CONNECTING:\n return ConnState.Connecting;\n case Enmasse.STATE_CONNECTED:\n return ConnState.Connected;\n }\n }\n\n async init(host: string): Promise<void> {\n if (\n this.initState === InitState.Initialising ||\n this.initState === InitState.Initialised\n ) {\n return this.initPromise;\n }\n\n this.initPromise = new Promise((resolve, reject) => {\n this.initState = InitState.Initialising;\n\n Enmasse.bind(Enmasse.ON_READY, () => {\n this.initState = InitState.Initialised;\n\n Enmasse.unbind(Enmasse.ON_READY);\n Enmasse.unbind(Enmasse.ON_ERROR);\n\n resolve();\n });\n\n Enmasse.bind(Enmasse.ON_ERROR, (err: string) => {\n this.initState = InitState.NotInitialised;\n\n Enmasse.unbind(Enmasse.ON_READY);\n Enmasse.unbind(Enmasse.ON_ERROR);\n\n reject(new Error(`Unable to initialise connect kit: ${err}`));\n });\n\n Enmasse.init({\n config: `https://${host}/config/enmasse.json`,\n });\n });\n\n return this.initPromise;\n }\n\n connect(): Promise<void> {\n if (this.initState !== InitState.Initialised) {\n return Promise.reject(new Error('must be initialised before connecting'));\n }\n\n if (this.state === ConnState.Connected) {\n return Promise.resolve();\n }\n\n if (this.state === ConnState.Connecting) {\n if (this.connectPromise) {\n return this.connectPromise;\n }\n\n // This should never happen - indicates a bug in state management\n return Promise.reject(\n new Error(\n 'BUG: Connection state is Connecting but connectPromise is null - ' +\n 'this indicates an internal inconsistency',\n ),\n );\n }\n\n this.connectPromise = new Promise((resolve, reject) => {\n const handler = (state: ConnState) => {\n switch (state) {\n case ConnState.Connected:\n Enmasse.unbind(Enmasse.ON_STATE, handler);\n\n this.connectPromise = null;\n\n resolve();\n break;\n case ConnState.Disconnected:\n Enmasse.unbind(Enmasse.ON_STATE, handler);\n\n this.connectPromise = null;\n\n reject(new Error('disconnected'));\n break;\n case ConnState.Connecting:\n // The Enmasse library may emit the \"connecting\" state multiple\n // times. This is expected and does not impact the connection\n // process, so we safely ignore it.\n break;\n }\n };\n\n Enmasse.bind(Enmasse.ON_STATE, handler);\n\n Enmasse.connect();\n });\n\n return this.connectPromise;\n }\n\n disconnect() {\n Enmasse.disconnect();\n }\n\n subscribe(channel: string): Promise<void> {\n return new Promise((resolve) => {\n const handler = (ch: string) => {\n if (ch !== channel) return;\n\n Enmasse.unbind(Enmasse.ON_EOC, handler);\n\n resolve();\n };\n\n Enmasse.bind(Enmasse.ON_EOC, handler);\n\n Enmasse.subscribe(channel);\n });\n }\n\n unsubscribe(channel: string): void {\n Enmasse.unsubscribe(channel);\n }\n\n send(channel: string, klass: string, body: (string | number)[]): void {\n Enmasse.send(channel, klass, body);\n }\n\n async login(\n userId: string,\n timestamp: number,\n signature: string,\n ): Promise<void> {\n return new Promise((resolve, reject) => {\n Enmasse.login(userId, timestamp, signature, resolve, () => {\n reject(new Error('Login failure'));\n });\n });\n }\n\n async logout(): Promise<void> {\n Enmasse.logout();\n\n return Promise.resolve();\n }\n\n delete() {}\n}\n","/**\n * @license\n * @monterosa/sdk-connect-kit\n *\n * Copyright © 2022-2024 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { getSdk } from '@monterosa/sdk-core';\nimport { memoizePromise, Unsubscribe } from '@monterosa/sdk-util';\n\nimport { Connect, ConnState, Message, Klass } from './types';\nimport { onState } from './helpers';\nimport { ConnectImpl } from './connect_impl';\n\n/**\n * @internal\n */\nconst getConnectMemoized = memoizePromise(\n async (host: string): Promise<Connect> => {\n const conn = ConnectImpl.getInstance();\n\n await conn.init(host);\n\n return conn;\n },\n (host: string): string => host,\n);\n\n/**\n * Returns the {@link Connect} instance associated with the provided\n * host. If host is not provided, it returns Connect instance for\n * the host associated with the default sdk.\n *\n * @param host - The host URL. If not provided, uses the host\n * from the default SDK instance.\n */\nfunction getConnect(host?: string): Promise<Connect> {\n if (host === undefined) {\n const sdk = getSdk();\n\n host = sdk.options.host;\n }\n\n return getConnectMemoized(host);\n}\n\n/**\n * Adds an observer for when connection state changed to connected.\n *\n * @param conn - The {@link Connect} instance\n * @param callback - The callback triggered when {@link ConnState | state}\n * changed to connected\n */\nfunction onConnected(\n conn: Connect,\n callback: (timestamp: number) => void,\n): Unsubscribe {\n return onState(conn, ConnState.Connected, callback);\n}\n\n/**\n * Adds an observer for when connection state changed to connecting.\n *\n * @param conn - The {@link Connect} instance\n * @param callback - callback triggered on connecting state. Two parameters\n * are provided: `attempt`, the sequential number of connect attempt, and\n * `delay` - delay in seconds before the next attempt\n */\nfunction onConnecting(\n conn: Connect,\n callback: (attempt: number, delay: number) => void,\n): Unsubscribe {\n return onState(conn, ConnState.Connecting, callback);\n}\n\n/**\n * Adds an observer for when connection state changed to disconnected.\n *\n * @param conn - The {@link Connect} instance\n * @param callback - callback triggered on disconnected state\n */\nfunction onDisconnected(conn: Connect, callback: () => void): Unsubscribe {\n return onState(conn, ConnState.Disconnected, callback);\n}\n\n/**\n * Adds an observer for when a new message received\n *\n * @example\n * ```javascript\n * const unsubscribe = onMessage(conn, (message) => {\n * console.log(message.body);\n * });\n * ```\n *\n * @param conn - The {@link Connect} instance\n * @param callback - The callback function triggered on message receive\n */\nfunction onMessage(\n conn: Connect,\n callback: (message: Message) => void,\n): Unsubscribe {\n const handler = (message: Message) => {\n callback(message);\n };\n\n conn.on('message', handler);\n\n return () => conn.off('message', handler);\n}\n\n/**\n * Starts a connection process.\n *\n * @remarks\n * If connect is successful a promise resolved by\n * and {@link onConnected} is triggered, otherwise a next attempt will be\n * automatically invoked and {@link onConnecting} is triggered.\n *\n * SDK connects automatically when its created. Connection procedure can be\n * aborted by calling {@link disconnect} function and the promise is rejected.\n *\n * @example\n * ```javascript\n * try {\n * const conn = await getConnect();\n *\n * await connect(conn);\n *\n * console.log('connected!');\n * } catch (err) {\n * console.log(err)\n * }\n * ```\n *\n * State of the connection can be handled separately\n *\n * @example\n * ```javascript\n * onConnected(() => console.log('connected'));\n *\n * onConnecting((attempt, delay) => console.log('connecting'));\n *\n * onDisconnected(() => console.log('disconnected'));\n * ```\n *\n * @param conn - The {@link Connect} instance\n * @param host - Interaction Cloud Studio host.\n * Can be found in Project Settings in API tab\n */\nfunction connect(conn: Connect): Promise<void> {\n // No need to memoize this, it's already memoized\n // in the ConnectImpl class implementation\n return conn.connect();\n}\n\n/**\n * Disconnect from the server and triggers {@link onDisconnected}\n *\n * @param conn - The {@link Connect} instance\n */\nfunction disconnect(conn: Connect): void {\n conn.disconnect();\n}\n\n/**\n * @internal\n */\nconst subscribeMemoized = memoizePromise(\n async (conn: Connect, channel: string): Promise<void> =>\n conn.subscribe(channel),\n (conn: Connect, channel: string): string => channel,\n);\n\n/**\n * Subscribe to the server channel.\n *\n * @remarks\n * Any message published to a channel is {@link onMessage | received}\n * only by subscribers to that channel. The sdk out of the box handles\n * all required subscriptions internally and {@link onMessage | handles messages}\n * so there is no need in to subscribe by developers.\n *\n * To stop receiving messages on a channel {@link unsubscribe} should be called.\n *\n * @param conn - The {@link Connect} instance\n * @param channel - Channel name\n */\nfunction subscribe(conn: Connect, channel: string): Promise<void> {\n return subscribeMemoized(conn, channel);\n}\n\n/**\n * Unsubscribe from the server channel.\n *\n * @remarks\n * Removes subscription to the channel so that recipient no longer receive\n * messages from that channel.\n *\n * @param conn - The {@link Connect} instance\n * @param channel - Channel name\n */\nfunction unsubscribe(conn: Connect, channel: string): void {\n conn.unsubscribe(channel);\n}\n\n/**\n * Send message to the server.\n *\n * @remarks\n * The sdk out of the box provides more high level functions that uses\n * this function to send data to the server. Though a developer still can\n * use it if he knows a message protocol (klass and body) and a channel\n * that expect the message.\n *\n * @param conn - The Connect instance\n * @param channel - Channel name. Only {@link subscribe | subscribers}\n * to that channel can send messages.\n * @param klass - Message class name.\n * @param body - Message payload\n */\nfunction send(\n conn: Connect,\n channel: string,\n klass: Klass | string,\n body: (string | number)[],\n): void {\n conn.send(channel, klass, body);\n}\n\n/**\n * Authenticates the connection with user credentials.\n *\n * @param conn - The Connect instance\n * @param userId - The user identifier\n * @param timestamp - The signature timestamp in seconds\n * @param signature - The session signature string\n *\n * @public\n */\nasync function login(\n conn: Connect,\n userId: string,\n timestamp: number,\n signature: string,\n): Promise<void> {\n const result = await conn.login(userId, timestamp, signature);\n\n return result;\n}\n\nasync function logout(conn: Connect): Promise<void> {\n const result = await conn.logout();\n\n return result;\n}\n\nexport {\n onConnected,\n onConnecting,\n onDisconnected,\n onMessage,\n disconnect,\n unsubscribe,\n send,\n getConnect,\n getConnectMemoized,\n connect,\n subscribe,\n subscribeMemoized,\n login,\n logout,\n};\n"],"names":[],"mappings":";;;;AAAA;;;;;;;AAOG;AAKH;;AAEG;AACI,MAAM,QAAQ,GAAG,UAAU;AA2DlC;;AAEG;IACS,UAIX;AAJD,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,gBAAA,CAAA,GAAA,iBAAkC,CAAA;AAClC,IAAA,SAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;AAC3B,IAAA,SAAA,CAAA,cAAA,CAAA,GAAA,cAA6B,CAAA;AAC/B,CAAC,EAJW,SAAS,KAAT,SAAS,GAIpB,EAAA,CAAA,CAAA,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;AAwBG;IACS,UAaX;AAbD,CAAA,UAAY,SAAS,EAAA;AACnB;;AAEG;AACH,IAAA,SAAA,CAAA,cAAA,CAAA,GAAA,cAA6B,CAAA;AAC7B;;AAEG;AACH,IAAA,SAAA,CAAA,YAAA,CAAA,GAAA,YAAyB,CAAA;AACzB;;AAEG;AACH,IAAA,SAAA,CAAA,WAAA,CAAA,GAAA,WAAuB,CAAA;AACzB,CAAC,EAbW,SAAS,KAAT,SAAS,GAapB,EAAA,CAAA,CAAA,CAAA;AAED;;AAEG;IACS,MAyDX;AAzDD,CAAA,UAAY,KAAK,EAAA;AACf;;AAEG;AACH,IAAA,KAAA,CAAA,cAAA,CAAA,GAAA,MAAqB,CAAA;AACrB;;;AAGG;AACH,IAAA,KAAA,CAAA,sBAAA,CAAA,GAAA,OAA8B,CAAA;AAC9B;;;AAGG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;;;;AAcG;AACH,SAAS,IAAI,CACX,IAAa,EACb,OAAe,EACf,KAAqB,EACrB,IAAyB,EAAA;IAEzB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;;;;AASG;AACH,eAAe,KAAK,CAClB,IAAa,EACb,MAAc,EACd,SAAiB,EACjB,SAAiB,EAAA;AAEjB,IAAA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAE9D,IAAA,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,eAAe,MAAM,CAAC,IAAa,EAAA;AACjC,IAAA,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;AAEnC,IAAA,OAAO,MAAM,CAAC;AAChB;;;;"}
|
package/dist/types.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { Emitter } from '@monterosa/sdk-util';
|
|
|
13
13
|
*/
|
|
14
14
|
export declare const KIT_NAME = "connect";
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Represents a Connect Kit instance. Obtain one via {@link getConnect}.
|
|
17
17
|
*/
|
|
18
18
|
export interface Connect extends MonterosaKit, Emitter {
|
|
19
19
|
/**
|
|
@@ -52,6 +52,9 @@ export interface Connect extends MonterosaKit, Emitter {
|
|
|
52
52
|
* @internal
|
|
53
53
|
*/
|
|
54
54
|
send(channel: string, klass: string, body: (string | number)[]): void;
|
|
55
|
+
/**
|
|
56
|
+
* @internal
|
|
57
|
+
*/
|
|
55
58
|
login(userId: string, timestamp: number, signature: string): Promise<void>;
|
|
56
59
|
logout(): void;
|
|
57
60
|
}
|
|
@@ -64,8 +67,10 @@ export declare enum InitState {
|
|
|
64
67
|
Initialising = "initialising"
|
|
65
68
|
}
|
|
66
69
|
/**
|
|
67
|
-
* A list of possible connection states.
|
|
68
|
-
*
|
|
70
|
+
* A list of possible connection states.
|
|
71
|
+
*
|
|
72
|
+
* @remarks
|
|
73
|
+
* Can be used with {@link Connect | Connect.state} to determine the current state.
|
|
69
74
|
*
|
|
70
75
|
* By default {@link Connect} is in the disconnected state.
|
|
71
76
|
* When {@link connect} invoked `Connect` state switches to
|
|
@@ -162,20 +167,20 @@ export declare enum Klass {
|
|
|
162
167
|
Vote = "v"
|
|
163
168
|
}
|
|
164
169
|
/**
|
|
165
|
-
*
|
|
170
|
+
* Represents a message received from or sent to the server.
|
|
171
|
+
* Subscribe via {@link onMessage} to receive messages.
|
|
166
172
|
*/
|
|
167
173
|
export interface Message {
|
|
168
174
|
/**
|
|
169
|
-
* The channel
|
|
170
|
-
* {@link subscribe} to
|
|
171
|
-
* messages
|
|
175
|
+
* The channel on which this message was received. You must
|
|
176
|
+
* {@link subscribe} to a channel to start receiving messages.
|
|
172
177
|
*/
|
|
173
178
|
channel: string;
|
|
174
179
|
/**
|
|
175
180
|
* The class indicates the desired action to be performed or the result of
|
|
176
181
|
* the action. E.g. in order to authenticate a developer should {@link send}
|
|
177
|
-
* {@link Klass.AuthenticateResponse} klass message as a response on
|
|
178
|
-
* a received {@link Klass.Authenticate} message
|
|
182
|
+
* {@link Klass | Klass.AuthenticateResponse} klass message as a response on
|
|
183
|
+
* a received {@link Klass | Klass.Authenticate} message
|
|
179
184
|
*/
|
|
180
185
|
klass: Klass | string;
|
|
181
186
|
/**
|
|
@@ -183,7 +188,7 @@ export interface Message {
|
|
|
183
188
|
*/
|
|
184
189
|
sent_at: number;
|
|
185
190
|
/**
|
|
186
|
-
* The message payload. Each
|
|
191
|
+
* The message payload. Each piece of data is a `string`
|
|
187
192
|
*/
|
|
188
193
|
body: string[];
|
|
189
194
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monterosa/sdk-connect-kit",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.2",
|
|
4
4
|
"description": "Monterosa JS SDK / Connect",
|
|
5
5
|
"author": "Monterosa Productions Limited <hello@monterosa.co.uk> (https://www.monterosa.co/)",
|
|
6
|
-
"main": "dist/index.
|
|
7
|
-
"browser": "dist/index.esm.js",
|
|
8
|
-
"module": "dist/index.esm.js",
|
|
6
|
+
"main": "./dist/index.js",
|
|
9
7
|
"types": "./dist/index.d.ts",
|
|
10
|
-
"
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
11
15
|
"files": [
|
|
12
16
|
"dist"
|
|
13
17
|
],
|
|
@@ -19,21 +23,19 @@
|
|
|
19
23
|
"test:ci": "jest --color --coverage --ci --reporters=jest-junit",
|
|
20
24
|
"api-report": "api-extractor run --local --verbose"
|
|
21
25
|
},
|
|
22
|
-
"keywords": [
|
|
26
|
+
"keywords": [
|
|
27
|
+
"monterosa",
|
|
28
|
+
"sdk",
|
|
29
|
+
"interaction-cloud",
|
|
30
|
+
"connect"
|
|
31
|
+
],
|
|
23
32
|
"license": "MIT",
|
|
24
|
-
"peerDependencies": {
|
|
25
|
-
"@monterosa/sdk-core": "0.x",
|
|
26
|
-
"@monterosa/sdk-enmasse-kit": "0.x",
|
|
27
|
-
"@monterosa/sdk-util": "0.x"
|
|
28
|
-
},
|
|
29
33
|
"dependencies": {
|
|
30
|
-
"@
|
|
31
|
-
"@monterosa/sdk-
|
|
32
|
-
"@monterosa/sdk-
|
|
33
|
-
"@monterosa/sdk-util": "^2.0.0-rc.1"
|
|
34
|
+
"@monterosa/sdk-core": "2.0.0-rc.2",
|
|
35
|
+
"@monterosa/sdk-enmasse-kit": "2.0.0-rc.2",
|
|
36
|
+
"@monterosa/sdk-util": "2.0.0-rc.2"
|
|
34
37
|
},
|
|
35
38
|
"devDependencies": {
|
|
36
|
-
"@rollup/plugin-commonjs": "^21.1.0",
|
|
37
39
|
"@rollup/plugin-json": "^4.1.0",
|
|
38
40
|
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
39
41
|
"@rollup/plugin-terser": "^0.4.4",
|
|
@@ -51,5 +53,5 @@
|
|
|
51
53
|
"publishConfig": {
|
|
52
54
|
"access": "public"
|
|
53
55
|
},
|
|
54
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "0e2d4cd71055bf0ab38ec5a73d6040c55151da1c"
|
|
55
57
|
}
|
package/dist/index.cjs.js
DELETED
|
@@ -1,645 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var sdkCore = require('@monterosa/sdk-core');
|
|
6
|
-
var sdkUtil = require('@monterosa/sdk-util');
|
|
7
|
-
var Enmasse = require('@monterosa/sdk-enmasse-kit');
|
|
8
|
-
|
|
9
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
-
|
|
11
|
-
var Enmasse__default = /*#__PURE__*/_interopDefaultLegacy(Enmasse);
|
|
12
|
-
|
|
13
|
-
/******************************************************************************
|
|
14
|
-
Copyright (c) Microsoft Corporation.
|
|
15
|
-
|
|
16
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
17
|
-
purpose with or without fee is hereby granted.
|
|
18
|
-
|
|
19
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
20
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
21
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
22
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
23
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
24
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
25
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
26
|
-
***************************************************************************** */
|
|
27
|
-
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
28
|
-
|
|
29
|
-
var extendStatics = function(d, b) {
|
|
30
|
-
extendStatics = Object.setPrototypeOf ||
|
|
31
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
32
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
33
|
-
return extendStatics(d, b);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function __extends(d, b) {
|
|
37
|
-
if (typeof b !== "function" && b !== null)
|
|
38
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
39
|
-
extendStatics(d, b);
|
|
40
|
-
function __() { this.constructor = d; }
|
|
41
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
45
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
46
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
47
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
48
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
49
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
50
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function __generator(thisArg, body) {
|
|
55
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
56
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
57
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
58
|
-
function step(op) {
|
|
59
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
60
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
61
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
62
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
63
|
-
switch (op[0]) {
|
|
64
|
-
case 0: case 1: t = op; break;
|
|
65
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
66
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
67
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
68
|
-
default:
|
|
69
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
70
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
71
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
72
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
73
|
-
if (t[2]) _.ops.pop();
|
|
74
|
-
_.trys.pop(); continue;
|
|
75
|
-
}
|
|
76
|
-
op = body.call(thisArg, _);
|
|
77
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
78
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function __spreadArray(to, from, pack) {
|
|
83
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
84
|
-
if (ar || !(i in from)) {
|
|
85
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
86
|
-
ar[i] = from[i];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
93
|
-
var e = new Error(message);
|
|
94
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @license
|
|
99
|
-
* @monterosa/sdk-connect-kit
|
|
100
|
-
*
|
|
101
|
-
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
102
|
-
*
|
|
103
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
104
|
-
*/
|
|
105
|
-
/**
|
|
106
|
-
* @internal
|
|
107
|
-
*/
|
|
108
|
-
var KIT_NAME = 'connect';
|
|
109
|
-
/**
|
|
110
|
-
* @internal
|
|
111
|
-
*/
|
|
112
|
-
exports.InitState = void 0;
|
|
113
|
-
(function (InitState) {
|
|
114
|
-
InitState["NotInitialised"] = "not_initialised";
|
|
115
|
-
InitState["Initialised"] = "initialised";
|
|
116
|
-
InitState["Initialising"] = "initialising";
|
|
117
|
-
})(exports.InitState || (exports.InitState = {}));
|
|
118
|
-
/**
|
|
119
|
-
* A list of possible connection states. Can be used with
|
|
120
|
-
* {@link Connect.state} to determine the current state.
|
|
121
|
-
*
|
|
122
|
-
* By default {@link Connect} is in the disconnected state.
|
|
123
|
-
* When {@link connect} invoked `Connect` state switches to
|
|
124
|
-
* `ConnState.Connecting` and connection is maintained permanently until
|
|
125
|
-
* {@link disconnect} method is invoked. If connection was unsucessful,
|
|
126
|
-
* a new attempt will start after a short delay and `ConnState.connecting`
|
|
127
|
-
* is triggered. Delays between attempts increased based on this sequence:
|
|
128
|
-
* 0, 3, 5, 10, 20, 30, 45, 60 where 60 seconds is the max.
|
|
129
|
-
*
|
|
130
|
-
* If `Connect` was previously connected and for any reason connection is lost,
|
|
131
|
-
* the state changed to `ConnState.Connecting` again and the connection process
|
|
132
|
-
* starts again automatically.
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```javascript
|
|
136
|
-
* if (conn.state === ConnState.Connecting) {
|
|
137
|
-
* // display "connecting" message
|
|
138
|
-
* }
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
exports.ConnState = void 0;
|
|
142
|
-
(function (ConnState) {
|
|
143
|
-
/**
|
|
144
|
-
* Disconnected state
|
|
145
|
-
*/
|
|
146
|
-
ConnState["Disconnected"] = "disconnected";
|
|
147
|
-
/**
|
|
148
|
-
* Connecting state
|
|
149
|
-
*/
|
|
150
|
-
ConnState["Connecting"] = "connecting";
|
|
151
|
-
/**
|
|
152
|
-
* Connected state
|
|
153
|
-
*/
|
|
154
|
-
ConnState["Connected"] = "connected";
|
|
155
|
-
})(exports.ConnState || (exports.ConnState = {}));
|
|
156
|
-
/**
|
|
157
|
-
* Class of the {@link Message}
|
|
158
|
-
*/
|
|
159
|
-
exports.Klass = void 0;
|
|
160
|
-
(function (Klass) {
|
|
161
|
-
/**
|
|
162
|
-
* Authentication request. Sent by server on client connection.
|
|
163
|
-
*/
|
|
164
|
-
Klass["Authenticate"] = "auth";
|
|
165
|
-
/**
|
|
166
|
-
* Authentication response. Sent by client as response
|
|
167
|
-
* to authentication request.
|
|
168
|
-
*/
|
|
169
|
-
Klass["AuthenticateResponse"] = "authr";
|
|
170
|
-
/**
|
|
171
|
-
* Authentication acknowledgement. Sent by the server as confirmation
|
|
172
|
-
* of successful authentication.
|
|
173
|
-
*/
|
|
174
|
-
Klass["AuthenticateSuccess"] = "authok";
|
|
175
|
-
/**
|
|
176
|
-
* Ping message is sent by server periodically as a keep-alive.
|
|
177
|
-
* Ping message is only sent if no messages are sent for specific time
|
|
178
|
-
* period, meaning if there are other messages sent frequently enough
|
|
179
|
-
* then ping messages are not sent at all.
|
|
180
|
-
*/
|
|
181
|
-
Klass["Ping"] = "ping";
|
|
182
|
-
/**
|
|
183
|
-
* Subscribe to a channel. Sent by the client to subscribe to a channel
|
|
184
|
-
*/
|
|
185
|
-
Klass["Subscribe"] = "sub";
|
|
186
|
-
/**
|
|
187
|
-
* Unsubscribe from a channel. Sent by the client to unsubscribe from a channel
|
|
188
|
-
*/
|
|
189
|
-
Klass["Unsububscribe"] = "unsub";
|
|
190
|
-
/**
|
|
191
|
-
* End of cache. Sent by the server to notify that all messages are sent from
|
|
192
|
-
* a channel cache
|
|
193
|
-
*/
|
|
194
|
-
Klass["EndOfCache"] = "eoc";
|
|
195
|
-
/**
|
|
196
|
-
* User login. Sent by client to supply verified user identity to the server.
|
|
197
|
-
*/
|
|
198
|
-
Klass["Login"] = "login";
|
|
199
|
-
/**
|
|
200
|
-
* User login success
|
|
201
|
-
*/
|
|
202
|
-
Klass["LoginSuccess"] = "login_ok";
|
|
203
|
-
/**
|
|
204
|
-
* User login failure
|
|
205
|
-
*/
|
|
206
|
-
Klass["LoginFail"] = "login_fail";
|
|
207
|
-
/**
|
|
208
|
-
* Averages counters. Client can submit a counter which is processed together
|
|
209
|
-
* with other counters to determine the average of all counters within specific
|
|
210
|
-
* demographics segment.
|
|
211
|
-
*/
|
|
212
|
-
Klass["Counter"] = "counter";
|
|
213
|
-
/**
|
|
214
|
-
* Client votes. Sents by a user to vote for a poll option
|
|
215
|
-
*/
|
|
216
|
-
Klass["Vote"] = "v";
|
|
217
|
-
})(exports.Klass || (exports.Klass = {}));
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @license
|
|
221
|
-
* @monterosa/sdk-connect-kit
|
|
222
|
-
*
|
|
223
|
-
* Copyright © 2022 Monterosa Productions Limited. All rights reserved.
|
|
224
|
-
*
|
|
225
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
226
|
-
*/
|
|
227
|
-
function onState(conn, needle, callback) {
|
|
228
|
-
var handler = function (state) {
|
|
229
|
-
var rest = [];
|
|
230
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
231
|
-
rest[_i - 1] = arguments[_i];
|
|
232
|
-
}
|
|
233
|
-
if (state === needle) {
|
|
234
|
-
callback.apply(void 0, rest);
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
conn.on('state', handler);
|
|
238
|
-
return function () { return conn.off('state', handler); };
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/* eslint class-methods-use-this: "off" */
|
|
242
|
-
/**
|
|
243
|
-
* @internal
|
|
244
|
-
*/
|
|
245
|
-
var ConnectImpl = /** @class */ (function (_super) {
|
|
246
|
-
__extends(ConnectImpl, _super);
|
|
247
|
-
function ConnectImpl() {
|
|
248
|
-
var _this = _super.call(this) || this;
|
|
249
|
-
_this.initState = exports.InitState.NotInitialised;
|
|
250
|
-
_this.initPromise = Promise.resolve();
|
|
251
|
-
_this.connectPromise = null;
|
|
252
|
-
Enmasse__default["default"].bind(Enmasse__default["default"].ON_STATE, function (state) {
|
|
253
|
-
var rest = [];
|
|
254
|
-
for (var _i = 1; _i < arguments.length; _i++) {
|
|
255
|
-
rest[_i - 1] = arguments[_i];
|
|
256
|
-
}
|
|
257
|
-
if (state === Enmasse__default["default"].STATE_CONNECTED) {
|
|
258
|
-
var timestamp = rest[0];
|
|
259
|
-
sdkUtil.setTimestamp(timestamp);
|
|
260
|
-
}
|
|
261
|
-
_this.emit.apply(_this, __spreadArray(['state', ConnectImpl.toConnState(state)], rest, false));
|
|
262
|
-
});
|
|
263
|
-
Enmasse__default["default"].bind(Enmasse__default["default"].ON_MESSAGE, function (message) {
|
|
264
|
-
_this.emit('message', message);
|
|
265
|
-
});
|
|
266
|
-
return _this;
|
|
267
|
-
}
|
|
268
|
-
Object.defineProperty(ConnectImpl.prototype, "state", {
|
|
269
|
-
get: function () {
|
|
270
|
-
return ConnectImpl.toConnState(Enmasse__default["default"].getState());
|
|
271
|
-
},
|
|
272
|
-
enumerable: false,
|
|
273
|
-
configurable: true
|
|
274
|
-
});
|
|
275
|
-
Object.defineProperty(ConnectImpl.prototype, "sessionId", {
|
|
276
|
-
get: function () {
|
|
277
|
-
return Enmasse__default["default"].getSessionId();
|
|
278
|
-
},
|
|
279
|
-
enumerable: false,
|
|
280
|
-
configurable: true
|
|
281
|
-
});
|
|
282
|
-
ConnectImpl.getInstance = function () {
|
|
283
|
-
if (!ConnectImpl.instance) {
|
|
284
|
-
ConnectImpl.instance = new ConnectImpl();
|
|
285
|
-
}
|
|
286
|
-
return ConnectImpl.instance;
|
|
287
|
-
};
|
|
288
|
-
ConnectImpl.toConnState = function (state) {
|
|
289
|
-
switch (state) {
|
|
290
|
-
default:
|
|
291
|
-
case Enmasse__default["default"].STATE_DISCONNECTED:
|
|
292
|
-
return exports.ConnState.Disconnected;
|
|
293
|
-
case Enmasse__default["default"].STATE_CONNECTING:
|
|
294
|
-
return exports.ConnState.Connecting;
|
|
295
|
-
case Enmasse__default["default"].STATE_CONNECTED:
|
|
296
|
-
return exports.ConnState.Connected;
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
ConnectImpl.prototype.init = function (host) {
|
|
300
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
301
|
-
var _this = this;
|
|
302
|
-
return __generator(this, function (_a) {
|
|
303
|
-
if (this.initState === exports.InitState.Initialising ||
|
|
304
|
-
this.initState === exports.InitState.Initialised) {
|
|
305
|
-
return [2 /*return*/, this.initPromise];
|
|
306
|
-
}
|
|
307
|
-
this.initPromise = new Promise(function (resolve, reject) {
|
|
308
|
-
_this.initState = exports.InitState.Initialising;
|
|
309
|
-
Enmasse__default["default"].bind(Enmasse__default["default"].ON_READY, function () {
|
|
310
|
-
_this.initState = exports.InitState.Initialised;
|
|
311
|
-
Enmasse__default["default"].unbind(Enmasse__default["default"].ON_READY);
|
|
312
|
-
Enmasse__default["default"].unbind(Enmasse__default["default"].ON_ERROR);
|
|
313
|
-
resolve();
|
|
314
|
-
});
|
|
315
|
-
Enmasse__default["default"].bind(Enmasse__default["default"].ON_ERROR, function (err) {
|
|
316
|
-
_this.initState = exports.InitState.NotInitialised;
|
|
317
|
-
Enmasse__default["default"].unbind(Enmasse__default["default"].ON_READY);
|
|
318
|
-
Enmasse__default["default"].unbind(Enmasse__default["default"].ON_ERROR);
|
|
319
|
-
reject(new Error("Unable to initialise connect kit: ".concat(err)));
|
|
320
|
-
});
|
|
321
|
-
Enmasse__default["default"].init({
|
|
322
|
-
config: "https://".concat(host, "/config/enmasse.json"),
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
return [2 /*return*/, this.initPromise];
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
};
|
|
329
|
-
ConnectImpl.prototype.connect = function () {
|
|
330
|
-
var _this = this;
|
|
331
|
-
if (this.initState !== exports.InitState.Initialised) {
|
|
332
|
-
return Promise.reject(new Error('must be initialised before connecting'));
|
|
333
|
-
}
|
|
334
|
-
if (this.state === exports.ConnState.Connected) {
|
|
335
|
-
return Promise.resolve();
|
|
336
|
-
}
|
|
337
|
-
if (this.state === exports.ConnState.Connecting) {
|
|
338
|
-
if (this.connectPromise) {
|
|
339
|
-
return this.connectPromise;
|
|
340
|
-
}
|
|
341
|
-
// This should never happen - indicates a bug in state management
|
|
342
|
-
return Promise.reject(new Error('BUG: Connection state is Connecting but connectPromise is null — ' +
|
|
343
|
-
'this indicates an internal inconsistency'));
|
|
344
|
-
}
|
|
345
|
-
this.connectPromise = new Promise(function (resolve, reject) {
|
|
346
|
-
var handler = function (state) {
|
|
347
|
-
switch (state) {
|
|
348
|
-
case exports.ConnState.Connected:
|
|
349
|
-
Enmasse__default["default"].unbind(Enmasse__default["default"].ON_STATE, handler);
|
|
350
|
-
_this.connectPromise = null;
|
|
351
|
-
resolve();
|
|
352
|
-
break;
|
|
353
|
-
case exports.ConnState.Disconnected:
|
|
354
|
-
Enmasse__default["default"].unbind(Enmasse__default["default"].ON_STATE, handler);
|
|
355
|
-
_this.connectPromise = null;
|
|
356
|
-
reject(new Error('disconnected'));
|
|
357
|
-
break;
|
|
358
|
-
case exports.ConnState.Connecting:
|
|
359
|
-
// The Enmasse library may emit the "connecting" state multiple
|
|
360
|
-
// times. This is expected and does not impact the connection
|
|
361
|
-
// process, so we safely ignore it.
|
|
362
|
-
break;
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
Enmasse__default["default"].bind(Enmasse__default["default"].ON_STATE, handler);
|
|
366
|
-
Enmasse__default["default"].connect();
|
|
367
|
-
});
|
|
368
|
-
return this.connectPromise;
|
|
369
|
-
};
|
|
370
|
-
ConnectImpl.prototype.disconnect = function () {
|
|
371
|
-
Enmasse__default["default"].disconnect();
|
|
372
|
-
};
|
|
373
|
-
ConnectImpl.prototype.subscribe = function (channel) {
|
|
374
|
-
return new Promise(function (resolve) {
|
|
375
|
-
var handler = function (ch) {
|
|
376
|
-
if (ch !== channel)
|
|
377
|
-
return;
|
|
378
|
-
Enmasse__default["default"].unbind(Enmasse__default["default"].ON_EOC, handler);
|
|
379
|
-
resolve();
|
|
380
|
-
};
|
|
381
|
-
Enmasse__default["default"].bind(Enmasse__default["default"].ON_EOC, handler);
|
|
382
|
-
Enmasse__default["default"].subscribe(channel);
|
|
383
|
-
});
|
|
384
|
-
};
|
|
385
|
-
ConnectImpl.prototype.unsubscribe = function (channel) {
|
|
386
|
-
Enmasse__default["default"].unsubscribe(channel);
|
|
387
|
-
};
|
|
388
|
-
ConnectImpl.prototype.send = function (channel, klass, body) {
|
|
389
|
-
Enmasse__default["default"].send(channel, klass, body);
|
|
390
|
-
};
|
|
391
|
-
ConnectImpl.prototype.login = function (userId, timestamp, signature) {
|
|
392
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
393
|
-
return __generator(this, function (_a) {
|
|
394
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
395
|
-
Enmasse__default["default"].login(userId, timestamp, signature, resolve, function () {
|
|
396
|
-
reject(new Error('Login failure'));
|
|
397
|
-
});
|
|
398
|
-
})];
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
};
|
|
402
|
-
ConnectImpl.prototype.logout = function () {
|
|
403
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
404
|
-
return __generator(this, function (_a) {
|
|
405
|
-
Enmasse__default["default"].logout();
|
|
406
|
-
return [2 /*return*/, Promise.resolve()];
|
|
407
|
-
});
|
|
408
|
-
});
|
|
409
|
-
};
|
|
410
|
-
ConnectImpl.prototype.delete = function () { };
|
|
411
|
-
return ConnectImpl;
|
|
412
|
-
}(sdkUtil.Emitter));
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* @license
|
|
416
|
-
* @monterosa/sdk-connect-kit
|
|
417
|
-
*
|
|
418
|
-
* Copyright © 2022-2024 Monterosa Productions Limited. All rights reserved.
|
|
419
|
-
*
|
|
420
|
-
* More details on the license can be found at https://www.monterosa.co/sdk/license
|
|
421
|
-
*/
|
|
422
|
-
/**
|
|
423
|
-
* @internal
|
|
424
|
-
*/
|
|
425
|
-
var getConnectMemoized = sdkUtil.memoizePromise(function (host) { return __awaiter(void 0, void 0, void 0, function () {
|
|
426
|
-
var conn;
|
|
427
|
-
return __generator(this, function (_a) {
|
|
428
|
-
switch (_a.label) {
|
|
429
|
-
case 0:
|
|
430
|
-
conn = ConnectImpl.getInstance();
|
|
431
|
-
return [4 /*yield*/, conn.init(host)];
|
|
432
|
-
case 1:
|
|
433
|
-
_a.sent();
|
|
434
|
-
return [2 /*return*/, conn];
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
}); }, function (host) { return host; });
|
|
438
|
-
/**
|
|
439
|
-
* Returns the {@link Connect} instance associated with the provided
|
|
440
|
-
* host. If host is not provided, it returns Connect instance for
|
|
441
|
-
* the host associated with the default sdk.
|
|
442
|
-
*
|
|
443
|
-
* @param sdk - Monterosa SDK.
|
|
444
|
-
*/
|
|
445
|
-
function getConnect(host) {
|
|
446
|
-
if (host === undefined) {
|
|
447
|
-
var sdk = sdkCore.getSdk();
|
|
448
|
-
host = sdk.options.host;
|
|
449
|
-
}
|
|
450
|
-
return getConnectMemoized(host);
|
|
451
|
-
}
|
|
452
|
-
/**
|
|
453
|
-
* Adds an observer for when connection state changed to connected.
|
|
454
|
-
*
|
|
455
|
-
* @param conn - The {@link Connect} instance
|
|
456
|
-
* @param callback - The callback triggered when {@link ConnState | state}
|
|
457
|
-
* changed to connected
|
|
458
|
-
*/
|
|
459
|
-
function onConnected(conn, callback) {
|
|
460
|
-
return onState(conn, exports.ConnState.Connected, callback);
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Adds an observer for when connection state changed to connecting.
|
|
464
|
-
*
|
|
465
|
-
* @param conn - The {@link Connect} instance
|
|
466
|
-
* @param callback - callback triggered on connecting state. Two parameters
|
|
467
|
-
* are provided: `attempt` — sequential number of connect attempt and
|
|
468
|
-
* `delay` - delay in seconds before the next attempt
|
|
469
|
-
*/
|
|
470
|
-
function onConnecting(conn, callback) {
|
|
471
|
-
return onState(conn, exports.ConnState.Connecting, callback);
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* Adds an observer for when connection state changed to disconnected.
|
|
475
|
-
*
|
|
476
|
-
* @param conn - The {@link Connect} instance
|
|
477
|
-
* @param callback - callback triggered on disconnected state
|
|
478
|
-
*/
|
|
479
|
-
function onDisconnected(conn, callback) {
|
|
480
|
-
return onState(conn, exports.ConnState.Disconnected, callback);
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Adds an observer for when a new message received
|
|
484
|
-
*
|
|
485
|
-
* @example
|
|
486
|
-
* ```javascript
|
|
487
|
-
* const unsubscribe = onMessage(conn, (message) => {
|
|
488
|
-
* console.log(message.body);
|
|
489
|
-
* });
|
|
490
|
-
* ```
|
|
491
|
-
*
|
|
492
|
-
* @param conn - The {@link Connect} instance
|
|
493
|
-
* @param callback - The callback function triggered on message receive
|
|
494
|
-
*/
|
|
495
|
-
function onMessage(conn, callback) {
|
|
496
|
-
var handler = function (message) {
|
|
497
|
-
callback(message);
|
|
498
|
-
};
|
|
499
|
-
conn.on('message', handler);
|
|
500
|
-
return function () { return conn.off('message', handler); };
|
|
501
|
-
}
|
|
502
|
-
/**
|
|
503
|
-
* Starts a connection process. If connect is successful a promise resolved by
|
|
504
|
-
* and {@link onConnected} is triggered, otherwise a next attempt will be
|
|
505
|
-
* automatically invoked and {@link onConnecting} is triggered.
|
|
506
|
-
*
|
|
507
|
-
* SDK connects automatically when its created. Connection procedure can be
|
|
508
|
-
* aborted by calling {@link disconnect} function and the promise is rejected.
|
|
509
|
-
*
|
|
510
|
-
* @example
|
|
511
|
-
* ```javascript
|
|
512
|
-
* try {
|
|
513
|
-
* const conn = await getConnect();
|
|
514
|
-
*
|
|
515
|
-
* await connect(conn);
|
|
516
|
-
*
|
|
517
|
-
* console.log('connected!');
|
|
518
|
-
* } catch (err) {
|
|
519
|
-
* console.log(err)
|
|
520
|
-
* }
|
|
521
|
-
* ```
|
|
522
|
-
*
|
|
523
|
-
* State of the connection can be handled separately
|
|
524
|
-
*
|
|
525
|
-
* @example
|
|
526
|
-
* ```javascript
|
|
527
|
-
* onConnected(() => console.log('connected'));
|
|
528
|
-
*
|
|
529
|
-
* onConnecting((attempt, delay) => console.log('connecting'));
|
|
530
|
-
*
|
|
531
|
-
* onDisconnected(() => console.log('disconnected'));
|
|
532
|
-
* ```
|
|
533
|
-
*
|
|
534
|
-
* @param conn - The {@link Connect} instance
|
|
535
|
-
* @param host - Interaction Cloud Studio host.
|
|
536
|
-
* Can be found in Project Settings in API tab
|
|
537
|
-
*/
|
|
538
|
-
function connect(conn) {
|
|
539
|
-
// No need to memoize this, it's already memoized
|
|
540
|
-
// in the ConnectImpl class implementation
|
|
541
|
-
return conn.connect();
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Disconnect from the server and triggers {@link onDisconnected}
|
|
545
|
-
*
|
|
546
|
-
* @param conn - The {@link Connect} instance
|
|
547
|
-
*/
|
|
548
|
-
function disconnect(conn) {
|
|
549
|
-
conn.disconnect();
|
|
550
|
-
}
|
|
551
|
-
/**
|
|
552
|
-
* @internal
|
|
553
|
-
*/
|
|
554
|
-
var subscribeMemoized = sdkUtil.memoizePromise(function (conn, channel) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
555
|
-
return [2 /*return*/, conn.subscribe(channel)];
|
|
556
|
-
}); }); }, function (conn, channel) { return channel; });
|
|
557
|
-
/**
|
|
558
|
-
* Subscribe to the server channel.
|
|
559
|
-
*
|
|
560
|
-
* Any message published to a channel is {@link onMessage | received}
|
|
561
|
-
* only by subscribers to that channel. The sdk out of the box handles
|
|
562
|
-
* all required subscriptions internally and {@link onMessage | handles messages}
|
|
563
|
-
* so there is no need in to subscribe by developers.
|
|
564
|
-
*
|
|
565
|
-
* To stop receiving messages on a channel {@link unsubscribe} should be called.
|
|
566
|
-
*
|
|
567
|
-
* @param conn - The {@link Connect} instance
|
|
568
|
-
* @param channel - Channel name
|
|
569
|
-
*/
|
|
570
|
-
function subscribe(conn, channel) {
|
|
571
|
-
return subscribeMemoized(conn, channel);
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* Unsubscribe from the server channel.
|
|
575
|
-
*
|
|
576
|
-
* Removes subscription to the channel so that recipient no longer receive
|
|
577
|
-
* messages from that channel.
|
|
578
|
-
*
|
|
579
|
-
* @param conn - The {@link Connect} instance
|
|
580
|
-
* @param channel - Channel name
|
|
581
|
-
*/
|
|
582
|
-
function unsubscribe(conn, channel) {
|
|
583
|
-
conn.unsubscribe(channel);
|
|
584
|
-
}
|
|
585
|
-
/**
|
|
586
|
-
* Send message to the server.
|
|
587
|
-
*
|
|
588
|
-
* The sdk out of the box provides more high level functions that uses
|
|
589
|
-
* this function to send data to the server. Though a developer still can
|
|
590
|
-
* use it if he knows a message protocol (klass and body) and a channel
|
|
591
|
-
* that expect the message.
|
|
592
|
-
*
|
|
593
|
-
* @param conn - The Connect instance
|
|
594
|
-
* @param channel - Channel name. Only {@link subscribe | subscribers}
|
|
595
|
-
* to that channel can send messages.
|
|
596
|
-
* @param klass - Message class name.
|
|
597
|
-
* @param body - Message payload
|
|
598
|
-
*/
|
|
599
|
-
function send(conn, channel, klass, body) {
|
|
600
|
-
conn.send(channel, klass, body);
|
|
601
|
-
}
|
|
602
|
-
function login(conn, userId, timestamp, signature) {
|
|
603
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
604
|
-
var result;
|
|
605
|
-
return __generator(this, function (_a) {
|
|
606
|
-
switch (_a.label) {
|
|
607
|
-
case 0: return [4 /*yield*/, conn.login(userId, timestamp, signature)];
|
|
608
|
-
case 1:
|
|
609
|
-
result = _a.sent();
|
|
610
|
-
return [2 /*return*/, result];
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
|
-
function logout(conn) {
|
|
616
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
617
|
-
var result;
|
|
618
|
-
return __generator(this, function (_a) {
|
|
619
|
-
switch (_a.label) {
|
|
620
|
-
case 0: return [4 /*yield*/, conn.logout()];
|
|
621
|
-
case 1:
|
|
622
|
-
result = _a.sent();
|
|
623
|
-
return [2 /*return*/, result];
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
exports.ConnectImpl = ConnectImpl;
|
|
630
|
-
exports.KIT_NAME = KIT_NAME;
|
|
631
|
-
exports.connect = connect;
|
|
632
|
-
exports.disconnect = disconnect;
|
|
633
|
-
exports.getConnect = getConnect;
|
|
634
|
-
exports.getConnectMemoized = getConnectMemoized;
|
|
635
|
-
exports.login = login;
|
|
636
|
-
exports.logout = logout;
|
|
637
|
-
exports.onConnected = onConnected;
|
|
638
|
-
exports.onConnecting = onConnecting;
|
|
639
|
-
exports.onDisconnected = onDisconnected;
|
|
640
|
-
exports.onMessage = onMessage;
|
|
641
|
-
exports.send = send;
|
|
642
|
-
exports.subscribe = subscribe;
|
|
643
|
-
exports.subscribeMemoized = subscribeMemoized;
|
|
644
|
-
exports.unsubscribe = unsubscribe;
|
|
645
|
-
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/types.ts","../src/helpers.ts","../src/connect_impl.ts","../src/connect.ts"],"sourcesContent":["/**\n * @license\n * @monterosa/sdk-connect-kit\n *\n * Copyright © 2022 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaKit } from '@monterosa/sdk-core';\nimport { Emitter } from '@monterosa/sdk-util';\n\n/**\n * @internal\n */\nexport const KIT_NAME = 'connect';\n\n/**\n * Interface representing Connect kit.\n */\nexport interface Connect extends MonterosaKit, Emitter {\n /**\n * Connection state\n */\n state: ConnState;\n\n /**\n * Session ID\n */\n sessionId: string | null;\n\n /**\n * @internal\n */\n initState: InitState;\n\n /**\n * @internal\n */\n init(host: string): Promise<void>;\n\n /**\n * @internal\n */\n connect(): Promise<void>;\n\n /**\n * @internal\n */\n disconnect(): void;\n\n /**\n * @internal\n */\n subscribe(channel: string): Promise<void>;\n\n /**\n * @internal\n */\n unsubscribe(channel: string): void;\n\n /**\n * @internal\n */\n send(channel: string, klass: string, body: (string | number)[]): void;\n\n login(userId: string, timestamp: number, signature: string): Promise<void>;\n\n logout(): void;\n}\n\n/**\n * @internal\n */\nexport enum InitState {\n NotInitialised = 'not_initialised',\n Initialised = 'initialised',\n Initialising = 'initialising',\n}\n\n/**\n * A list of possible connection states. Can be used with\n * {@link Connect.state} to determine the current state.\n *\n * By default {@link Connect} is in the disconnected state.\n * When {@link connect} invoked `Connect` state switches to\n * `ConnState.Connecting` and connection is maintained permanently until\n * {@link disconnect} method is invoked. If connection was unsucessful,\n * a new attempt will start after a short delay and `ConnState.connecting`\n * is triggered. Delays between attempts increased based on this sequence:\n * 0, 3, 5, 10, 20, 30, 45, 60 where 60 seconds is the max.\n *\n * If `Connect` was previously connected and for any reason connection is lost,\n * the state changed to `ConnState.Connecting` again and the connection process\n * starts again automatically.\n *\n * @example\n * ```javascript\n * if (conn.state === ConnState.Connecting) {\n * // display \"connecting\" message\n * }\n * ```\n */\nexport enum ConnState {\n /**\n * Disconnected state\n */\n Disconnected = 'disconnected',\n /**\n * Connecting state\n */\n Connecting = 'connecting',\n /**\n * Connected state\n */\n Connected = 'connected',\n}\n\n/**\n * Class of the {@link Message}\n */\nexport enum Klass {\n /**\n * Authentication request. Sent by server on client connection.\n */\n Authenticate = 'auth',\n /**\n * Authentication response. Sent by client as response\n * to authentication request.\n */\n AuthenticateResponse = 'authr',\n /**\n * Authentication acknowledgement. Sent by the server as confirmation\n * of successful authentication.\n */\n AuthenticateSuccess = 'authok',\n /**\n * Ping message is sent by server periodically as a keep-alive.\n * Ping message is only sent if no messages are sent for specific time\n * period, meaning if there are other messages sent frequently enough\n * then ping messages are not sent at all.\n */\n Ping = 'ping',\n /**\n * Subscribe to a channel. Sent by the client to subscribe to a channel\n */\n Subscribe = 'sub',\n /**\n * Unsubscribe from a channel. Sent by the client to unsubscribe from a channel\n */\n Unsububscribe = 'unsub',\n /**\n * End of cache. Sent by the server to notify that all messages are sent from\n * a channel cache\n */\n EndOfCache = 'eoc',\n /**\n * User login. Sent by client to supply verified user identity to the server.\n */\n Login = 'login',\n /**\n * User login success\n */\n LoginSuccess = 'login_ok',\n /**\n * User login failure\n */\n LoginFail = 'login_fail',\n /**\n * Averages counters. Client can submit a counter which is processed together\n * with other counters to determine the average of all counters within specific\n * demographics segment.\n */\n Counter = 'counter',\n /**\n * Client votes. Sents by a user to vote for a poll option\n */\n Vote = 'v',\n}\n\n/**\n * A Message to be sent to the Monterosa / Interaction Cloud\n */\nexport interface Message {\n /**\n * The channel id on which this message was received. It s required to be\n * {@link subscribe} to that channel in order to start receiving\n * messages\n */\n channel: string;\n /**\n * The class indicates the desired action to be performed or the result of\n * the action. E.g. in order to authenticate a developer should {@link send}\n * {@link Klass.AuthenticateResponse} klass message as a response on\n * a received {@link Klass.Authenticate} message\n */\n klass: Klass | string;\n /**\n * The timestamp (in seconds) when this message was sent\n */\n sent_at: number;\n /**\n * The message payload. Each peace of data is a `string`\n */\n body: string[];\n}\n","/**\n * @license\n * @monterosa/sdk-connect-kit\n *\n * Copyright © 2022 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Unsubscribe } from '@monterosa/sdk-util';\n\nimport { Connect, ConnState } from './types';\n\nexport function onState(\n conn: Connect,\n needle: ConnState,\n callback: Function,\n): Unsubscribe {\n const handler = (state: ConnState, ...rest: unknown[]) => {\n if (state === needle) {\n callback(...rest);\n }\n };\n\n conn.on('state', handler);\n\n return () => conn.off('state', handler);\n}\n","/* eslint class-methods-use-this: \"off\" */\n\n/**\n * @license\n * @monterosa/sdk-connect-kit\n *\n * Copyright © 2022 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport Enmasse from '@monterosa/sdk-enmasse-kit';\nimport { Emitter, setTimestamp } from '@monterosa/sdk-util';\n\nimport { Connect, ConnState, InitState, Message } from './types';\n\n/**\n * @internal\n */\nexport class ConnectImpl extends Emitter implements Connect {\n private static instance: ConnectImpl;\n public initState: InitState = InitState.NotInitialised;\n private initPromise: Promise<void> = Promise.resolve();\n private connectPromise: Promise<void> | null = null;\n\n private constructor() {\n super();\n\n Enmasse.bind(\n Enmasse.ON_STATE,\n (state: Enmasse.States, ...rest: unknown[]) => {\n if (state === Enmasse.STATE_CONNECTED) {\n const [timestamp] = rest as [number];\n\n setTimestamp(timestamp);\n }\n\n this.emit('state', ConnectImpl.toConnState(state), ...rest);\n },\n );\n\n Enmasse.bind(Enmasse.ON_MESSAGE, (message: Enmasse.Message) => {\n this.emit('message', <Message>message);\n });\n }\n\n get state() {\n return ConnectImpl.toConnState(Enmasse.getState());\n }\n\n get sessionId() {\n return Enmasse.getSessionId();\n }\n\n public static getInstance(): ConnectImpl {\n if (!ConnectImpl.instance) {\n ConnectImpl.instance = new ConnectImpl();\n }\n\n return ConnectImpl.instance;\n }\n\n static toConnState(state: Enmasse.States): ConnState {\n switch (state) {\n default:\n case Enmasse.STATE_DISCONNECTED:\n return ConnState.Disconnected;\n case Enmasse.STATE_CONNECTING:\n return ConnState.Connecting;\n case Enmasse.STATE_CONNECTED:\n return ConnState.Connected;\n }\n }\n\n async init(host: string): Promise<void> {\n if (\n this.initState === InitState.Initialising ||\n this.initState === InitState.Initialised\n ) {\n return this.initPromise;\n }\n\n this.initPromise = new Promise((resolve, reject) => {\n this.initState = InitState.Initialising;\n\n Enmasse.bind(Enmasse.ON_READY, () => {\n this.initState = InitState.Initialised;\n\n Enmasse.unbind(Enmasse.ON_READY);\n Enmasse.unbind(Enmasse.ON_ERROR);\n\n resolve();\n });\n\n Enmasse.bind(Enmasse.ON_ERROR, (err: string) => {\n this.initState = InitState.NotInitialised;\n\n Enmasse.unbind(Enmasse.ON_READY);\n Enmasse.unbind(Enmasse.ON_ERROR);\n\n reject(new Error(`Unable to initialise connect kit: ${err}`));\n });\n\n Enmasse.init({\n config: `https://${host}/config/enmasse.json`,\n });\n });\n\n return this.initPromise;\n }\n\n connect(): Promise<void> {\n if (this.initState !== InitState.Initialised) {\n return Promise.reject(new Error('must be initialised before connecting'));\n }\n\n if (this.state === ConnState.Connected) {\n return Promise.resolve();\n }\n\n if (this.state === ConnState.Connecting) {\n if (this.connectPromise) {\n return this.connectPromise;\n }\n\n // This should never happen - indicates a bug in state management\n return Promise.reject(\n new Error(\n 'BUG: Connection state is Connecting but connectPromise is null — ' +\n 'this indicates an internal inconsistency',\n ),\n );\n }\n\n this.connectPromise = new Promise((resolve, reject) => {\n const handler = (state: ConnState) => {\n switch (state) {\n case ConnState.Connected:\n Enmasse.unbind(Enmasse.ON_STATE, handler);\n\n this.connectPromise = null;\n\n resolve();\n break;\n case ConnState.Disconnected:\n Enmasse.unbind(Enmasse.ON_STATE, handler);\n\n this.connectPromise = null;\n\n reject(new Error('disconnected'));\n break;\n case ConnState.Connecting:\n // The Enmasse library may emit the \"connecting\" state multiple\n // times. This is expected and does not impact the connection\n // process, so we safely ignore it.\n break;\n }\n };\n\n Enmasse.bind(Enmasse.ON_STATE, handler);\n\n Enmasse.connect();\n });\n\n return this.connectPromise;\n }\n\n disconnect() {\n Enmasse.disconnect();\n }\n\n subscribe(channel: string): Promise<void> {\n return new Promise((resolve) => {\n const handler = (ch: string) => {\n if (ch !== channel) return;\n\n Enmasse.unbind(Enmasse.ON_EOC, handler);\n\n resolve();\n };\n\n Enmasse.bind(Enmasse.ON_EOC, handler);\n\n Enmasse.subscribe(channel);\n });\n }\n\n unsubscribe(channel: string): void {\n Enmasse.unsubscribe(channel);\n }\n\n send(channel: string, klass: string, body: (string | number)[]): void {\n Enmasse.send(channel, klass, body);\n }\n\n async login(\n userId: string,\n timestamp: number,\n signature: string,\n ): Promise<void> {\n return new Promise((resolve, reject) => {\n Enmasse.login(userId, timestamp, signature, resolve, () => {\n reject(new Error('Login failure'));\n });\n });\n }\n\n async logout(): Promise<void> {\n Enmasse.logout();\n\n return Promise.resolve();\n }\n\n delete() {}\n}\n","/**\n * @license\n * @monterosa/sdk-connect-kit\n *\n * Copyright © 2022-2024 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { getSdk } from '@monterosa/sdk-core';\nimport { memoizePromise, Unsubscribe } from '@monterosa/sdk-util';\n\nimport { Connect, ConnState, Message, Klass } from './types';\nimport { onState } from './helpers';\nimport { ConnectImpl } from './connect_impl';\n\n/**\n * @internal\n */\nconst getConnectMemoized = memoizePromise(\n async (host: string): Promise<Connect> => {\n const conn = ConnectImpl.getInstance();\n\n await conn.init(host);\n\n return conn;\n },\n (host: string): string => host,\n);\n\n/**\n * Returns the {@link Connect} instance associated with the provided\n * host. If host is not provided, it returns Connect instance for\n * the host associated with the default sdk.\n *\n * @param sdk - Monterosa SDK.\n */\nfunction getConnect(host?: string): Promise<Connect> {\n if (host === undefined) {\n const sdk = getSdk();\n\n host = sdk.options.host;\n }\n\n return getConnectMemoized(host);\n}\n\n/**\n * Adds an observer for when connection state changed to connected.\n *\n * @param conn - The {@link Connect} instance\n * @param callback - The callback triggered when {@link ConnState | state}\n * changed to connected\n */\nfunction onConnected(\n conn: Connect,\n callback: (timestamp: number) => void,\n): Unsubscribe {\n return onState(conn, ConnState.Connected, callback);\n}\n\n/**\n * Adds an observer for when connection state changed to connecting.\n *\n * @param conn - The {@link Connect} instance\n * @param callback - callback triggered on connecting state. Two parameters\n * are provided: `attempt` — sequential number of connect attempt and\n * `delay` - delay in seconds before the next attempt\n */\nfunction onConnecting(\n conn: Connect,\n callback: (attempt: number, delay: number) => void,\n): Unsubscribe {\n return onState(conn, ConnState.Connecting, callback);\n}\n\n/**\n * Adds an observer for when connection state changed to disconnected.\n *\n * @param conn - The {@link Connect} instance\n * @param callback - callback triggered on disconnected state\n */\nfunction onDisconnected(conn: Connect, callback: () => void): Unsubscribe {\n return onState(conn, ConnState.Disconnected, callback);\n}\n\n/**\n * Adds an observer for when a new message received\n *\n * @example\n * ```javascript\n * const unsubscribe = onMessage(conn, (message) => {\n * console.log(message.body);\n * });\n * ```\n *\n * @param conn - The {@link Connect} instance\n * @param callback - The callback function triggered on message receive\n */\nfunction onMessage(\n conn: Connect,\n callback: (message: Message) => void,\n): Unsubscribe {\n const handler = (message: Message) => {\n callback(message);\n };\n\n conn.on('message', handler);\n\n return () => conn.off('message', handler);\n}\n\n/**\n * Starts a connection process. If connect is successful a promise resolved by\n * and {@link onConnected} is triggered, otherwise a next attempt will be\n * automatically invoked and {@link onConnecting} is triggered.\n *\n * SDK connects automatically when its created. Connection procedure can be\n * aborted by calling {@link disconnect} function and the promise is rejected.\n *\n * @example\n * ```javascript\n * try {\n * const conn = await getConnect();\n *\n * await connect(conn);\n *\n * console.log('connected!');\n * } catch (err) {\n * console.log(err)\n * }\n * ```\n *\n * State of the connection can be handled separately\n *\n * @example\n * ```javascript\n * onConnected(() => console.log('connected'));\n *\n * onConnecting((attempt, delay) => console.log('connecting'));\n *\n * onDisconnected(() => console.log('disconnected'));\n * ```\n *\n * @param conn - The {@link Connect} instance\n * @param host - Interaction Cloud Studio host.\n * Can be found in Project Settings in API tab\n */\nfunction connect(conn: Connect): Promise<void> {\n // No need to memoize this, it's already memoized\n // in the ConnectImpl class implementation\n return conn.connect();\n}\n\n/**\n * Disconnect from the server and triggers {@link onDisconnected}\n *\n * @param conn - The {@link Connect} instance\n */\nfunction disconnect(conn: Connect): void {\n conn.disconnect();\n}\n\n/**\n * @internal\n */\nconst subscribeMemoized = memoizePromise(\n async (conn: Connect, channel: string): Promise<void> =>\n conn.subscribe(channel),\n (conn: Connect, channel: string): string => channel,\n);\n\n/**\n * Subscribe to the server channel.\n *\n * Any message published to a channel is {@link onMessage | received}\n * only by subscribers to that channel. The sdk out of the box handles\n * all required subscriptions internally and {@link onMessage | handles messages}\n * so there is no need in to subscribe by developers.\n *\n * To stop receiving messages on a channel {@link unsubscribe} should be called.\n *\n * @param conn - The {@link Connect} instance\n * @param channel - Channel name\n */\nfunction subscribe(conn: Connect, channel: string): Promise<void> {\n return subscribeMemoized(conn, channel);\n}\n\n/**\n * Unsubscribe from the server channel.\n *\n * Removes subscription to the channel so that recipient no longer receive\n * messages from that channel.\n *\n * @param conn - The {@link Connect} instance\n * @param channel - Channel name\n */\nfunction unsubscribe(conn: Connect, channel: string): void {\n conn.unsubscribe(channel);\n}\n\n/**\n * Send message to the server.\n *\n * The sdk out of the box provides more high level functions that uses\n * this function to send data to the server. Though a developer still can\n * use it if he knows a message protocol (klass and body) and a channel\n * that expect the message.\n *\n * @param conn - The Connect instance\n * @param channel - Channel name. Only {@link subscribe | subscribers}\n * to that channel can send messages.\n * @param klass - Message class name.\n * @param body - Message payload\n */\nfunction send(\n conn: Connect,\n channel: string,\n klass: Klass | string,\n body: (string | number)[],\n): void {\n conn.send(channel, klass, body);\n}\n\nasync function login(\n conn: Connect,\n userId: string,\n timestamp: number,\n signature: string,\n): Promise<void> {\n const result = await conn.login(userId, timestamp, signature);\n\n return result;\n}\n\nasync function logout(conn: Connect): Promise<void> {\n const result = await conn.logout();\n\n return result;\n}\n\nexport {\n onConnected,\n onConnecting,\n onDisconnected,\n onMessage,\n disconnect,\n unsubscribe,\n send,\n getConnect,\n getConnectMemoized,\n connect,\n subscribe,\n subscribeMemoized,\n login,\n logout,\n};\n"],"names":["InitState","ConnState","Klass","Enmasse","setTimestamp","Emitter","memoizePromise","getSdk"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAOG;AAKH;;AAEG;AACI,IAAM,QAAQ,GAAG,UAAU;AAwDlC;;AAEG;AACSA,2BAIX;AAJD,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,gBAAA,CAAA,GAAA,iBAAkC,CAAA;AAClC,IAAA,SAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;AAC3B,IAAA,SAAA,CAAA,cAAA,CAAA,GAAA,cAA6B,CAAA;AAC/B,CAAC,EAJWA,iBAAS,KAATA,iBAAS,GAIpB,EAAA,CAAA,CAAA,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACSC,2BAaX;AAbD,CAAA,UAAY,SAAS,EAAA;AACnB;;AAEG;AACH,IAAA,SAAA,CAAA,cAAA,CAAA,GAAA,cAA6B,CAAA;AAC7B;;AAEG;AACH,IAAA,SAAA,CAAA,YAAA,CAAA,GAAA,YAAyB,CAAA;AACzB;;AAEG;AACH,IAAA,SAAA,CAAA,WAAA,CAAA,GAAA,WAAuB,CAAA;AACzB,CAAC,EAbWA,iBAA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IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA,CAAA;;AAAvD,oBAAA,MAAM,GAAG,EAA8C,CAAA,IAAA,EAAA,CAAA;AAE7D,oBAAA,OAAA,CAAA,CAAA,aAAO,MAAM,CAAC,CAAA;;;;AACf,CAAA;AAED,SAAe,MAAM,CAAC,IAAa,EAAA;;;;;AAClB,gBAAA,KAAA,CAAA,EAAA,OAAA,CAAA,CAAA,YAAM,IAAI,CAAC,MAAM,EAAE,CAAA,CAAA;;AAA5B,oBAAA,MAAM,GAAG,EAAmB,CAAA,IAAA,EAAA,CAAA;AAElC,oBAAA,OAAA,CAAA,CAAA,aAAO,MAAM,CAAC,CAAA;;;;AACf;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/types.ts","../src/helpers.ts","../src/connect_impl.ts","../src/connect.ts"],"sourcesContent":["/**\n * @license\n * @monterosa/sdk-connect-kit\n *\n * Copyright © 2022 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { MonterosaKit } from '@monterosa/sdk-core';\nimport { Emitter } from '@monterosa/sdk-util';\n\n/**\n * @internal\n */\nexport const KIT_NAME = 'connect';\n\n/**\n * Interface representing Connect kit.\n */\nexport interface Connect extends MonterosaKit, Emitter {\n /**\n * Connection state\n */\n state: ConnState;\n\n /**\n * Session ID\n */\n sessionId: string | null;\n\n /**\n * @internal\n */\n initState: InitState;\n\n /**\n * @internal\n */\n init(host: string): Promise<void>;\n\n /**\n * @internal\n */\n connect(): Promise<void>;\n\n /**\n * @internal\n */\n disconnect(): void;\n\n /**\n * @internal\n */\n subscribe(channel: string): Promise<void>;\n\n /**\n * @internal\n */\n unsubscribe(channel: string): void;\n\n /**\n * @internal\n */\n send(channel: string, klass: string, body: (string | number)[]): void;\n\n login(userId: string, timestamp: number, signature: string): Promise<void>;\n\n logout(): void;\n}\n\n/**\n * @internal\n */\nexport enum InitState {\n NotInitialised = 'not_initialised',\n Initialised = 'initialised',\n Initialising = 'initialising',\n}\n\n/**\n * A list of possible connection states. Can be used with\n * {@link Connect.state} to determine the current state.\n *\n * By default {@link Connect} is in the disconnected state.\n * When {@link connect} invoked `Connect` state switches to\n * `ConnState.Connecting` and connection is maintained permanently until\n * {@link disconnect} method is invoked. If connection was unsucessful,\n * a new attempt will start after a short delay and `ConnState.connecting`\n * is triggered. Delays between attempts increased based on this sequence:\n * 0, 3, 5, 10, 20, 30, 45, 60 where 60 seconds is the max.\n *\n * If `Connect` was previously connected and for any reason connection is lost,\n * the state changed to `ConnState.Connecting` again and the connection process\n * starts again automatically.\n *\n * @example\n * ```javascript\n * if (conn.state === ConnState.Connecting) {\n * // display \"connecting\" message\n * }\n * ```\n */\nexport enum ConnState {\n /**\n * Disconnected state\n */\n Disconnected = 'disconnected',\n /**\n * Connecting state\n */\n Connecting = 'connecting',\n /**\n * Connected state\n */\n Connected = 'connected',\n}\n\n/**\n * Class of the {@link Message}\n */\nexport enum Klass {\n /**\n * Authentication request. Sent by server on client connection.\n */\n Authenticate = 'auth',\n /**\n * Authentication response. Sent by client as response\n * to authentication request.\n */\n AuthenticateResponse = 'authr',\n /**\n * Authentication acknowledgement. Sent by the server as confirmation\n * of successful authentication.\n */\n AuthenticateSuccess = 'authok',\n /**\n * Ping message is sent by server periodically as a keep-alive.\n * Ping message is only sent if no messages are sent for specific time\n * period, meaning if there are other messages sent frequently enough\n * then ping messages are not sent at all.\n */\n Ping = 'ping',\n /**\n * Subscribe to a channel. Sent by the client to subscribe to a channel\n */\n Subscribe = 'sub',\n /**\n * Unsubscribe from a channel. Sent by the client to unsubscribe from a channel\n */\n Unsububscribe = 'unsub',\n /**\n * End of cache. Sent by the server to notify that all messages are sent from\n * a channel cache\n */\n EndOfCache = 'eoc',\n /**\n * User login. Sent by client to supply verified user identity to the server.\n */\n Login = 'login',\n /**\n * User login success\n */\n LoginSuccess = 'login_ok',\n /**\n * User login failure\n */\n LoginFail = 'login_fail',\n /**\n * Averages counters. Client can submit a counter which is processed together\n * with other counters to determine the average of all counters within specific\n * demographics segment.\n */\n Counter = 'counter',\n /**\n * Client votes. Sents by a user to vote for a poll option\n */\n Vote = 'v',\n}\n\n/**\n * A Message to be sent to the Monterosa / Interaction Cloud\n */\nexport interface Message {\n /**\n * The channel id on which this message was received. It s required to be\n * {@link subscribe} to that channel in order to start receiving\n * messages\n */\n channel: string;\n /**\n * The class indicates the desired action to be performed or the result of\n * the action. E.g. in order to authenticate a developer should {@link send}\n * {@link Klass.AuthenticateResponse} klass message as a response on\n * a received {@link Klass.Authenticate} message\n */\n klass: Klass | string;\n /**\n * The timestamp (in seconds) when this message was sent\n */\n sent_at: number;\n /**\n * The message payload. Each peace of data is a `string`\n */\n body: string[];\n}\n","/**\n * @license\n * @monterosa/sdk-connect-kit\n *\n * Copyright © 2022 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { Unsubscribe } from '@monterosa/sdk-util';\n\nimport { Connect, ConnState } from './types';\n\nexport function onState(\n conn: Connect,\n needle: ConnState,\n callback: Function,\n): Unsubscribe {\n const handler = (state: ConnState, ...rest: unknown[]) => {\n if (state === needle) {\n callback(...rest);\n }\n };\n\n conn.on('state', handler);\n\n return () => conn.off('state', handler);\n}\n","/* eslint class-methods-use-this: \"off\" */\n\n/**\n * @license\n * @monterosa/sdk-connect-kit\n *\n * Copyright © 2022 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport Enmasse from '@monterosa/sdk-enmasse-kit';\nimport { Emitter, setTimestamp } from '@monterosa/sdk-util';\n\nimport { Connect, ConnState, InitState, Message } from './types';\n\n/**\n * @internal\n */\nexport class ConnectImpl extends Emitter implements Connect {\n private static instance: ConnectImpl;\n public initState: InitState = InitState.NotInitialised;\n private initPromise: Promise<void> = Promise.resolve();\n private connectPromise: Promise<void> | null = null;\n\n private constructor() {\n super();\n\n Enmasse.bind(\n Enmasse.ON_STATE,\n (state: Enmasse.States, ...rest: unknown[]) => {\n if (state === Enmasse.STATE_CONNECTED) {\n const [timestamp] = rest as [number];\n\n setTimestamp(timestamp);\n }\n\n this.emit('state', ConnectImpl.toConnState(state), ...rest);\n },\n );\n\n Enmasse.bind(Enmasse.ON_MESSAGE, (message: Enmasse.Message) => {\n this.emit('message', <Message>message);\n });\n }\n\n get state() {\n return ConnectImpl.toConnState(Enmasse.getState());\n }\n\n get sessionId() {\n return Enmasse.getSessionId();\n }\n\n public static getInstance(): ConnectImpl {\n if (!ConnectImpl.instance) {\n ConnectImpl.instance = new ConnectImpl();\n }\n\n return ConnectImpl.instance;\n }\n\n static toConnState(state: Enmasse.States): ConnState {\n switch (state) {\n default:\n case Enmasse.STATE_DISCONNECTED:\n return ConnState.Disconnected;\n case Enmasse.STATE_CONNECTING:\n return ConnState.Connecting;\n case Enmasse.STATE_CONNECTED:\n return ConnState.Connected;\n }\n }\n\n async init(host: string): Promise<void> {\n if (\n this.initState === InitState.Initialising ||\n this.initState === InitState.Initialised\n ) {\n return this.initPromise;\n }\n\n this.initPromise = new Promise((resolve, reject) => {\n this.initState = InitState.Initialising;\n\n Enmasse.bind(Enmasse.ON_READY, () => {\n this.initState = InitState.Initialised;\n\n Enmasse.unbind(Enmasse.ON_READY);\n Enmasse.unbind(Enmasse.ON_ERROR);\n\n resolve();\n });\n\n Enmasse.bind(Enmasse.ON_ERROR, (err: string) => {\n this.initState = InitState.NotInitialised;\n\n Enmasse.unbind(Enmasse.ON_READY);\n Enmasse.unbind(Enmasse.ON_ERROR);\n\n reject(new Error(`Unable to initialise connect kit: ${err}`));\n });\n\n Enmasse.init({\n config: `https://${host}/config/enmasse.json`,\n });\n });\n\n return this.initPromise;\n }\n\n connect(): Promise<void> {\n if (this.initState !== InitState.Initialised) {\n return Promise.reject(new Error('must be initialised before connecting'));\n }\n\n if (this.state === ConnState.Connected) {\n return Promise.resolve();\n }\n\n if (this.state === ConnState.Connecting) {\n if (this.connectPromise) {\n return this.connectPromise;\n }\n\n // This should never happen - indicates a bug in state management\n return Promise.reject(\n new Error(\n 'BUG: Connection state is Connecting but connectPromise is null — ' +\n 'this indicates an internal inconsistency',\n ),\n );\n }\n\n this.connectPromise = new Promise((resolve, reject) => {\n const handler = (state: ConnState) => {\n switch (state) {\n case ConnState.Connected:\n Enmasse.unbind(Enmasse.ON_STATE, handler);\n\n this.connectPromise = null;\n\n resolve();\n break;\n case ConnState.Disconnected:\n Enmasse.unbind(Enmasse.ON_STATE, handler);\n\n this.connectPromise = null;\n\n reject(new Error('disconnected'));\n break;\n case ConnState.Connecting:\n // The Enmasse library may emit the \"connecting\" state multiple\n // times. This is expected and does not impact the connection\n // process, so we safely ignore it.\n break;\n }\n };\n\n Enmasse.bind(Enmasse.ON_STATE, handler);\n\n Enmasse.connect();\n });\n\n return this.connectPromise;\n }\n\n disconnect() {\n Enmasse.disconnect();\n }\n\n subscribe(channel: string): Promise<void> {\n return new Promise((resolve) => {\n const handler = (ch: string) => {\n if (ch !== channel) return;\n\n Enmasse.unbind(Enmasse.ON_EOC, handler);\n\n resolve();\n };\n\n Enmasse.bind(Enmasse.ON_EOC, handler);\n\n Enmasse.subscribe(channel);\n });\n }\n\n unsubscribe(channel: string): void {\n Enmasse.unsubscribe(channel);\n }\n\n send(channel: string, klass: string, body: (string | number)[]): void {\n Enmasse.send(channel, klass, body);\n }\n\n async login(\n userId: string,\n timestamp: number,\n signature: string,\n ): Promise<void> {\n return new Promise((resolve, reject) => {\n Enmasse.login(userId, timestamp, signature, resolve, () => {\n reject(new Error('Login failure'));\n });\n });\n }\n\n async logout(): Promise<void> {\n Enmasse.logout();\n\n return Promise.resolve();\n }\n\n delete() {}\n}\n","/**\n * @license\n * @monterosa/sdk-connect-kit\n *\n * Copyright © 2022-2024 Monterosa Productions Limited. All rights reserved.\n *\n * More details on the license can be found at https://www.monterosa.co/sdk/license\n */\n\nimport { getSdk } from '@monterosa/sdk-core';\nimport { memoizePromise, Unsubscribe } from '@monterosa/sdk-util';\n\nimport { Connect, ConnState, Message, Klass } from './types';\nimport { onState } from './helpers';\nimport { ConnectImpl } from './connect_impl';\n\n/**\n * @internal\n */\nconst getConnectMemoized = memoizePromise(\n async (host: string): Promise<Connect> => {\n const conn = ConnectImpl.getInstance();\n\n await conn.init(host);\n\n return conn;\n },\n (host: string): string => host,\n);\n\n/**\n * Returns the {@link Connect} instance associated with the provided\n * host. If host is not provided, it returns Connect instance for\n * the host associated with the default sdk.\n *\n * @param sdk - Monterosa SDK.\n */\nfunction getConnect(host?: string): Promise<Connect> {\n if (host === undefined) {\n const sdk = getSdk();\n\n host = sdk.options.host;\n }\n\n return getConnectMemoized(host);\n}\n\n/**\n * Adds an observer for when connection state changed to connected.\n *\n * @param conn - The {@link Connect} instance\n * @param callback - The callback triggered when {@link ConnState | state}\n * changed to connected\n */\nfunction onConnected(\n conn: Connect,\n callback: (timestamp: number) => void,\n): Unsubscribe {\n return onState(conn, ConnState.Connected, callback);\n}\n\n/**\n * Adds an observer for when connection state changed to connecting.\n *\n * @param conn - The {@link Connect} instance\n * @param callback - callback triggered on connecting state. Two parameters\n * are provided: `attempt` — sequential number of connect attempt and\n * `delay` - delay in seconds before the next attempt\n */\nfunction onConnecting(\n conn: Connect,\n callback: (attempt: number, delay: number) => void,\n): Unsubscribe {\n return onState(conn, ConnState.Connecting, callback);\n}\n\n/**\n * Adds an observer for when connection state changed to disconnected.\n *\n * @param conn - The {@link Connect} instance\n * @param callback - callback triggered on disconnected state\n */\nfunction onDisconnected(conn: Connect, callback: () => void): Unsubscribe {\n return onState(conn, ConnState.Disconnected, callback);\n}\n\n/**\n * Adds an observer for when a new message received\n *\n * @example\n * ```javascript\n * const unsubscribe = onMessage(conn, (message) => {\n * console.log(message.body);\n * });\n * ```\n *\n * @param conn - The {@link Connect} instance\n * @param callback - The callback function triggered on message receive\n */\nfunction onMessage(\n conn: Connect,\n callback: (message: Message) => void,\n): Unsubscribe {\n const handler = (message: Message) => {\n callback(message);\n };\n\n conn.on('message', handler);\n\n return () => conn.off('message', handler);\n}\n\n/**\n * Starts a connection process. If connect is successful a promise resolved by\n * and {@link onConnected} is triggered, otherwise a next attempt will be\n * automatically invoked and {@link onConnecting} is triggered.\n *\n * SDK connects automatically when its created. Connection procedure can be\n * aborted by calling {@link disconnect} function and the promise is rejected.\n *\n * @example\n * ```javascript\n * try {\n * const conn = await getConnect();\n *\n * await connect(conn);\n *\n * console.log('connected!');\n * } catch (err) {\n * console.log(err)\n * }\n * ```\n *\n * State of the connection can be handled separately\n *\n * @example\n * ```javascript\n * onConnected(() => console.log('connected'));\n *\n * onConnecting((attempt, delay) => console.log('connecting'));\n *\n * onDisconnected(() => console.log('disconnected'));\n * ```\n *\n * @param conn - The {@link Connect} instance\n * @param host - Interaction Cloud Studio host.\n * Can be found in Project Settings in API tab\n */\nfunction connect(conn: Connect): Promise<void> {\n // No need to memoize this, it's already memoized\n // in the ConnectImpl class implementation\n return conn.connect();\n}\n\n/**\n * Disconnect from the server and triggers {@link onDisconnected}\n *\n * @param conn - The {@link Connect} instance\n */\nfunction disconnect(conn: Connect): void {\n conn.disconnect();\n}\n\n/**\n * @internal\n */\nconst subscribeMemoized = memoizePromise(\n async (conn: Connect, channel: string): Promise<void> =>\n conn.subscribe(channel),\n (conn: Connect, channel: string): string => channel,\n);\n\n/**\n * Subscribe to the server channel.\n *\n * Any message published to a channel is {@link onMessage | received}\n * only by subscribers to that channel. The sdk out of the box handles\n * all required subscriptions internally and {@link onMessage | handles messages}\n * so there is no need in to subscribe by developers.\n *\n * To stop receiving messages on a channel {@link unsubscribe} should be called.\n *\n * @param conn - The {@link Connect} instance\n * @param channel - Channel name\n */\nfunction subscribe(conn: Connect, channel: string): Promise<void> {\n return subscribeMemoized(conn, channel);\n}\n\n/**\n * Unsubscribe from the server channel.\n *\n * Removes subscription to the channel so that recipient no longer receive\n * messages from that channel.\n *\n * @param conn - The {@link Connect} instance\n * @param channel - Channel name\n */\nfunction unsubscribe(conn: Connect, channel: string): void {\n conn.unsubscribe(channel);\n}\n\n/**\n * Send message to the server.\n *\n * The sdk out of the box provides more high level functions that uses\n * this function to send data to the server. Though a developer still can\n * use it if he knows a message protocol (klass and body) and a channel\n * that expect the message.\n *\n * @param conn - The Connect instance\n * @param channel - Channel name. Only {@link subscribe | subscribers}\n * to that channel can send messages.\n * @param klass - Message class name.\n * @param body - Message payload\n */\nfunction send(\n conn: Connect,\n channel: string,\n klass: Klass | string,\n body: (string | number)[],\n): void {\n conn.send(channel, klass, body);\n}\n\nasync function login(\n conn: Connect,\n userId: string,\n timestamp: number,\n signature: string,\n): Promise<void> {\n const result = await conn.login(userId, timestamp, signature);\n\n return result;\n}\n\nasync function logout(conn: Connect): Promise<void> {\n const result = await conn.logout();\n\n return result;\n}\n\nexport {\n onConnected,\n onConnecting,\n onDisconnected,\n onMessage,\n disconnect,\n unsubscribe,\n send,\n getConnect,\n getConnectMemoized,\n connect,\n subscribe,\n subscribeMemoized,\n login,\n logout,\n};\n"],"names":[],"mappings":";;;;AAAA;;;;;;;AAOG;AAKH;;AAEG;AACI,MAAM,QAAQ,GAAG,UAAU;AAwDlC;;AAEG;IACS,UAIX;AAJD,CAAA,UAAY,SAAS,EAAA;AACnB,IAAA,SAAA,CAAA,gBAAA,CAAA,GAAA,iBAAkC,CAAA;AAClC,IAAA,SAAA,CAAA,aAAA,CAAA,GAAA,aAA2B,CAAA;AAC3B,IAAA,SAAA,CAAA,cAAA,CAAA,GAAA,cAA6B,CAAA;AAC/B,CAAC,EAJW,SAAS,KAAT,SAAS,GAIpB,EAAA,CAAA,CAAA,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;AAsBG;IACS,UAaX;AAbD,CAAA,UAAY,SAAS,EAAA;AACnB;;AAEG;AACH,IAAA,SAAA,CAAA,cAAA,CAAA,GAAA,cAA6B,CAAA;AAC7B;;AAE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