@libp2p/daemon-server 1.0.1 → 1.0.4
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/src/pubsub.d.ts.map +1 -1
- package/dist/src/pubsub.js +6 -3
- package/dist/src/pubsub.js.map +1 -1
- package/package.json +6 -6
- package/src/pubsub.ts +7 -3
package/dist/src/pubsub.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pubsub.d.ts","sourceRoot":"","sources":["../../src/pubsub.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"pubsub.d.ts","sourceRoot":"","sources":["../../src/pubsub.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAOvD,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;CACf;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;gBAElB,IAAI,EAAE,oBAAoB;IAM/B,SAAS;IAcT,SAAS,CAAE,KAAK,EAAE,MAAM;IA8BxB,OAAO,CAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU;CASjD"}
|
package/dist/src/pubsub.js
CHANGED
|
@@ -3,7 +3,6 @@ import { PSMessage } from '@libp2p/daemon-protocol';
|
|
|
3
3
|
import { ErrorResponse, OkResponse } from './responses.js';
|
|
4
4
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
5
5
|
import { pushable } from 'it-pushable';
|
|
6
|
-
import { CustomEvent } from '@libp2p/interfaces';
|
|
7
6
|
import { logger } from '@libp2p/logger';
|
|
8
7
|
const log = logger('libp2p:daemon-server:pubsub');
|
|
9
8
|
export class PubSubOperations {
|
|
@@ -28,8 +27,12 @@ export class PubSubOperations {
|
|
|
28
27
|
async *subscribe(topic) {
|
|
29
28
|
try {
|
|
30
29
|
const onMessage = pushable();
|
|
31
|
-
|
|
30
|
+
this.pubsub.subscribe(topic);
|
|
31
|
+
await this.pubsub.addEventListener('message', (evt) => {
|
|
32
32
|
const msg = evt.detail;
|
|
33
|
+
if (msg.topic !== topic) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
33
36
|
onMessage.push(PSMessage.encode({
|
|
34
37
|
from: msg.from.toBytes(),
|
|
35
38
|
data: msg.data,
|
|
@@ -49,7 +52,7 @@ export class PubSubOperations {
|
|
|
49
52
|
}
|
|
50
53
|
async *publish(topic, data) {
|
|
51
54
|
try {
|
|
52
|
-
this.pubsub.
|
|
55
|
+
await this.pubsub.publish(topic, data);
|
|
53
56
|
yield OkResponse();
|
|
54
57
|
}
|
|
55
58
|
catch (err) {
|
package/dist/src/pubsub.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../../src/pubsub.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,EACL,SAAS,EACV,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"pubsub.js","sourceRoot":"","sources":["../../src/pubsub.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,EACL,SAAS,EACV,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE1D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,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C,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC;oBACjI,QAAQ,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC;oBACrB,SAAS,EAAE,GAAG,CAAC,SAAS;oBACxB,GAAG,EAAE,GAAG,CAAC,GAAG;iBACb,CAAC,CAAC,CAAA;YACL,CAAC,CAAC,CAAA;YAEF,MAAM,UAAU,EAAE,CAAA;YAClB,KAAM,CAAC,CAAC,SAAS,CAAA;SAClB;QAAC,OAAO,GAAQ,EAAE;YACjB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACd,MAAM,aAAa,CAAC,GAAG,CAAC,CAAA;SACzB;IACH,CAAC;IAED,KAAK,CAAC,CAAE,OAAO,CAAE,KAAa,EAAE,IAAgB;QAC9C,IAAI;YACF,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;YACtC,MAAM,UAAU,EAAE,CAAA;SACnB;QAAC,OAAO,GAAQ,EAAE;YACjB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YACd,MAAM,aAAa,CAAC,GAAG,CAAC,CAAA;SACzB;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/daemon-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "API server for libp2p-daemon instances",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p-daemon/tree/master/packages/libp2p-daemon-server#readme",
|
|
@@ -134,10 +134,10 @@
|
|
|
134
134
|
},
|
|
135
135
|
"dependencies": {
|
|
136
136
|
"@libp2p/daemon-protocol": "^1.0.0",
|
|
137
|
-
"@libp2p/interfaces": "^
|
|
138
|
-
"@libp2p/logger": "^1.1.
|
|
139
|
-
"@libp2p/peer-id": "^1.1.
|
|
140
|
-
"@libp2p/tcp": "^1.0.
|
|
137
|
+
"@libp2p/interfaces": "^2.0.1",
|
|
138
|
+
"@libp2p/logger": "^1.1.4",
|
|
139
|
+
"@libp2p/peer-id": "^1.1.10",
|
|
140
|
+
"@libp2p/tcp": "^1.0.8",
|
|
141
141
|
"@multiformats/multiaddr": "^10.1.8",
|
|
142
142
|
"it-drain": "^1.0.5",
|
|
143
143
|
"it-length-prefixed": "^7.0.1",
|
|
@@ -148,7 +148,7 @@
|
|
|
148
148
|
},
|
|
149
149
|
"devDependencies": {
|
|
150
150
|
"aegir": "^37.0.5",
|
|
151
|
-
"sinon": "^
|
|
151
|
+
"sinon": "^14.0.0",
|
|
152
152
|
"ts-sinon": "^2.0.2"
|
|
153
153
|
}
|
|
154
154
|
}
|
package/src/pubsub.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { ErrorResponse, OkResponse } from './responses.js'
|
|
|
7
7
|
import type { PubSub } from '@libp2p/interfaces/pubsub'
|
|
8
8
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
9
9
|
import { pushable } from 'it-pushable'
|
|
10
|
-
import { CustomEvent } from '@libp2p/interfaces'
|
|
11
10
|
import { logger } from '@libp2p/logger'
|
|
12
11
|
|
|
13
12
|
const log = logger('libp2p:daemon-server:pubsub')
|
|
@@ -42,10 +41,15 @@ export class PubSubOperations {
|
|
|
42
41
|
async * subscribe (topic: string) {
|
|
43
42
|
try {
|
|
44
43
|
const onMessage = pushable<Uint8Array>()
|
|
44
|
+
this.pubsub.subscribe(topic)
|
|
45
45
|
|
|
46
|
-
await this.pubsub.addEventListener(
|
|
46
|
+
await this.pubsub.addEventListener('message', (evt) => {
|
|
47
47
|
const msg = evt.detail
|
|
48
48
|
|
|
49
|
+
if (msg.topic !== topic) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
onMessage.push(PSMessage.encode({
|
|
50
54
|
from: msg.from.toBytes(),
|
|
51
55
|
data: msg.data,
|
|
@@ -66,7 +70,7 @@ export class PubSubOperations {
|
|
|
66
70
|
|
|
67
71
|
async * publish (topic: string, data: Uint8Array) {
|
|
68
72
|
try {
|
|
69
|
-
this.pubsub.
|
|
73
|
+
await this.pubsub.publish(topic, data)
|
|
70
74
|
yield OkResponse()
|
|
71
75
|
} catch (err: any) {
|
|
72
76
|
log.error(err)
|