From be0e93a25e37fb68bf85e1a3ca03eb87e068b559 Mon Sep 17 00:00:00 2001 From: Rodrigo Nascimento Date: Mon, 21 Jun 2021 00:57:47 -0300 Subject: [PATCH] [FIX] Memory leak generated by Stream Cast usage (#22329) Co-authored-by: Diego Sampaio --- server/stream/streamBroadcast.js | 40 ++++++++++++++------------------ 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/server/stream/streamBroadcast.js b/server/stream/streamBroadcast.js index 34965198282..73e0c532b12 100644 --- a/server/stream/streamBroadcast.js +++ b/server/stream/streamBroadcast.js @@ -3,7 +3,6 @@ import { UserPresence } from 'meteor/konecty:user-presence'; import { InstanceStatus } from 'meteor/konecty:multiple-instances-status'; import { check } from 'meteor/check'; import { DDP } from 'meteor/ddp'; -import { DDPCommon } from 'meteor/ddp-common'; import { Logger, LoggerManager } from '../../app/logger'; import { hasPermission } from '../../app/authorization'; @@ -172,31 +171,28 @@ function startStreamCastBroadcast(value) { return authorizeConnection(instance); }; - connection._stream.on('message', function(raw_msg) { - const msg = DDPCommon.parseDDP(raw_msg); - if (!msg || msg.msg !== 'changed' || !msg.collection || !msg.fields) { - return; - } - - const { streamName, eventName, args } = msg.fields; + connection.registerStore('broadcast-stream', { + update({ fields }) { + const { streamName, eventName, args } = fields; - if (!streamName || !eventName || !args) { - return; - } + if (!streamName || !eventName || !args) { + return; + } - if (connection.broadcastAuth !== true) { - return 'not-authorized'; - } + if (connection.broadcastAuth !== true) { + return 'not-authorized'; + } - const instance = StreamerCentral.instances[streamName]; - if (!instance) { - return 'stream-not-exists'; - } + const instance = StreamerCentral.instances[streamName]; + if (!instance) { + return 'stream-not-exists'; + } - if (instance.serverOnly) { - return instance.__emit(eventName, ...args); - } - return instance._emit(eventName, args); + if (instance.serverOnly) { + return instance.__emit(eventName, ...args); + } + return instance._emit(eventName, args); + }, }); return connection.subscribe('stream');