2019-09-16 20:26:32 +00:00
|
|
|
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
2020-02-17 19:06:18 +00:00
|
|
|
import { InteractionManager } from 'react-native';
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
import database from '../../database';
|
2018-04-24 19:34:03 +00:00
|
|
|
import { merge } from '../helpers/mergeSubscriptionsRooms';
|
2018-05-18 17:55:08 +00:00
|
|
|
import protectedFunction from '../helpers/protectedFunction';
|
2018-05-23 13:39:18 +00:00
|
|
|
import messagesStatus from '../../../constants/messagesStatus';
|
2018-05-18 17:55:08 +00:00
|
|
|
import log from '../../../utils/log';
|
2018-12-05 20:52:08 +00:00
|
|
|
import random from '../../../utils/random';
|
2019-02-07 16:13:21 +00:00
|
|
|
import store from '../../createStore';
|
|
|
|
import { roomsRequest } from '../../../actions/rooms';
|
2020-02-11 14:01:35 +00:00
|
|
|
import { handlePayloadUserInteraction } from '../actions';
|
2020-02-05 15:22:29 +00:00
|
|
|
import buildMessage from '../helpers/buildMessage';
|
2020-02-12 17:21:11 +00:00
|
|
|
import RocketChat from '../../rocketchat';
|
2020-06-16 20:32:30 +00:00
|
|
|
import EventEmitter from '../../../utils/events';
|
2020-03-20 16:38:01 +00:00
|
|
|
import { removedRoom } from '../../../actions/room';
|
2020-06-26 20:45:21 +00:00
|
|
|
import { setUser } from '../../../actions/login';
|
2020-06-16 20:32:30 +00:00
|
|
|
import { INAPP_NOTIFICATION_EMITTER } from '../../../containers/InAppNotification';
|
2020-09-11 14:31:38 +00:00
|
|
|
import { Encryption } from '../../encryption';
|
|
|
|
import { E2E_MESSAGE_TYPE } from '../../encryption/constants';
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2019-02-14 16:43:56 +00:00
|
|
|
const removeListener = listener => listener.stop();
|
|
|
|
|
|
|
|
let connectedListener;
|
|
|
|
let disconnectedListener;
|
|
|
|
let streamListener;
|
2019-06-17 13:57:07 +00:00
|
|
|
let subServer;
|
2020-08-24 19:59:55 +00:00
|
|
|
let queue = {};
|
2020-02-05 15:22:29 +00:00
|
|
|
let subTimer = null;
|
2020-02-17 19:06:18 +00:00
|
|
|
const WINDOW_TIME = 500;
|
2019-02-14 16:43:56 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
const createOrUpdateSubscription = async(subscription, room) => {
|
|
|
|
try {
|
|
|
|
const db = database.active;
|
2021-03-15 20:16:34 +00:00
|
|
|
const subCollection = db.get('subscriptions');
|
|
|
|
const roomsCollection = db.get('rooms');
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
if (!subscription) {
|
|
|
|
try {
|
|
|
|
const s = await subCollection.find(room._id);
|
|
|
|
// We have to create a plain obj so we can manipulate it on `merge`
|
|
|
|
// Can we do it in a better way?
|
|
|
|
subscription = {
|
|
|
|
_id: s._id,
|
|
|
|
f: s.f,
|
|
|
|
t: s.t,
|
|
|
|
ts: s.ts,
|
|
|
|
ls: s.ls,
|
|
|
|
name: s.name,
|
|
|
|
fname: s.fname,
|
|
|
|
rid: s.rid,
|
|
|
|
open: s.open,
|
|
|
|
alert: s.alert,
|
|
|
|
unread: s.unread,
|
|
|
|
userMentions: s.userMentions,
|
|
|
|
roomUpdatedAt: s.roomUpdatedAt,
|
|
|
|
ro: s.ro,
|
|
|
|
lastOpen: s.lastOpen,
|
|
|
|
description: s.description,
|
|
|
|
announcement: s.announcement,
|
2020-05-08 12:57:04 +00:00
|
|
|
bannerClosed: s.bannerClosed,
|
2019-09-16 20:26:32 +00:00
|
|
|
topic: s.topic,
|
|
|
|
blocked: s.blocked,
|
|
|
|
blocker: s.blocker,
|
|
|
|
reactWhenReadOnly: s.reactWhenReadOnly,
|
|
|
|
archived: s.archived,
|
|
|
|
joinCodeRequired: s.joinCodeRequired,
|
|
|
|
muted: s.muted,
|
2020-11-30 20:00:31 +00:00
|
|
|
ignored: s.ignored,
|
2019-09-16 20:26:32 +00:00
|
|
|
broadcast: s.broadcast,
|
|
|
|
prid: s.prid,
|
|
|
|
draftMessage: s.draftMessage,
|
|
|
|
lastThreadSync: s.lastThreadSync,
|
2019-09-18 17:32:12 +00:00
|
|
|
jitsiTimeout: s.jitsiTimeout,
|
2019-09-16 20:26:32 +00:00
|
|
|
autoTranslate: s.autoTranslate,
|
|
|
|
autoTranslateLanguage: s.autoTranslateLanguage,
|
2020-04-01 12:28:54 +00:00
|
|
|
lastMessage: s.lastMessage,
|
2020-04-13 12:51:16 +00:00
|
|
|
roles: s.roles,
|
2020-04-01 12:28:54 +00:00
|
|
|
usernames: s.usernames,
|
2020-05-08 17:36:10 +00:00
|
|
|
uids: s.uids,
|
|
|
|
visitor: s.visitor,
|
|
|
|
departmentId: s.departmentId,
|
|
|
|
servedBy: s.servedBy,
|
|
|
|
livechatData: s.livechatData,
|
2020-09-11 14:31:38 +00:00
|
|
|
tags: s.tags,
|
|
|
|
encrypted: s.encrypted,
|
|
|
|
e2eKeyId: s.e2eKeyId,
|
2020-10-30 13:51:04 +00:00
|
|
|
E2EKey: s.E2EKey,
|
|
|
|
avatarETag: s.avatarETag
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
|
|
|
} catch (error) {
|
|
|
|
try {
|
|
|
|
await db.action(async() => {
|
2019-10-08 12:36:15 +00:00
|
|
|
await roomsCollection.create(protectedFunction((r) => {
|
2019-09-16 20:26:32 +00:00
|
|
|
r._raw = sanitizedRaw({ id: room._id }, roomsCollection.schema);
|
|
|
|
Object.assign(r, room);
|
2019-10-08 12:36:15 +00:00
|
|
|
}));
|
2019-09-16 20:26:32 +00:00
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!room && subscription) {
|
|
|
|
try {
|
|
|
|
const r = await roomsCollection.find(subscription.rid);
|
|
|
|
// We have to create a plain obj so we can manipulate it on `merge`
|
|
|
|
// Can we do it in a better way?
|
|
|
|
room = {
|
2020-05-08 17:36:10 +00:00
|
|
|
v: r.v,
|
|
|
|
ro: r.ro,
|
|
|
|
tags: r.tags,
|
|
|
|
servedBy: r.servedBy,
|
2019-09-16 20:26:32 +00:00
|
|
|
encrypted: r.encrypted,
|
2020-09-11 14:31:38 +00:00
|
|
|
e2eKeyId: r.e2eKeyId,
|
2020-05-08 17:36:10 +00:00
|
|
|
broadcast: r.broadcast,
|
|
|
|
customFields: r.customFields,
|
|
|
|
departmentId: r.departmentId,
|
2020-10-30 13:51:04 +00:00
|
|
|
livechatData: r.livechatData,
|
|
|
|
avatarETag: r.avatarETag
|
2019-09-16 20:26:32 +00:00
|
|
|
};
|
|
|
|
} catch (error) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-11 14:31:38 +00:00
|
|
|
let tmp = merge(subscription, room);
|
|
|
|
tmp = await Encryption.decryptSubscription(tmp);
|
|
|
|
let sub;
|
|
|
|
try {
|
|
|
|
sub = await subCollection.find(tmp.rid);
|
|
|
|
} catch (error) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're receiving a E2EKey of a room
|
|
|
|
if (sub && !sub.E2EKey && subscription?.E2EKey) {
|
|
|
|
// Assing info from database subscription to tmp
|
|
|
|
// It should be a plain object
|
|
|
|
tmp = Object.assign(tmp, {
|
|
|
|
rid: sub.rid,
|
|
|
|
encrypted: sub.encrypted,
|
|
|
|
lastMessage: sub.lastMessage,
|
|
|
|
E2EKey: subscription.E2EKey,
|
|
|
|
e2eKeyId: sub.e2eKeyId
|
|
|
|
});
|
|
|
|
// Decrypt lastMessage using the received E2EKey
|
|
|
|
tmp = await Encryption.decryptSubscription(tmp);
|
|
|
|
// Decrypt all pending messages of this room in parallel
|
|
|
|
Encryption.decryptPendingMessages(tmp.rid);
|
|
|
|
}
|
|
|
|
|
|
|
|
const batch = [];
|
|
|
|
if (sub) {
|
|
|
|
try {
|
|
|
|
const update = sub.prepareUpdate((s) => {
|
|
|
|
Object.assign(s, tmp);
|
|
|
|
if (subscription.announcement) {
|
|
|
|
if (subscription.announcement !== sub.announcement) {
|
|
|
|
s.bannerClosed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
batch.push(update);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
} else {
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
2020-09-11 14:31:38 +00:00
|
|
|
const create = subCollection.prepareCreate((s) => {
|
|
|
|
s._raw = sanitizedRaw({ id: tmp.rid }, subCollection.schema);
|
|
|
|
Object.assign(s, tmp);
|
|
|
|
if (s.roomUpdatedAt) {
|
|
|
|
s.roomUpdatedAt = new Date();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
batch.push(create);
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const { rooms } = store.getState().room;
|
|
|
|
if (tmp.lastMessage && !rooms.includes(tmp.rid)) {
|
|
|
|
const lastMessage = buildMessage(tmp.lastMessage);
|
2021-03-15 20:16:34 +00:00
|
|
|
const messagesCollection = db.get('messages');
|
2020-09-11 14:31:38 +00:00
|
|
|
let messageRecord;
|
|
|
|
try {
|
|
|
|
messageRecord = await messagesCollection.find(lastMessage._id);
|
2019-09-16 20:26:32 +00:00
|
|
|
} catch (error) {
|
2019-10-08 12:36:15 +00:00
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
2020-09-11 14:31:38 +00:00
|
|
|
if (messageRecord) {
|
|
|
|
batch.push(
|
|
|
|
messageRecord.prepareUpdate(() => {
|
|
|
|
Object.assign(messageRecord, lastMessage);
|
|
|
|
})
|
|
|
|
);
|
2019-10-08 12:36:15 +00:00
|
|
|
} else {
|
2020-09-11 14:31:38 +00:00
|
|
|
batch.push(
|
|
|
|
messagesCollection.prepareCreate((m) => {
|
|
|
|
m._raw = sanitizedRaw({ id: lastMessage._id }, messagesCollection.schema);
|
|
|
|
m.subscription.id = lastMessage.rid;
|
|
|
|
return Object.assign(m, lastMessage);
|
|
|
|
})
|
|
|
|
);
|
2020-02-05 15:22:29 +00:00
|
|
|
}
|
2020-09-11 14:31:38 +00:00
|
|
|
}
|
2019-10-30 18:31:26 +00:00
|
|
|
|
2020-09-11 14:31:38 +00:00
|
|
|
await db.action(async() => {
|
2019-10-30 18:31:26 +00:00
|
|
|
await db.batch(...batch);
|
2019-09-16 20:26:32 +00:00
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-08-24 19:59:55 +00:00
|
|
|
const getSubQueueId = rid => `SUB-${ rid }`;
|
|
|
|
|
|
|
|
const getRoomQueueId = rid => `ROOM-${ rid }`;
|
|
|
|
|
|
|
|
const debouncedUpdate = (subscription) => {
|
2020-02-05 15:22:29 +00:00
|
|
|
if (!subTimer) {
|
|
|
|
subTimer = setTimeout(() => {
|
2020-08-24 19:59:55 +00:00
|
|
|
const batch = queue;
|
|
|
|
queue = {};
|
2020-02-05 15:22:29 +00:00
|
|
|
subTimer = null;
|
2020-08-24 19:59:55 +00:00
|
|
|
Object.keys(batch).forEach((key) => {
|
2020-02-17 19:06:18 +00:00
|
|
|
InteractionManager.runAfterInteractions(() => {
|
2020-08-24 19:59:55 +00:00
|
|
|
if (batch[key]) {
|
|
|
|
if (/SUB/.test(key)) {
|
|
|
|
const sub = batch[key];
|
|
|
|
const roomQueueId = getRoomQueueId(sub.rid);
|
|
|
|
const room = batch[roomQueueId];
|
|
|
|
delete batch[roomQueueId];
|
|
|
|
createOrUpdateSubscription(sub, room);
|
|
|
|
} else {
|
|
|
|
const room = batch[key];
|
|
|
|
const subQueueId = getSubQueueId(room._id);
|
|
|
|
const sub = batch[subQueueId];
|
|
|
|
delete batch[subQueueId];
|
|
|
|
createOrUpdateSubscription(sub, room);
|
|
|
|
}
|
|
|
|
}
|
2020-02-17 19:06:18 +00:00
|
|
|
});
|
2020-02-05 15:22:29 +00:00
|
|
|
});
|
|
|
|
}, WINDOW_TIME);
|
|
|
|
}
|
2020-08-24 19:59:55 +00:00
|
|
|
queue[subscription.rid ? getSubQueueId(subscription.rid) : getRoomQueueId(subscription._id)] = subscription;
|
2020-02-05 15:22:29 +00:00
|
|
|
};
|
|
|
|
|
2019-06-26 12:33:56 +00:00
|
|
|
export default function subscribeRooms() {
|
2019-08-14 11:16:59 +00:00
|
|
|
const handleConnection = () => {
|
2019-02-07 20:28:39 +00:00
|
|
|
store.dispatch(roomsRequest());
|
2019-02-14 16:43:56 +00:00
|
|
|
};
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
const handleStreamMessageReceived = protectedFunction(async(ddpMessage) => {
|
|
|
|
const db = database.active;
|
|
|
|
|
2019-06-17 13:57:07 +00:00
|
|
|
// check if the server from variable is the same as the js sdk client
|
|
|
|
if (this.sdk && this.sdk.client && this.sdk.client.host !== subServer) {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-05 20:52:08 +00:00
|
|
|
if (ddpMessage.msg === 'added') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const [type, data] = ddpMessage.fields.args;
|
|
|
|
const [, ev] = ddpMessage.fields.eventName.split('/');
|
2020-06-26 20:45:21 +00:00
|
|
|
if (/userData/.test(ev)) {
|
|
|
|
const [{ diff }] = ddpMessage.fields.args;
|
2020-08-21 13:38:50 +00:00
|
|
|
if (diff?.statusLivechat) {
|
|
|
|
store.dispatch(setUser({ statusLivechat: diff.statusLivechat }));
|
|
|
|
}
|
2020-10-30 17:35:07 +00:00
|
|
|
if (['settings.preferences.showMessageInMainThread'] in diff) {
|
|
|
|
store.dispatch(setUser({ showMessageInMainThread: diff['settings.preferences.showMessageInMainThread'] }));
|
|
|
|
}
|
2020-06-26 20:45:21 +00:00
|
|
|
}
|
2018-12-05 20:52:08 +00:00
|
|
|
if (/subscriptions/.test(ev)) {
|
|
|
|
if (type === 'removed') {
|
2019-02-25 16:23:17 +00:00
|
|
|
try {
|
2021-03-15 20:16:34 +00:00
|
|
|
const subCollection = db.get('subscriptions');
|
2019-09-16 20:26:32 +00:00
|
|
|
const sub = await subCollection.find(data.rid);
|
|
|
|
const messages = await sub.messages.fetch();
|
|
|
|
const threads = await sub.threads.fetch();
|
|
|
|
const threadMessages = await sub.threadMessages.fetch();
|
|
|
|
const messagesToDelete = messages.map(m => m.prepareDestroyPermanently());
|
|
|
|
const threadsToDelete = threads.map(m => m.prepareDestroyPermanently());
|
|
|
|
const threadMessagesToDelete = threadMessages.map(m => m.prepareDestroyPermanently());
|
|
|
|
await db.action(async() => {
|
|
|
|
await db.batch(
|
|
|
|
sub.prepareDestroyPermanently(),
|
|
|
|
...messagesToDelete,
|
|
|
|
...threadsToDelete,
|
2019-10-31 16:21:59 +00:00
|
|
|
...threadMessagesToDelete
|
2019-09-16 20:26:32 +00:00
|
|
|
);
|
2019-02-25 16:23:17 +00:00
|
|
|
});
|
2020-03-06 13:13:24 +00:00
|
|
|
|
|
|
|
const roomState = store.getState().room;
|
|
|
|
// Delete and remove events come from this stream
|
|
|
|
// Here we identify which one was triggered
|
|
|
|
if (data.rid === roomState.rid && roomState.isDeleting) {
|
2020-03-20 16:38:01 +00:00
|
|
|
store.dispatch(removedRoom());
|
2020-03-06 13:13:24 +00:00
|
|
|
} else {
|
2020-06-16 20:32:30 +00:00
|
|
|
EventEmitter.emit('ROOM_REMOVED', { rid: data.rid });
|
2020-03-06 13:13:24 +00:00
|
|
|
}
|
2019-02-25 16:23:17 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-02-25 16:23:17 +00:00
|
|
|
}
|
2018-12-05 20:52:08 +00:00
|
|
|
} else {
|
2020-08-24 19:59:55 +00:00
|
|
|
debouncedUpdate(data);
|
2018-05-07 20:43:26 +00:00
|
|
|
}
|
2018-12-05 20:52:08 +00:00
|
|
|
}
|
|
|
|
if (/rooms/.test(ev)) {
|
2019-09-16 20:26:32 +00:00
|
|
|
if (type === 'updated' || type === 'inserted') {
|
2020-08-24 19:59:55 +00:00
|
|
|
debouncedUpdate(data);
|
2018-05-07 20:43:26 +00:00
|
|
|
}
|
2018-12-05 20:52:08 +00:00
|
|
|
}
|
|
|
|
if (/message/.test(ev)) {
|
|
|
|
const [args] = ddpMessage.fields.args;
|
|
|
|
const _id = random(17);
|
|
|
|
const message = {
|
|
|
|
_id,
|
|
|
|
rid: args.rid,
|
|
|
|
msg: args.msg,
|
2020-02-11 14:01:35 +00:00
|
|
|
blocks: args.blocks,
|
2018-12-05 20:52:08 +00:00
|
|
|
ts: new Date(),
|
|
|
|
_updatedAt: new Date(),
|
|
|
|
status: messagesStatus.SENT,
|
|
|
|
u: {
|
2018-05-23 13:39:18 +00:00
|
|
|
_id,
|
2018-12-05 20:52:08 +00:00
|
|
|
username: 'rocket.cat'
|
|
|
|
}
|
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
2021-03-15 20:16:34 +00:00
|
|
|
const msgCollection = db.get('messages');
|
2019-09-16 20:26:32 +00:00
|
|
|
await db.action(async() => {
|
|
|
|
await msgCollection.create(protectedFunction((m) => {
|
|
|
|
m._raw = sanitizedRaw({ id: message._id }, msgCollection.schema);
|
|
|
|
m.subscription.id = args.rid;
|
|
|
|
Object.assign(m, message);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
2018-12-05 20:52:08 +00:00
|
|
|
}
|
2019-06-10 16:23:19 +00:00
|
|
|
if (/notification/.test(ev)) {
|
|
|
|
const [notification] = ddpMessage.fields.args;
|
2020-02-12 17:21:11 +00:00
|
|
|
try {
|
2020-09-11 14:31:38 +00:00
|
|
|
const { payload: { rid, message, sender } } = notification;
|
2020-02-21 16:13:05 +00:00
|
|
|
const room = await RocketChat.getRoom(rid);
|
|
|
|
notification.title = RocketChat.getRoomTitle(room);
|
|
|
|
notification.avatar = RocketChat.getRoomAvatar(room);
|
2020-09-11 14:31:38 +00:00
|
|
|
|
|
|
|
// If it's from a encrypted room
|
2020-11-12 14:07:36 +00:00
|
|
|
if (message?.t === E2E_MESSAGE_TYPE) {
|
2020-09-11 14:31:38 +00:00
|
|
|
// Decrypt this message content
|
|
|
|
const { msg } = await Encryption.decryptMessage({ ...message, rid });
|
|
|
|
// If it's a direct the content is the message decrypted
|
|
|
|
if (room.t === 'd') {
|
|
|
|
notification.text = msg;
|
|
|
|
// If it's a private group we should add the sender name
|
|
|
|
} else {
|
|
|
|
notification.text = `${ RocketChat.getSenderName(sender) }: ${ msg }`;
|
|
|
|
}
|
|
|
|
}
|
2020-02-12 17:21:11 +00:00
|
|
|
} catch (e) {
|
2020-09-11 14:31:38 +00:00
|
|
|
log(e);
|
2020-02-12 17:21:11 +00:00
|
|
|
}
|
2020-06-16 20:32:30 +00:00
|
|
|
EventEmitter.emit(INAPP_NOTIFICATION_EMITTER, notification);
|
2019-06-10 16:23:19 +00:00
|
|
|
}
|
2020-02-11 14:01:35 +00:00
|
|
|
if (/uiInteraction/.test(ev)) {
|
|
|
|
const { type: eventType, ...args } = type;
|
|
|
|
handlePayloadUserInteraction(eventType, args);
|
|
|
|
}
|
2020-09-11 14:31:38 +00:00
|
|
|
if (/e2ekeyRequest/.test(ev)) {
|
|
|
|
const [roomId, keyId] = ddpMessage.fields.args;
|
|
|
|
try {
|
|
|
|
await Encryption.provideRoomKeyToUser(keyId, roomId);
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
}
|
2019-02-14 16:43:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const stop = () => {
|
|
|
|
if (connectedListener) {
|
|
|
|
connectedListener.then(removeListener);
|
|
|
|
connectedListener = false;
|
|
|
|
}
|
|
|
|
if (disconnectedListener) {
|
|
|
|
disconnectedListener.then(removeListener);
|
|
|
|
disconnectedListener = false;
|
|
|
|
}
|
|
|
|
if (streamListener) {
|
|
|
|
streamListener.then(removeListener);
|
|
|
|
streamListener = false;
|
|
|
|
}
|
2020-08-24 19:59:55 +00:00
|
|
|
queue = {};
|
2020-02-05 15:22:29 +00:00
|
|
|
if (subTimer) {
|
|
|
|
clearTimeout(subTimer);
|
|
|
|
subTimer = false;
|
|
|
|
}
|
2019-02-14 16:43:56 +00:00
|
|
|
};
|
|
|
|
|
2019-08-14 11:16:59 +00:00
|
|
|
connectedListener = this.sdk.onStreamData('connected', handleConnection);
|
2021-03-15 20:16:34 +00:00
|
|
|
// disconnectedListener = this.sdk.onStreamData('close', handleConnection);
|
2019-02-14 16:43:56 +00:00
|
|
|
streamListener = this.sdk.onStreamData('stream-notify-user', handleStreamMessageReceived);
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
2019-06-17 13:57:07 +00:00
|
|
|
// set the server that started this task
|
|
|
|
subServer = this.sdk.client.host;
|
2019-06-26 12:33:56 +00:00
|
|
|
this.sdk.subscribeNotifyUser().catch(e => console.log(e));
|
|
|
|
|
|
|
|
return {
|
|
|
|
stop: () => stop()
|
|
|
|
};
|
2018-05-18 17:55:08 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-06-26 12:33:56 +00:00
|
|
|
return Promise.reject();
|
2018-05-18 17:55:08 +00:00
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|