mqtt 4.2.5 → 4.3.0
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/CHANGELOG.md +63 -0
- package/README.md +108 -49
- package/bin/mqtt.js +3 -3
- package/bin/pub.js +12 -12
- package/bin/sub.js +6 -6
- package/dist/mqtt.js +13015 -5878
- package/dist/mqtt.min.js +1 -1
- package/lib/client.js +569 -260
- package/lib/connect/ali.js +14 -14
- package/lib/connect/index.js +18 -30
- package/lib/connect/tcp.js +4 -5
- package/lib/connect/tls.js +8 -5
- package/lib/connect/ws.js +16 -15
- package/lib/connect/wx.js +11 -13
- package/lib/default-message-id-provider.js +69 -0
- package/lib/store.js +9 -9
- package/lib/topic-alias-recv.js +47 -0
- package/lib/topic-alias-send.js +93 -0
- package/lib/unique-message-id-provider.js +65 -0
- package/lib/validations.js +3 -3
- package/mqtt.js +7 -3
- package/package.json +26 -10
- package/types/index.d.ts +4 -1
- package/types/lib/client-options.d.ts +24 -11
- package/types/lib/client.d.ts +33 -4
- package/types/lib/default-message-id-provider.d.ts +49 -0
- package/types/lib/message-id-provider.d.ts +40 -0
- package/types/lib/unique-message-id-provider.d.ts +48 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const NumberAllocator = require('number-allocator').NumberAllocator
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* UniqueMessageAllocator constructor
|
|
7
|
+
* @constructor
|
|
8
|
+
*/
|
|
9
|
+
function UniqueMessageIdProvider () {
|
|
10
|
+
if (!(this instanceof UniqueMessageIdProvider)) {
|
|
11
|
+
return new UniqueMessageIdProvider()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
this.numberAllocator = new NumberAllocator(1, 65535)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* allocate
|
|
19
|
+
*
|
|
20
|
+
* Get the next messageId.
|
|
21
|
+
* @return if messageId is fully allocated then return null,
|
|
22
|
+
* otherwise return the smallest usable unsigned int messageId.
|
|
23
|
+
*/
|
|
24
|
+
UniqueMessageIdProvider.prototype.allocate = function () {
|
|
25
|
+
this.lastId = this.numberAllocator.alloc()
|
|
26
|
+
return this.lastId
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* getLastAllocated
|
|
31
|
+
* Get the last allocated messageId.
|
|
32
|
+
* @return unsigned int
|
|
33
|
+
*/
|
|
34
|
+
UniqueMessageIdProvider.prototype.getLastAllocated = function () {
|
|
35
|
+
return this.lastId
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* register
|
|
40
|
+
* Register messageId. If success return true, otherwise return false.
|
|
41
|
+
* @param { unsigned int } - messageId to register,
|
|
42
|
+
* @return boolean
|
|
43
|
+
*/
|
|
44
|
+
UniqueMessageIdProvider.prototype.register = function (messageId) {
|
|
45
|
+
return this.numberAllocator.use(messageId)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* deallocate
|
|
50
|
+
* Deallocate messageId.
|
|
51
|
+
* @param { unsigned int } - messageId to deallocate,
|
|
52
|
+
*/
|
|
53
|
+
UniqueMessageIdProvider.prototype.deallocate = function (messageId) {
|
|
54
|
+
this.numberAllocator.free(messageId)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* clear
|
|
59
|
+
* Deallocate all messageIds.
|
|
60
|
+
*/
|
|
61
|
+
UniqueMessageIdProvider.prototype.clear = function () {
|
|
62
|
+
this.numberAllocator.clear()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = UniqueMessageIdProvider
|
package/lib/validations.js
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
* @returns {Boolean} If the topic is valid, returns true. Otherwise, returns false.
|
|
11
11
|
*/
|
|
12
12
|
function validateTopic (topic) {
|
|
13
|
-
|
|
13
|
+
const parts = topic.split('/')
|
|
14
14
|
|
|
15
|
-
for (
|
|
15
|
+
for (let i = 0; i < parts.length; i++) {
|
|
16
16
|
if (parts[i] === '+') {
|
|
17
17
|
continue
|
|
18
18
|
}
|
|
@@ -39,7 +39,7 @@ function validateTopics (topics) {
|
|
|
39
39
|
if (topics.length === 0) {
|
|
40
40
|
return 'empty_topic_list'
|
|
41
41
|
}
|
|
42
|
-
for (
|
|
42
|
+
for (let i = 0; i < topics.length; i++) {
|
|
43
43
|
if (!validateTopic(topics[i])) {
|
|
44
44
|
return topics[i]
|
|
45
45
|
}
|
package/mqtt.js
CHANGED
|
@@ -5,9 +5,11 @@
|
|
|
5
5
|
* See LICENSE for more information
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const MqttClient = require('./lib/client')
|
|
9
|
+
const connect = require('./lib/connect')
|
|
10
|
+
const Store = require('./lib/store')
|
|
11
|
+
const DefaultMessageIdProvider = require('./lib/default-message-id-provider')
|
|
12
|
+
const UniqueMessageIdProvider = require('./lib/unique-message-id-provider')
|
|
11
13
|
|
|
12
14
|
module.exports.connect = connect
|
|
13
15
|
|
|
@@ -15,3 +17,5 @@ module.exports.connect = connect
|
|
|
15
17
|
module.exports.MqttClient = MqttClient
|
|
16
18
|
module.exports.Client = MqttClient
|
|
17
19
|
module.exports.Store = Store
|
|
20
|
+
module.exports.DefaultMessageIdProvider = DefaultMessageIdProvider
|
|
21
|
+
module.exports.UniqueMessageIdProvider = UniqueMessageIdProvider
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mqtt",
|
|
3
3
|
"description": "A library for the MQTT protocol",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.3.0",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Adam Rudd <adamvrr@gmail.com>",
|
|
7
7
|
"Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"main": "mqtt.js",
|
|
23
23
|
"types": "types/index.d.ts",
|
|
24
24
|
"scripts": {
|
|
25
|
-
"test": "node_modules/.bin/nyc --reporter=lcov --reporter=text ./node_modules/mocha/bin/_mocha",
|
|
25
|
+
"test": "node_modules/.bin/nyc --reporter=lcov --reporter=text ./node_modules/mocha/bin/_mocha --exit",
|
|
26
26
|
"pretest": "standard | snazzy",
|
|
27
27
|
"tslint": "tslint types/**/*.d.ts",
|
|
28
28
|
"typescript-compile-test": "tsc -p test/typescript/tsconfig.json",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"ci": "npm run tslint && npm run typescript-compile-test && npm run test && codecov"
|
|
36
36
|
},
|
|
37
37
|
"pre-commit": [
|
|
38
|
-
"
|
|
38
|
+
"pretest",
|
|
39
39
|
"tslint"
|
|
40
40
|
],
|
|
41
41
|
"bin": {
|
|
@@ -62,31 +62,37 @@
|
|
|
62
62
|
"net": false
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
+
"babel-eslint": "^10.1.0",
|
|
66
|
+
"collections": "^5.1.12",
|
|
65
67
|
"commist": "^1.0.0",
|
|
66
68
|
"concat-stream": "^2.0.0",
|
|
67
69
|
"debug": "^4.1.1",
|
|
68
|
-
"
|
|
70
|
+
"duplexify": "^4.1.1",
|
|
71
|
+
"help-me": "^3.0.0",
|
|
69
72
|
"inherits": "^2.0.3",
|
|
70
73
|
"minimist": "^1.2.5",
|
|
71
|
-
"mqtt-packet": "^6.
|
|
74
|
+
"mqtt-packet": "^6.8.0",
|
|
75
|
+
"number-allocator": "^1.0.7",
|
|
72
76
|
"pump": "^3.0.0",
|
|
73
77
|
"readable-stream": "^3.6.0",
|
|
74
78
|
"reinterval": "^1.1.0",
|
|
79
|
+
"rfdc": "^1.3.0",
|
|
75
80
|
"split2": "^3.1.0",
|
|
76
|
-
"ws": "^7.
|
|
81
|
+
"ws": "^7.5.5",
|
|
77
82
|
"xtend": "^4.0.2"
|
|
78
83
|
},
|
|
79
84
|
"devDependencies": {
|
|
80
85
|
"@types/node": "^10.0.0",
|
|
81
|
-
"
|
|
86
|
+
"@types/ws": "^7.4.7",
|
|
87
|
+
"aedes": "^0.42.5",
|
|
88
|
+
"airtap": "^4.0.4",
|
|
82
89
|
"browserify": "^16.5.0",
|
|
83
90
|
"chai": "^4.2.0",
|
|
84
91
|
"codecov": "^3.0.4",
|
|
85
92
|
"end-of-stream": "^1.4.1",
|
|
86
93
|
"global": "^4.3.2",
|
|
87
|
-
"aedes": "^0.42.5",
|
|
88
94
|
"mkdirp": "^0.5.1",
|
|
89
|
-
"mocha": "^
|
|
95
|
+
"mocha": "^9.1.3",
|
|
90
96
|
"mqtt-connection": "^4.0.0",
|
|
91
97
|
"nyc": "^15.0.1",
|
|
92
98
|
"pre-commit": "^1.2.2",
|
|
@@ -94,15 +100,25 @@
|
|
|
94
100
|
"should": "^13.2.1",
|
|
95
101
|
"sinon": "^9.0.0",
|
|
96
102
|
"snazzy": "^8.0.0",
|
|
97
|
-
"standard": "^
|
|
103
|
+
"standard": "^16.0.4",
|
|
98
104
|
"tslint": "^5.11.0",
|
|
99
105
|
"tslint-config-standard": "^8.0.1",
|
|
100
106
|
"typescript": "^3.2.2",
|
|
101
107
|
"uglify-es": "^3.3.9"
|
|
102
108
|
},
|
|
103
109
|
"standard": {
|
|
110
|
+
"parser": "babel-eslint",
|
|
104
111
|
"env": [
|
|
105
112
|
"mocha"
|
|
113
|
+
],
|
|
114
|
+
"globals": [
|
|
115
|
+
"expect",
|
|
116
|
+
"test",
|
|
117
|
+
"describe",
|
|
118
|
+
"it",
|
|
119
|
+
"beforeEach",
|
|
120
|
+
"beforeAll",
|
|
121
|
+
"afterAll"
|
|
106
122
|
]
|
|
107
123
|
}
|
|
108
124
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -23,5 +23,8 @@ export {
|
|
|
23
23
|
IPingreqPacket,
|
|
24
24
|
IPingrespPacket,
|
|
25
25
|
IDisconnectPacket,
|
|
26
|
-
Packet
|
|
26
|
+
Packet,
|
|
27
|
+
UserProperties
|
|
27
28
|
} from 'mqtt-packet'
|
|
29
|
+
export { IMessageIdProvider } from './lib/message-id-provider'
|
|
30
|
+
export { UniqueMessageIdProvider } from './lib/unique-message-id-provider'
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { MqttClient } from './client'
|
|
2
2
|
import { Store } from './store'
|
|
3
|
-
import {
|
|
3
|
+
import { ClientOptions } from 'ws'
|
|
4
|
+
import { ClientRequestArgs } from 'http'
|
|
5
|
+
import { QoS, UserProperties } from 'mqtt-packet'
|
|
6
|
+
import { IMessageIdProvider } from './message-id-provider'
|
|
4
7
|
|
|
5
8
|
export declare type StorePutCallback = () => void
|
|
6
9
|
|
|
@@ -11,9 +14,7 @@ export interface IClientOptions extends ISecureClientOptions {
|
|
|
11
14
|
path?: string
|
|
12
15
|
protocol?: 'wss' | 'ws' | 'mqtt' | 'mqtts' | 'tcp' | 'ssl' | 'wx' | 'wxs'
|
|
13
16
|
|
|
14
|
-
wsOptions?:
|
|
15
|
-
[x: string]: any
|
|
16
|
-
}
|
|
17
|
+
wsOptions?: ClientOptions | ClientRequestArgs
|
|
17
18
|
/**
|
|
18
19
|
* 10 seconds, set to 0 to disable
|
|
19
20
|
*/
|
|
@@ -99,7 +100,7 @@ export interface IClientOptions extends ISecureClientOptions {
|
|
|
99
100
|
contentType?: string,
|
|
100
101
|
responseTopic?: string,
|
|
101
102
|
correlationData?: Buffer,
|
|
102
|
-
userProperties?:
|
|
103
|
+
userProperties?: UserProperties
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
transformWsUrl?: (url: string, options: IClientOptions, client: MqttClient) => string,
|
|
@@ -110,10 +111,11 @@ export interface IClientOptions extends ISecureClientOptions {
|
|
|
110
111
|
topicAliasMaximum?: number,
|
|
111
112
|
requestResponseInformation?: boolean,
|
|
112
113
|
requestProblemInformation?: boolean,
|
|
113
|
-
userProperties?:
|
|
114
|
+
userProperties?: UserProperties,
|
|
114
115
|
authenticationMethod?: string,
|
|
115
116
|
authenticationData?: Buffer
|
|
116
|
-
}
|
|
117
|
+
},
|
|
118
|
+
messageIdProvider?: IMessageIdProvider
|
|
117
119
|
}
|
|
118
120
|
export interface ISecureClientOptions {
|
|
119
121
|
/**
|
|
@@ -129,6 +131,10 @@ export interface ISecureClientOptions {
|
|
|
129
131
|
*/
|
|
130
132
|
ca?: string | string[] | Buffer | Buffer[]
|
|
131
133
|
rejectUnauthorized?: boolean
|
|
134
|
+
/**
|
|
135
|
+
* optional alpn's
|
|
136
|
+
*/
|
|
137
|
+
ALPNProtocols?: string[] | Buffer[] | Uint8Array[] | Buffer | Uint8Array
|
|
132
138
|
}
|
|
133
139
|
export interface IClientPublishOptions {
|
|
134
140
|
/**
|
|
@@ -147,12 +153,12 @@ export interface IClientPublishOptions {
|
|
|
147
153
|
* MQTT 5.0 properties object
|
|
148
154
|
*/
|
|
149
155
|
properties?: {
|
|
150
|
-
payloadFormatIndicator?:
|
|
156
|
+
payloadFormatIndicator?: boolean,
|
|
151
157
|
messageExpiryInterval?: number,
|
|
152
|
-
topicAlias?:
|
|
158
|
+
topicAlias?: number,
|
|
153
159
|
responseTopic?: string,
|
|
154
160
|
correlationData?: Buffer,
|
|
155
|
-
userProperties?:
|
|
161
|
+
userProperties?: UserProperties,
|
|
156
162
|
subscriptionIdentifier?: number,
|
|
157
163
|
contentType?: string
|
|
158
164
|
}
|
|
@@ -177,7 +183,14 @@ export interface IClientSubscribeOptions {
|
|
|
177
183
|
/*
|
|
178
184
|
* Retain Handling option
|
|
179
185
|
* */
|
|
180
|
-
rh?: number
|
|
186
|
+
rh?: number,
|
|
187
|
+
/*
|
|
188
|
+
* MQTT 5.0 properies object of subscribe
|
|
189
|
+
* */
|
|
190
|
+
properties?: {
|
|
191
|
+
subscriptionIdentifier?: number,
|
|
192
|
+
userProperties?: UserProperties
|
|
193
|
+
}
|
|
181
194
|
}
|
|
182
195
|
export interface IClientReconnectOptions {
|
|
183
196
|
/**
|
package/types/lib/client.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
IClientReconnectOptions
|
|
9
9
|
} from './client-options'
|
|
10
10
|
import { Store } from './store'
|
|
11
|
-
import { Packet, QoS } from 'mqtt-packet'
|
|
11
|
+
import { IAuthPacket, IConnectPacket, IPublishPacket, IDisconnectPacket, IConnackPacket, Packet, QoS } from 'mqtt-packet'
|
|
12
12
|
|
|
13
13
|
export interface ISubscriptionGrant {
|
|
14
14
|
/**
|
|
@@ -66,13 +66,15 @@ export interface ISubscriptionMap {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export declare type OnConnectCallback = (packet:
|
|
69
|
+
export declare type OnConnectCallback = (packet: IConnackPacket) => void
|
|
70
|
+
export declare type OnDisconnectCallback = (packet: IDisconnectPacket) => void
|
|
70
71
|
export declare type ClientSubscribeCallback = (err: Error, granted: ISubscriptionGrant[]) => void
|
|
71
|
-
export declare type OnMessageCallback = (topic: string, payload: Buffer, packet:
|
|
72
|
+
export declare type OnMessageCallback = (topic: string, payload: Buffer, packet: IPublishPacket) => void
|
|
72
73
|
export declare type OnPacketCallback = (packet: Packet) => void
|
|
74
|
+
export declare type OnCloseCallback = () => void
|
|
73
75
|
export declare type OnErrorCallback = (error: Error) => void
|
|
74
76
|
export declare type PacketCallback = (error?: Error, packet?: Packet) => any
|
|
75
|
-
export declare type CloseCallback = () => void
|
|
77
|
+
export declare type CloseCallback = (error?: Error) => void
|
|
76
78
|
|
|
77
79
|
export interface IStream extends events.EventEmitter {
|
|
78
80
|
pipe (to: any): any
|
|
@@ -101,13 +103,19 @@ export declare class MqttClient extends events.EventEmitter {
|
|
|
101
103
|
public on (event: 'connect', cb: OnConnectCallback): this
|
|
102
104
|
public on (event: 'message', cb: OnMessageCallback): this
|
|
103
105
|
public on (event: 'packetsend' | 'packetreceive', cb: OnPacketCallback): this
|
|
106
|
+
public on (event: 'disconnect', cb: OnDisconnectCallback): this
|
|
104
107
|
public on (event: 'error', cb: OnErrorCallback): this
|
|
108
|
+
public on (event: 'close', cb: OnCloseCallback): this
|
|
109
|
+
public on (event: 'end' | 'reconnect' | 'offline' | 'outgoingEmpty', cb: () => void): this
|
|
105
110
|
public on (event: string, cb: Function): this
|
|
106
111
|
|
|
107
112
|
public once (event: 'connect', cb: OnConnectCallback): this
|
|
108
113
|
public once (event: 'message', cb: OnMessageCallback): this
|
|
109
114
|
public once (event: 'packetsend' | 'packetreceive', cb: OnPacketCallback): this
|
|
115
|
+
public once (event: 'disconnect', cb: OnDisconnectCallback): this
|
|
110
116
|
public once (event: 'error', cb: OnErrorCallback): this
|
|
117
|
+
public once (event: 'close', cb: OnCloseCallback): this
|
|
118
|
+
public once (event: 'end' | 'reconnect' | 'offline' | 'outgoingEmpty', cb: () => void): this
|
|
111
119
|
public once (event: string, cb: Function): this
|
|
112
120
|
|
|
113
121
|
/**
|
|
@@ -224,6 +232,27 @@ export declare class MqttClient extends events.EventEmitter {
|
|
|
224
232
|
*/
|
|
225
233
|
public handleMessage (packet: Packet, callback: PacketCallback): void
|
|
226
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Handle auth packages for MQTT 5 enhanced authentication methods such
|
|
237
|
+
* as challenge response authentication.
|
|
238
|
+
*
|
|
239
|
+
* Challenge-response authentication flow would look something like this:
|
|
240
|
+
*
|
|
241
|
+
* --> CONNECT | authMethod = "mathChallenge" -->
|
|
242
|
+
* <-- AUTH | authMethod = "mathChallenge", authData = "12 + 34" <--
|
|
243
|
+
* --> AUTH | authMethod = "mathChallenge", authData = "46" -->
|
|
244
|
+
* <-- CONNACK | reasonCode = SUCCESS <--
|
|
245
|
+
*
|
|
246
|
+
* This form of authentication has several advantages over traditional
|
|
247
|
+
* credential-based approaches. For instance authentication without the direct
|
|
248
|
+
* exchange of authentication secrets.
|
|
249
|
+
*
|
|
250
|
+
* @param packet the auth packet to handle
|
|
251
|
+
* @param callback call when finished
|
|
252
|
+
* @api public
|
|
253
|
+
*/
|
|
254
|
+
public handleAuth (packet: IAuthPacket, callback: PacketCallback): void
|
|
255
|
+
|
|
227
256
|
/**
|
|
228
257
|
* getLastMessageId
|
|
229
258
|
*/
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { IMessageIdProvider } from './message-id-provider'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* DefaultMessageIdProvider
|
|
5
|
+
* This is compatible behavior with the original MQTT.js internal messageId allocation.
|
|
6
|
+
*/
|
|
7
|
+
declare class DefaultMessageIdProvider implements IMessageIdProvider {
|
|
8
|
+
/**
|
|
9
|
+
* DefaultMessageIdProvider constructor.
|
|
10
|
+
* Randomize initial messageId
|
|
11
|
+
* @constructor
|
|
12
|
+
*/
|
|
13
|
+
constructor ()
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Return the current messageId and increment the current messageId.
|
|
17
|
+
* @return {Number} - messageId
|
|
18
|
+
*/
|
|
19
|
+
public allocate (): Number | null
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get the last allocated messageId.
|
|
23
|
+
* @return {Number} - messageId.
|
|
24
|
+
*/
|
|
25
|
+
public getLastAllocated (): Number | null
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Register the messageId.
|
|
29
|
+
* This function actually nothing and always return true.
|
|
30
|
+
* @param {Number} num - The messageId to request use.
|
|
31
|
+
* @return {Boolean} - If `num` was not occupied, then return true, otherwise return false.
|
|
32
|
+
*/
|
|
33
|
+
public register (num: Number): Boolean
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Deallocate the messageId.
|
|
37
|
+
* This function actually nothing.
|
|
38
|
+
* @param {Number} num - The messageId to deallocate.
|
|
39
|
+
*/
|
|
40
|
+
public deallocate (num: Number): void
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Clear all occupied messageIds.
|
|
44
|
+
* This function actually nothing.
|
|
45
|
+
*/
|
|
46
|
+
public clear (): void
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { DefaultMessageIdProvider }
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MessageIdProvider
|
|
3
|
+
*/
|
|
4
|
+
declare interface IMessageIdProvider {
|
|
5
|
+
/**
|
|
6
|
+
* Allocate the first vacant messageId. The messageId become occupied status.
|
|
7
|
+
* @return {Number} - The first vacant messageId. If all messageIds are occupied, return null.
|
|
8
|
+
*/
|
|
9
|
+
allocate (): Number | null
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get the last allocated messageId.
|
|
13
|
+
* @return {Number} - messageId.
|
|
14
|
+
*/
|
|
15
|
+
getLastAllocated (): Number | null
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Register the messageId. The messageId become occupied status.
|
|
19
|
+
* If the messageId has already been occupied, then return false.
|
|
20
|
+
* @param {Number} num - The messageId to request use.
|
|
21
|
+
* @return {Boolean} - If `num` was not occupied, then return true, otherwise return false.
|
|
22
|
+
*/
|
|
23
|
+
register (num: Number): Boolean
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Deallocate the messageId. The messageId become vacant status.
|
|
27
|
+
* @param {Number} num - The messageId to deallocate. The messageId must be occupied status.
|
|
28
|
+
* In other words, the messageId must be allocated by allocate() or
|
|
29
|
+
* occupied by register().
|
|
30
|
+
*/
|
|
31
|
+
deallocate (num: Number): void
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Clear all occupied messageIds.
|
|
35
|
+
* The all messageIds are set to vacant status.
|
|
36
|
+
*/
|
|
37
|
+
clear (): void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { IMessageIdProvider }
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { IMessageIdProvider } from './message-id-provider'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* UniqueMessageIdProvider
|
|
5
|
+
*/
|
|
6
|
+
declare class UniqueMessageIdProvider implements IMessageIdProvider {
|
|
7
|
+
/**
|
|
8
|
+
* UniqueMessageIdProvider constructor.
|
|
9
|
+
* @constructor
|
|
10
|
+
*/
|
|
11
|
+
constructor ()
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Allocate the first vacant messageId. The messageId become occupied status.
|
|
15
|
+
* @return {Number} - The first vacant messageId. If all messageIds are occupied, return null.
|
|
16
|
+
*/
|
|
17
|
+
public allocate (): Number | null
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get the last allocated messageId.
|
|
21
|
+
* @return {Number} - messageId.
|
|
22
|
+
*/
|
|
23
|
+
public getLastAllocated (): Number | null
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Register the messageId. The messageId become occupied status.
|
|
27
|
+
* If the messageId has already been occupied, then return false.
|
|
28
|
+
* @param {Number} num - The messageId to request use.
|
|
29
|
+
* @return {Boolean} - If `num` was not occupied, then return true, otherwise return false.
|
|
30
|
+
*/
|
|
31
|
+
public register (num: Number): Boolean
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Deallocate the messageId. The messageId become vacant status.
|
|
35
|
+
* @param {Number} num - The messageId to deallocate. The messageId must be occupied status.
|
|
36
|
+
* In other words, the messageId must be allocated by allocate() or
|
|
37
|
+
* occupied by register().
|
|
38
|
+
*/
|
|
39
|
+
public deallocate (num: Number): void
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Clear all occupied messageIds.
|
|
43
|
+
* The all messageIds are set to vacant status.
|
|
44
|
+
*/
|
|
45
|
+
public clear (): void
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export { UniqueMessageIdProvider }
|