Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Does that mean I can have 10 ongoing chats at the same time?</p> </blockquote> <p>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.</p> <blockquote> <p>How should I structure my channels? Should there be one channel per chat?</p> </blockquote> <p>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.</p> <p><strong>Option 1 :</strong></p> <p>Each user subscribes to a channel named after him and listens to its events.</p> <p><em>user1</em> will subscribe to <em>presence-user1</em> channel and bind to the *message_received* event on this channel :</p> <pre><code>var channel = pusher.subscribe('user1'); channel.bind('message_received', function(message){ console.log('Message received : '); console.log(message); }); </code></pre> <p>When <em>user1</em> wants to contact <em>user2</em> they simply need to trigger a *message_received* and pass to it the message and some metadata :</p> <pre><code>var channel2 = pusher.subscribe('user2'); channel2.trigger('message_received',{ message:'hey', sender:'user1', sent_on:helpers.date() }); </code></pre> <p><a href="http://pusher.com" rel="nofollow">Pusher</a> have very good documentation and a very neat api here's <a href="http://pusher.com/docs/client_api_guide/client_events#bind-events" rel="nofollow">the page where they talk about events</a></p> <p>Since we're using a presence channel here you can get presence information about the users you care about as well.</p> <p>[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.</p> <p><strong>Option 2 :</strong></p> <p>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.</p> <p>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.</p> <p>I hope this helps !</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload