abmqtts 0.0.8 → 0.0.10
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/fbns/fbns.client.js +208 -162
- package/dist/mqttot/mqttot.client.d.ts +2 -2
- package/dist/mqttot/mqttot.client.js +99 -87
- package/dist/mqttot/mqttot.connect.request.packet.d.ts +1 -1
- package/dist/mqttot/mqttot.connect.response.packet.d.ts +1 -1
- package/dist/mqttot/mqttot.connect.response.packet.js +18 -15
- package/dist/realtime/commands/commands.d.ts +1 -1
- package/dist/realtime/commands/direct.commands.d.ts +2 -2
- package/dist/realtime/mixins/message-sync.mixin.js +69 -65
- package/dist/realtime/mixins/realtime-sub.mixin.js +53 -47
- package/dist/realtime/realtime.client.d.ts +1 -1
- package/dist/realtime/realtime.client.events.d.ts +2 -2
- package/dist/realtime/realtime.client.js +230 -179
- package/dist/shared.d.ts +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MQTToTClient } from '../../mqttot';
|
|
2
2
|
import { MessageSyncMessageTypes } from '../messages';
|
|
3
3
|
import { ThriftPacketDescriptor } from '../../thrift';
|
|
4
|
-
import { MqttMessageOutgoing } from '
|
|
4
|
+
import { MqttMessageOutgoing } from 'abmqtt-dist';
|
|
5
5
|
interface ItemBaseType {
|
|
6
6
|
threadId: string;
|
|
7
7
|
clientContext?: string;
|
|
@@ -64,4 +64,4 @@ export declare class DirectCommands {
|
|
|
64
64
|
isActive?: boolean;
|
|
65
65
|
} & ItemBaseType): Promise<MqttMessageOutgoing>;
|
|
66
66
|
}
|
|
67
|
-
export {};
|
|
67
|
+
export { };
|
|
@@ -4,74 +4,78 @@ exports.MessageSyncMixin = void 0;
|
|
|
4
4
|
const mixin_1 = require("./mixin");
|
|
5
5
|
const constants_1 = require("../../constants");
|
|
6
6
|
const shared_1 = require("../../shared");
|
|
7
|
-
const obmqtt_1 = require("
|
|
7
|
+
const obmqtt_1 = require("abmqtt-dist");
|
|
8
8
|
class MessageSyncMixin extends mixin_1.Mixin {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
apply(client) {
|
|
10
|
+
(0, mixin_1.hook)(client, "connect", {
|
|
11
|
+
post: () => {
|
|
12
|
+
if (!client.mqtt) {
|
|
13
|
+
throw new obmqtt_1.IllegalStateError("No mqtt client created");
|
|
14
|
+
}
|
|
15
|
+
client.mqtt.listen(
|
|
16
|
+
{
|
|
17
|
+
topic: constants_1.Topics.MESSAGE_SYNC.id,
|
|
18
|
+
transformer: async ({ payload }) =>
|
|
19
|
+
constants_1.Topics.MESSAGE_SYNC.parser
|
|
20
|
+
.parseMessage(
|
|
21
|
+
constants_1.Topics.MESSAGE_SYNC,
|
|
22
|
+
await (0, shared_1.tryUnzipAsync)(payload)
|
|
23
|
+
)
|
|
24
|
+
.map((msg) => msg.data),
|
|
25
|
+
},
|
|
26
|
+
(data) => this.handleMessageSync(client, data)
|
|
27
|
+
);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
handleMessageSync(client, syncData) {
|
|
32
|
+
for (const element of syncData) {
|
|
33
|
+
const data = element.data;
|
|
34
|
+
if (!data) {
|
|
35
|
+
client.emit("iris", element);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
delete element.data;
|
|
39
|
+
data.forEach((e) => {
|
|
40
|
+
if (!e.path) {
|
|
41
|
+
client.emit("iris", { ...element, ...e });
|
|
42
|
+
}
|
|
43
|
+
if (e.path.startsWith("/direct_v2/threads") && e.value) {
|
|
44
|
+
client.emit("message", {
|
|
45
|
+
...element,
|
|
46
|
+
message: {
|
|
47
|
+
path: e.path,
|
|
48
|
+
op: e.op,
|
|
49
|
+
thread_id: MessageSyncMixin.getThreadIdFromPath(e.path),
|
|
50
|
+
...JSON.parse(e.value),
|
|
21
51
|
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
if (e.path.startsWith('/direct_v2/threads') && e.value) {
|
|
37
|
-
client.emit('message', {
|
|
38
|
-
...element,
|
|
39
|
-
message: {
|
|
40
|
-
path: e.path,
|
|
41
|
-
op: e.op,
|
|
42
|
-
thread_id: MessageSyncMixin.getThreadIdFromPath(e.path),
|
|
43
|
-
...JSON.parse(e.value),
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
client.emit('threadUpdate', {
|
|
49
|
-
...element,
|
|
50
|
-
meta: {
|
|
51
|
-
path: e.path,
|
|
52
|
-
op: e.op,
|
|
53
|
-
thread_id: MessageSyncMixin.getThreadIdFromPath(e.path),
|
|
54
|
-
},
|
|
55
|
-
update: {
|
|
56
|
-
...JSON.parse(e.value),
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
});
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
client.emit("threadUpdate", {
|
|
55
|
+
...element,
|
|
56
|
+
meta: {
|
|
57
|
+
path: e.path,
|
|
58
|
+
op: e.op,
|
|
59
|
+
thread_id: MessageSyncMixin.getThreadIdFromPath(e.path),
|
|
60
|
+
},
|
|
61
|
+
update: {
|
|
62
|
+
...JSON.parse(e.value),
|
|
63
|
+
},
|
|
64
|
+
});
|
|
61
65
|
}
|
|
66
|
+
});
|
|
62
67
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
68
|
+
}
|
|
69
|
+
static getThreadIdFromPath(path) {
|
|
70
|
+
const itemMatch = path.match(/^\/direct_v2\/threads\/(\d+)/);
|
|
71
|
+
if (itemMatch) return itemMatch[1];
|
|
72
|
+
const inboxMatch = path.match(/^\/direct_v2\/inbox\/threads\/(\d+)/);
|
|
73
|
+
if (inboxMatch) return inboxMatch[1];
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
get name() {
|
|
77
|
+
return "Message Sync";
|
|
78
|
+
}
|
|
75
79
|
}
|
|
76
80
|
exports.MessageSyncMixin = MessageSyncMixin;
|
|
77
|
-
//# sourceMappingURL=message-sync.mixin.js.map
|
|
81
|
+
//# sourceMappingURL=message-sync.mixin.js.map
|
|
@@ -5,56 +5,62 @@ const mixin_1 = require("./mixin");
|
|
|
5
5
|
const constants_1 = require("../../constants");
|
|
6
6
|
const shared_1 = require("../../shared");
|
|
7
7
|
const subscriptions_1 = require("../subscriptions");
|
|
8
|
-
const obmqtt_1 = require("
|
|
8
|
+
const obmqtt_1 = require("abmqtt-dist");
|
|
9
9
|
class RealtimeSubMixin extends mixin_1.Mixin {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
client.mqtt.listen({
|
|
17
|
-
topic: constants_1.Topics.REALTIME_SUB.id,
|
|
18
|
-
transformer: async ({ payload }) => constants_1.Topics.REALTIME_SUB.parser.parseMessage(constants_1.Topics.REALTIME_SUB, await (0, shared_1.tryUnzipAsync)(payload)),
|
|
19
|
-
}, data => this.handleRealtimeSub(client, data));
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
handleRealtimeSub(client, { data, topic: messageTopic }) {
|
|
24
|
-
const { message } = data;
|
|
25
|
-
client.emit('realtimeSub', { data, topic: messageTopic });
|
|
26
|
-
if (typeof message === 'string') {
|
|
27
|
-
this.emitDirectEvent(client, JSON.parse(message));
|
|
10
|
+
apply(client) {
|
|
11
|
+
(0, mixin_1.hook)(client, "connect", {
|
|
12
|
+
post: () => {
|
|
13
|
+
if (!client.mqtt) {
|
|
14
|
+
throw new obmqtt_1.IllegalStateError("No mqtt client created");
|
|
28
15
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
16
|
+
client.mqtt.listen(
|
|
17
|
+
{
|
|
18
|
+
topic: constants_1.Topics.REALTIME_SUB.id,
|
|
19
|
+
transformer: async ({ payload }) =>
|
|
20
|
+
constants_1.Topics.REALTIME_SUB.parser.parseMessage(
|
|
21
|
+
constants_1.Topics.REALTIME_SUB,
|
|
22
|
+
await (0, shared_1.tryUnzipAsync)(payload)
|
|
23
|
+
),
|
|
24
|
+
},
|
|
25
|
+
(data) => this.handleRealtimeSub(client, data)
|
|
26
|
+
);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
handleRealtimeSub(client, { data, topic: messageTopic }) {
|
|
31
|
+
const { message } = data;
|
|
32
|
+
client.emit("realtimeSub", { data, topic: messageTopic });
|
|
33
|
+
if (typeof message === "string") {
|
|
34
|
+
this.emitDirectEvent(client, JSON.parse(message));
|
|
35
|
+
} else {
|
|
36
|
+
const { topic, payload, json } = message;
|
|
37
|
+
switch (topic) {
|
|
38
|
+
case "direct": {
|
|
39
|
+
this.emitDirectEvent(client, json);
|
|
40
|
+
break;
|
|
44
41
|
}
|
|
42
|
+
default: {
|
|
43
|
+
const entries = Object.entries(subscriptions_1.QueryIDs);
|
|
44
|
+
const query = entries.find((e) => e[1] === topic);
|
|
45
|
+
if (query) {
|
|
46
|
+
client.emit(query[0], json || payload);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
45
50
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
}
|
|
52
|
+
emitDirectEvent(client, parsed) {
|
|
53
|
+
parsed.data = parsed.data.map((e) => {
|
|
54
|
+
if (typeof e.value === "string") {
|
|
55
|
+
e.value = JSON.parse(e.value);
|
|
56
|
+
}
|
|
57
|
+
return e;
|
|
58
|
+
});
|
|
59
|
+
parsed.data.forEach((data) => client.emit("direct", data));
|
|
60
|
+
}
|
|
61
|
+
get name() {
|
|
62
|
+
return "Realtime Sub";
|
|
63
|
+
}
|
|
58
64
|
}
|
|
59
65
|
exports.RealtimeSubMixin = RealtimeSubMixin;
|
|
60
|
-
//# sourceMappingURL=realtime-sub.mixin.js.map
|
|
66
|
+
//# sourceMappingURL=realtime-sub.mixin.js.map
|
|
@@ -2,7 +2,7 @@ import { IgApiClient } from 'instagram-private-api';
|
|
|
2
2
|
import { Commands, DirectCommands } from './commands';
|
|
3
3
|
import { ToEventFn } from '../shared';
|
|
4
4
|
import { MQTToTClient, MQTToTConnectionClientInfo } from '../mqttot';
|
|
5
|
-
import { MqttMessageOutgoing } from '
|
|
5
|
+
import { MqttMessageOutgoing } from 'abmqtt-dist';
|
|
6
6
|
import { EventEmitter } from 'eventemitter3';
|
|
7
7
|
import { RealtimeClientEvents } from './realtime.client.events';
|
|
8
8
|
import { Mixin } from './mixins';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQlMessage, IrisParserData, ParsedMessage } from './parsers';
|
|
2
2
|
import { AppPresenceEventWrapper, MessageSyncMessageWrapper, RealtimeSubDirectDataWrapper } from './messages';
|
|
3
3
|
import { Topic } from '../topic';
|
|
4
|
-
import { MqttMessage } from '
|
|
4
|
+
import { MqttMessage } from 'abmqtt-dist';
|
|
5
5
|
import { QueryIDs } from './subscriptions';
|
|
6
6
|
import { ThreadUpdateWrapper } from './messages/thread-update.message';
|
|
7
7
|
type ReceiveEvent<T> = [Topic<T>, ParsedMessage<T>[]?];
|
|
@@ -32,4 +32,4 @@ export type MergedRealtimeSubPayloads = {
|
|
|
32
32
|
export type KnownRealtimeSubPayloads = {
|
|
33
33
|
appPresence: AppPresenceEventWrapper;
|
|
34
34
|
};
|
|
35
|
-
export {};
|
|
35
|
+
export { };
|