Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Events or Streams to broadcast messages #254

Closed
engelgabriel opened this issue Jul 1, 2015 · 10 comments
Closed

Use Events or Streams to broadcast messages #254

engelgabriel opened this issue Jul 1, 2015 · 10 comments
Assignees
Milestone

Comments

@engelgabriel
Copy link
Member

The idea is to reduce the need for the merge box, broadcasting all messages of each room, and have the minimongo to update the entire message on the local collection.

Arunoda's Streams looked promising, but it discontinued
http://arunoda.github.io/meteor-streams/
https://github.com/arunoda/meteor-streams/

Maybe we could ask to become the maintained or at least fork it.
arunoda/meteor-streams#21 (comment)

Alternatives:
https://github.com/raix/Meteor-EventDDP
https://github.com/Lepozepo/meteor-streams/

@sampaiodiego
Copy link
Member

done by #311

@coxley
Copy link

coxley commented Aug 15, 2015

Is this something that could be/is exposed for an external app to take advantage? Would be very cool to be able to hack together a real-time feed for a room or something.

@rodrigok
Copy link
Member

@coxley, yes, the current implementation of streams that we are using is based over DDP methods and publications, so any external apps can send streams using methods and receive streams listening for publications.

If you need I can explain more how to do this.

@coxley
Copy link

coxley commented Aug 16, 2015

@rodrigok If you wouldn't mind, it'd be great to learn more about how to do it! :)

@Sing-Li
Copy link
Member

Sing-Li commented Aug 16, 2015

@coxley One example we have - is an external application that uses NO METEOR CODE at all.

Yet, it taps the Rocket.Chat's DDP message firehose, processes, and reintroduces messages back into the system.

It is only about a single page of CoffeeScript code, and dockerized - so it is easy to try and (hopefully) understand.

The repo is here : Rocket.Chat Hubot Adapter

Hope this is helpful :)

@rodrigok
Copy link
Member

If you need to handle streams manually:

// Connect to Rocket.Chat via DDP
connection = DDP.connect('http://localhost:3000');

//// LISTEN EVENT
// Create a new collection to monitor typing events in remote connection
collection = new Meteor.Collection('stream-typing', connection);

// Subscribe to typing events
connection.subscribe('stream-typing');

// Handle events on add of collection and reserve an especial item of
// type subscriptionId to be used with Meteor Calls
collection.find({}).observe({
    added: function(item){
        if (item.type == 'subscriptionId') {
            window.subscriptionId = item._id;
        }
        console.log(item)
    }
});


//// EMIT EVENT
// Call stream on connection passing subscription id and arguments
// first argument must be event name, stream-typing is the stream name
connection.call('stream-typing', subscriptionId, ['typing', {room: 'GENERAL', username: 'rodrigo.rocket.team', start: true}]);

@Sing-Li
Copy link
Member

Sing-Li commented Aug 17, 2015

@rodrigok captured for future reference ... https://github.com/RocketChat/Rocket.Chat/wiki/Real-time-messaging-APIs 😄

@rodrigok
Copy link
Member

Thanks @Sing-Li, you are awesome :D

@markhorsman
Copy link

Hello everyone. I tried @rodrigok approach but got the following error:

a["{"msg":"nosub","id":"9ZFTePErqMDzvuYyv","error":{"error":404,"reason":"Subscription not found","message":"Subscription not found [404]","errorType":"Meteor.Error"}}"]

Because I never get an subscriptionId, the connection.call line also fails.
It looks like the 'stream-typing' sub does not exist.

Any suggestions?

@krisleech
Copy link

@markhorsman I know very little about this, but I found with stream-messages I could get messages for every room. I'm using Asteroid, not DDP library.

asteroid.subscribe("stream-messages", roomId, 10);

However it seems roomId is ignored and you get all messages.

HappyTobi pushed a commit to HappyTobi/Rocket.Chat that referenced this issue Jul 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants