JavaScript Pusher.com - how to use channels pusher channels react,pusher channels pricing,pusher channels vs beams,

I'm building a web app where users can connect to each other and chat. So each chat holds two users. I'm having some general questions concerning Pusher API, (http://pusher.com).

First question. Pusher lets you have 20 concurrent connection for free - does that mean I can have 10 ongoing chats at the same time? (Each chat is between two clients.)

Second question. How should I structure my channels? Should there be one channel per chat? (So 10 channels if there were 10 chats going on.) What would be the best way?

Answer:1

Does that mean I can have 10 ongoing chats at the same time?

You can actually have much more than that. you will have 10 if a person can speak ONLY to one person, however you would be limited by the number of messages in the plan.

How should I structure my channels? Should there be one channel per chat?

It depends if you care about knowing : who's online at all time, and if you want to reduce the number of presence messages spent by Pusher to optimise your plan.

Option 1 :

Each user subscribes to a channel named after him and listens to its events.

user1 will subscribe to presence-user1 channel and bind to the *message_received* event on this channel :

var channel = pusher.subscribe('user1');

channel.bind('message_received', function(message){ 
    console.log('Message received : ');
    console.log(message);
});

When user1 wants to contact user2 they simply need to trigger a *message_received* and pass to it the message and some metadata :

var channel2 = pusher.subscribe('user2');

channel2.trigger('message_received',{
    message:'hey', 
    sender:'user1',
    sent_on:helpers.date() 
});

Pusher have very good documentation and a very neat api here's the page where they talk about events

Since we're using a presence channel here you can get presence information about the users you care about as well.

[EDIT] Note that with this way all users subscribed to the user1 channel will be notified about the messages sent on his channel and this a suboptimal way to do it ! A better way to do it would be to create channels between each two users. There are many ways to architect your app, but I think the previous code should give you a basic idea.

Option 2 :

Create a room 'presence-all'. To which every user connects, then send private messages via 'namespaced events' so for example, user1 would bind to user1:message_received on the presence_all channel. The problem with that approach is the overhead, however if you're not expecting heavy traffic you can use this one as it is much more straight forward to code.

Or create a hybrid approach between both one for presence only and one for exchanging messages. You should check [https://pusher.tenderapp.com/kb/accountsbillingplanspricing/how-is-my-message-count-calculated][this] Pusher explain in detail how they price their messaging.

I hope this helps !

Answer:2

I have a list of bootstrap component class="list-group" I have a folder of videos/category, I want to when I click on a category, the list updates without loading a page (by changing the path). Have ...

I have a list of bootstrap component class="list-group" I have a folder of videos/category, I want to when I click on a category, the list updates without loading a page (by changing the path). Have ...

  1. dynamic list html javascript
  2. dynamic list html
  3. dynamic list html jquery
  4. dynamic list html c#
  5. dynamic drop down list html
  6. dynamic search list html
  7. create dynamic list html
  8. dynamic select list html
  9. dynamic checkbox list html
  10. dynamic unordered list html
  11. dynamic list filter html
  12. dynamic list display html
  13. dynamic list data html
  14. dynamic drop down list html form
  15. dynamic drop down list html javascript
  16. dynamic drop down list html jquery
  17. dynamic list view in html
  18. dynamic drop down list html python
  19. dynamic drop down list html php
  20. dynamic drop down list html w3schools

I have a object in my HTML site which I expand/add to with a little JavaScript bit (below) on button click. Can I refresh the dropdown/select on it's own to show the new choices automaticaly or can ...

I have a object in my HTML site which I expand/add to with a little JavaScript bit (below) on button click. Can I refresh the dropdown/select on it's own to show the new choices automaticaly or can ...

I have an XSLT with javascript in it which uses "&lt ;" and "&gt ;" inside for loop <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/...

I have an XSLT with javascript in it which uses "&lt ;" and "&gt ;" inside for loop <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/...

  1. python lxml library
  2. python lxml library install
  3. lxml python library installed on the managed machine
  4. lxml python library ubuntu
  5. lxml python library download
  6. python lxml parser library
  7. lxml python standard library
  8. python install parser library lxml

There are a list of links on a page and some of them are already visited by me. I have to make them invisible after any action(checking a checkbox, clicking button, etc). I tried to use jQuery: $("a:...

There are a list of links on a page and some of them are already visited by me. I have to make them invisible after any action(checking a checkbox, clicking button, etc). I tried to use jQuery: $("a:...

  1. hide visited links
  2. res hide visited links
  3. css hide visited links
  4. javascript hide visited links