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

How to trigger an event ? #13

Open
hamxabaig opened this issue Dec 12, 2017 · 9 comments
Open

How to trigger an event ? #13

hamxabaig opened this issue Dec 12, 2017 · 9 comments

Comments

@hamxabaig
Copy link

Hey there, I checked the documentation, seems there is no way i can trigger an event or get the pusher channel so i can trigger events on my own. Is there any way ? Or its not supported at all

@TheRusskiy
Copy link
Owner

@hamxabaig I don't think (correct me if I am wrong) that Pusher supports triggering events at all on client side, only on server, otherwise all your private keys would be exposed.

@hamxabaig
Copy link
Author

@TheRusskiy mmm, It supports check this out

@hamxabaig
Copy link
Author

All we need is channel object returned by subscribe.

@adbalits
Copy link

adbalits commented Dec 12, 2017

@hamxabaig I also needed to trigger client events so just sent a pull request that would allow it.

It would work as follows...

import { getChannel } from 'pusher-redux'

// gets the channel object from the client
var myChannel = getChannel('my-channel-name');

// trigger an event with your args
myChannel.trigger(...);

@hamxabaig
Copy link
Author

@adbalits thats cool, Yes it does make sense for a feature like this 🎉

@TheRusskiy
Copy link
Owner

@adbalits thanks again for taking your time to do the pull request.
@hamxabaig once the pull request is merged you are good?

@hamxabaig
Copy link
Author

@TheRusskiy one more thing is, I've a use case where i need to execute a function after i get the event from pusher-redux. We can do this easily with redux as disptach() returns a promise that i can use. Its this line

config.store.dispatch(pusherAction({ actionType: actionType, channelName: channelName, eventName: eventName, data: data, additionalParams: additionalParams }));

Right now i've forked the repo and added a callback function to the params of subscribe and then using it in the dispatch(..).then(cb)

Do you have some alternative solution to it?

@TheRusskiy
Copy link
Owner

TheRusskiy commented Dec 13, 2017

@hamxabaig
Let me make sure I understand this correctly:
You need to have some 2nd action, after the first has fired?
May be subscribe to that event like this reduxjs/redux#580 (comment) (check if action is coming from pusher-redux)

@hamxabaig
Copy link
Author

@TheRusskiy you understood correctly, I found a way to get this done. Can you release the feature getChannel to npm ?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants