nickoj
1
Hi,
I’m trying to add streaming messages to a Meteor 1.3 app.
I’ve looked at:
http://arunoda.github.io/meteor-streams/
Meteor-streams is obviously dead. Should I add Socket.IO as an npm module and use that or is there another solution I should look into?
Thanks
corvid
2
I had to do this recently. Used an event emitter on the server to stream messages with a null publication.
// some client file.
import {Mongo} from "meteor/mongo";
export const Messages = new Mongo.Collection('_messages');
export default Messages;
then on your server do some null publication. You can combine this with some kind of event emitter instance.
import {Meteor} from "meteor/meteor";
import {Random} from "meteor/random";
import {EventEmitter} from 'events';
const myEmitter = new EventEmitter();
Meteor.publish(null, function () {
// do something for when a message is added.
const onMessage = Meteor.bindEnvironment(data => {
this.added('_messages', Random.id(), { message: data.toString('ascii') });
});
myEmitter.on('message', onMessage);
this.ready();
this.onStop(() => myEmitter.removeListener('message', onMessage));
})