geonix 1.10.0 → 1.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +1 -1
- package/exports.js +3 -1
- package/package.json +1 -1
- package/src/Stream.js +9 -2
package/.vscode/settings.json
CHANGED
package/exports.js
CHANGED
|
@@ -38,4 +38,6 @@ export { connection, stopConnection } from './src/Connection.js'
|
|
|
38
38
|
export { registry } from './src/Registry.js'
|
|
39
39
|
export { Request, Subscribe, Publish } from './src/Request.js'
|
|
40
40
|
export { RequestOptions } from './src/RequestOptions.js'
|
|
41
|
-
export { picoid as randomID } from './src/Util.js'
|
|
41
|
+
export { picoid as randomID } from './src/Util.js'
|
|
42
|
+
|
|
43
|
+
export { stats as StreamStats } from './src/Stream.js'
|
package/package.json
CHANGED
package/src/Stream.js
CHANGED
|
@@ -4,6 +4,8 @@ import { picoid, StreamChunker } from './Util.js'
|
|
|
4
4
|
|
|
5
5
|
const CHUNK_SIZE = 1024 * 128
|
|
6
6
|
|
|
7
|
+
export const stats = {}
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Converts data to stream
|
|
9
11
|
*
|
|
@@ -11,7 +13,7 @@ const CHUNK_SIZE = 1024 * 128
|
|
|
11
13
|
* @param {*} automated
|
|
12
14
|
* @returns
|
|
13
15
|
*/
|
|
14
|
-
export function Stream(data) {
|
|
16
|
+
export function Stream(data, tag = '_') {
|
|
15
17
|
if (isStream(data))
|
|
16
18
|
return data
|
|
17
19
|
|
|
@@ -27,13 +29,18 @@ export function Stream(data) {
|
|
|
27
29
|
readable.pipe(transform)
|
|
28
30
|
readable = transform
|
|
29
31
|
|
|
32
|
+
stats[tag] = stats[tag] !== undefined ? stats[tag] + 1 : 1
|
|
33
|
+
|
|
30
34
|
const controlHandler = async () => {
|
|
31
35
|
const control = await connection.subscribe(`gx2.stream.${id}.a`, { max: 1 })
|
|
32
36
|
|
|
33
37
|
for await (const event of control)
|
|
34
38
|
if (event.data.length === 0) {
|
|
35
39
|
readable.on('data', chunk => connection.publishRaw(`gx2.stream.${id}.b`, chunk))
|
|
36
|
-
readable.on('close', () =>
|
|
40
|
+
readable.on('close', () => {
|
|
41
|
+
connection.publishRaw(`gx2.stream.${id}.b`)
|
|
42
|
+
stats[tag]--
|
|
43
|
+
})
|
|
37
44
|
}
|
|
38
45
|
}
|
|
39
46
|
|