Files
kami-parse-server/src/LiveQuery/ParsePubSub.js

38 lines
1.2 KiB
JavaScript
Raw Normal View History

import { loadAdapter } from '../Adapters/AdapterLoader';
import { EventEmitterPubSub } from '../Adapters/PubSub/EventEmitterPubSub';
import { RedisPubSub } from '../Adapters/PubSub/RedisPubSub';
2016-03-10 14:27:00 -08:00
2016-12-07 15:17:05 -08:00
const ParsePubSub = {};
2016-03-10 14:27:00 -08:00
function useRedis(config: any): boolean {
2016-12-07 15:17:05 -08:00
const redisURL = config.redisURL;
2016-03-10 14:27:00 -08:00
return typeof redisURL !== 'undefined' && redisURL !== '';
}
2020-07-13 13:06:52 -05:00
ParsePubSub.createPublisher = function (config: any): any {
2016-03-10 14:27:00 -08:00
if (useRedis(config)) {
return RedisPubSub.createPublisher(config);
2016-03-10 14:27:00 -08:00
} else {
const adapter = loadAdapter(config.pubSubAdapter, EventEmitterPubSub, config);
if (typeof adapter.createPublisher !== 'function') {
throw 'pubSubAdapter should have createPublisher()';
}
return adapter.createPublisher(config);
2016-03-10 14:27:00 -08:00
}
};
2016-03-10 14:27:00 -08:00
2020-07-13 13:06:52 -05:00
ParsePubSub.createSubscriber = function (config: any): void {
2016-03-10 14:27:00 -08:00
if (useRedis(config)) {
return RedisPubSub.createSubscriber(config);
2016-03-10 14:27:00 -08:00
} else {
const adapter = loadAdapter(config.pubSubAdapter, EventEmitterPubSub, config);
if (typeof adapter.createSubscriber !== 'function') {
throw 'pubSubAdapter should have createSubscriber()';
}
return adapter.createSubscriber(config);
2016-03-10 14:27:00 -08:00
}
};
2016-03-10 14:27:00 -08:00
export { ParsePubSub };