relayx-js 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ Unsubscribe from a topic:<br>
|
|
|
66
66
|
}
|
|
67
67
|
```
|
|
68
68
|
4. <b>History</b><br>
|
|
69
|
-
Get previously published messages between a start date and end date
|
|
69
|
+
Get previously published messages between a start date and end date. Dates are in UTC.
|
|
70
70
|
```javascript
|
|
71
71
|
var start = new Date();
|
|
72
72
|
var past = start.setDate(start.getDate() - 4) // Get start date from 4 days ago
|
package/examples/example_chat.js
CHANGED
|
@@ -8,8 +8,8 @@ const rl = readline.createInterface({
|
|
|
8
8
|
|
|
9
9
|
async function run(){
|
|
10
10
|
var realtime = new Realtime({
|
|
11
|
-
api_key:
|
|
12
|
-
secret:
|
|
11
|
+
api_key: "eyJ0eXAiOiJKV1QiLCJhbGciOiJlZDI1NTE5LW5rZXkifQ.eyJhdWQiOiJOQVRTIiwibmFtZSI6IjY3ZmZhMWVkMzk0NDRlODMwOGIxMDBiNCIsInN1YiI6IlVENUtRN0hNU01IMlNVWklCTTNCU1IyMjdQNUw3NFZKVTNUS0tPMk5XT1U2Qkg2S0pEV0JCNEFNIiwibmF0cyI6eyJkYXRhIjotMSwicGF5bG9hZCI6LTEsInN1YnMiOi0xLCJwdWIiOnsiZGVueSI6WyI-Il19LCJzdWIiOnsiZGVueSI6WyI-Il19LCJvcmdfZGF0YSI6eyJvcmdfaWQiOiI2N2ZmYTFkMzRmMDQ5MTAzNGQ5ZWJiNzIiLCJvcmdfbmFtZSI6IlNwYWNlWCIsInZhbGlkaXR5X2tleSI6IjU3NjUyM2UwLWM3ZGMtNGVlMS04OTFjLTAzNTFmMDgxOTkzYyIsInJvbGUiOiJ1c2VyIiwicHJvamVjdF9pZCI6IjY3ZmZhMWVkMzk0NDRlODMwOGIxMDBiNCJ9LCJpc3N1ZXJfYWNjb3VudCI6IkFCMzczR0JSWkVMNEhLNUdXWkJNNFNVTEFLVUhZSTVNUE9UWVNKQUpCVVVNU01KT09XREhFMjVYIiwidHlwZSI6InVzZXIiLCJ2ZXJzaW9uIjoyfSwiaXNzIjoiQUIzNzNHQlJaRUw0SEs1R1daQk00U1VMQUtVSFlJNU1QT1RZU0pBSkJVVU1TTUpPT1dESEUyNVgiLCJpYXQiOjE3NDQ4MDYzOTQsImp0aSI6Im5ZczM4MEZxa1dnNis3eGl4Wnl6VjJWS0ZLSVFNOEJrOG9ESFFzTjdBcW1YaUNmd05HTnNkQnVNK21YMW8xN0dFM2YxeEJXSFFGU1VUSmFrTmN1MGNnPT0ifQ.FVRHylWkCyIN0Axed0Z-H2Zgfh3HjEHGkjWQfUe70O3hl3OQYkQa1Ka-IYilGPB2fpd272t3VJarMvF1e5OSCw",
|
|
12
|
+
secret: "SUAC7MP5AIOVJJTV2DCKRQRVAANBETTVYP26O4YE2BXELFOCURXLMEX5YE"
|
|
13
13
|
});
|
|
14
14
|
await realtime.init(true, {
|
|
15
15
|
max_retries: 2,
|
|
@@ -28,8 +28,8 @@ async function run(){
|
|
|
28
28
|
console.log(`[IMPL] DISONNECT`)
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
await realtime.on("
|
|
32
|
-
console.log("
|
|
31
|
+
await realtime.on("power-telemetry", (data) => {
|
|
32
|
+
console.log("power-telemetry", data);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
await realtime.on("hello1", (data) => {
|
|
@@ -2,12 +2,12 @@ import { Realtime, CONNECTED, RECONNECT, DISCONNECTED, MESSAGE_RESEND } from "..
|
|
|
2
2
|
|
|
3
3
|
async function run(){
|
|
4
4
|
var realtime = new Realtime({
|
|
5
|
-
api_key:
|
|
6
|
-
secret:
|
|
5
|
+
api_key: "eyJ0eXAiOiJKV1QiLCJhbGciOiJlZDI1NTE5LW5rZXkifQ.eyJhdWQiOiJOQVRTIiwibmFtZSI6IjY3ZmY5OGEwMTQ4NTgwYTcw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
|
|
10
|
+
debug: true
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
realtime.on(CONNECTED, async () => {
|
|
@@ -16,9 +16,9 @@ async function run(){
|
|
|
16
16
|
for (let angle = 0; angle <= 18000; angle++){
|
|
17
17
|
|
|
18
18
|
var value = Math.floor(Math.random() * (100 + 1))
|
|
19
|
-
console.log(value)
|
|
19
|
+
// console.log(value)
|
|
20
20
|
|
|
21
|
-
// await realtime.publish("test-power
|
|
21
|
+
// await realtime.publish("test-power", {
|
|
22
22
|
// "value": value,
|
|
23
23
|
// "time": Date.now() + 2000
|
|
24
24
|
// })
|
|
@@ -28,7 +28,7 @@ async function run(){
|
|
|
28
28
|
"time": Date.now()
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
console.log(`Message sent => ${sent}`);
|
|
31
|
+
// console.log(`Message sent => ${sent}`);
|
|
32
32
|
|
|
33
33
|
await realtime.sleep(100)
|
|
34
34
|
}
|
package/package.json
CHANGED
package/realtime/realtime.js
CHANGED
|
@@ -114,7 +114,8 @@ export class Realtime {
|
|
|
114
114
|
"nats://0.0.0.0:4223",
|
|
115
115
|
"nats://0.0.0.0:4224",
|
|
116
116
|
"nats://0.0.0.0:4225",
|
|
117
|
-
"nats://0.0.0.0:4226"
|
|
117
|
+
"nats://0.0.0.0:4226"
|
|
118
|
+
] :
|
|
118
119
|
[
|
|
119
120
|
"nats://api.relay-x.io:4221",
|
|
120
121
|
"nats://api.relay-x.io:4222",
|
|
@@ -185,7 +186,7 @@ export class Realtime {
|
|
|
185
186
|
reconnect: true,
|
|
186
187
|
reconnectTimeWait: 1000,
|
|
187
188
|
authenticator: credsAuth,
|
|
188
|
-
token: this.api_key
|
|
189
|
+
token: this.api_key,
|
|
189
190
|
});
|
|
190
191
|
|
|
191
192
|
this.#jsManager = await jetstreamManager(this.#natsClient);
|
|
@@ -279,6 +280,7 @@ export class Realtime {
|
|
|
279
280
|
|
|
280
281
|
// Subscribe to topics
|
|
281
282
|
this.#subscribeToTopics();
|
|
283
|
+
this.#log("Subscribed to topics");
|
|
282
284
|
}
|
|
283
285
|
}
|
|
284
286
|
|
|
@@ -358,7 +360,7 @@ export class Realtime {
|
|
|
358
360
|
}
|
|
359
361
|
|
|
360
362
|
if (![CONNECTED, DISCONNECTED, RECONNECT, this.#RECONNECTED,
|
|
361
|
-
this.#RECONNECTING, this.#RECONN_FAIL, MESSAGE_RESEND].includes(topic)){
|
|
363
|
+
this.#RECONNECTING, this.#RECONN_FAIL, MESSAGE_RESEND, SERVER_DISCONNECT].includes(topic)){
|
|
362
364
|
if(!this.isTopicValid(topic)){
|
|
363
365
|
// We have an invalid topic, lets remove it
|
|
364
366
|
if(topic in this.#event_func){
|
|
@@ -580,12 +582,12 @@ export class Realtime {
|
|
|
580
582
|
|
|
581
583
|
const consumer = await this.#jetstream.consumers.get(this.#getStreamName(), opts);
|
|
582
584
|
this.#log(this.#topicMap)
|
|
583
|
-
this.#log("Consumer is consuming");
|
|
584
585
|
|
|
585
586
|
this.#consumerMap[topic] = consumer;
|
|
586
587
|
|
|
587
588
|
await consumer.consume({
|
|
588
589
|
callback: (msg) => {
|
|
590
|
+
console.log("TIMESTAMP", msg.info)
|
|
589
591
|
|
|
590
592
|
msg.ack();
|
|
591
593
|
try{
|
|
@@ -609,6 +611,7 @@ export class Realtime {
|
|
|
609
611
|
}
|
|
610
612
|
}
|
|
611
613
|
});
|
|
614
|
+
this.#log("Consumer is consuming");
|
|
612
615
|
}
|
|
613
616
|
|
|
614
617
|
/**
|
|
@@ -652,6 +655,7 @@ export class Realtime {
|
|
|
652
655
|
await this.#jsManager.streams.add({
|
|
653
656
|
name: streamName,
|
|
654
657
|
subjects: [...this.#getStreamTopicList(), ...this.#getPresenceTopics()],
|
|
658
|
+
num_replicas: 3
|
|
655
659
|
});
|
|
656
660
|
|
|
657
661
|
this.#log(`${streamName} created`);
|
|
@@ -677,9 +681,9 @@ export class Realtime {
|
|
|
677
681
|
isTopicValid(topic){
|
|
678
682
|
if(topic !== null && topic !== undefined && (typeof topic) == "string"){
|
|
679
683
|
var arrayCheck = ![CONNECTED, DISCONNECTED, RECONNECT, this.#RECONNECTED,
|
|
680
|
-
this.#RECONNECTING, this.#RECONN_FAIL, MESSAGE_RESEND].includes(topic);
|
|
684
|
+
this.#RECONNECTING, this.#RECONN_FAIL, MESSAGE_RESEND, SERVER_DISCONNECT].includes(topic);
|
|
681
685
|
|
|
682
|
-
var spaceStarCheck = !topic.includes(" ") && !topic.includes("*");
|
|
686
|
+
var spaceStarCheck = !topic.includes(" ") && !topic.includes("*") && !topic.includes(".");
|
|
683
687
|
|
|
684
688
|
return arrayCheck && spaceStarCheck;
|
|
685
689
|
}else{
|
|
@@ -861,4 +865,5 @@ export class Realtime {
|
|
|
861
865
|
export const CONNECTED = "CONNECTED";
|
|
862
866
|
export const RECONNECT = "RECONNECT";
|
|
863
867
|
export const MESSAGE_RESEND = "MESSAGE_RESEND";
|
|
864
|
-
export const DISCONNECTED = "DISCONNECTED";
|
|
868
|
+
export const DISCONNECTED = "DISCONNECTED";
|
|
869
|
+
export const SERVER_DISCONNECT = "SERVER_DISCONNECT";
|