Managing the Same Tokbox Sessions Over and Over - javascript

We are creating a video chat web app that is using Tokbox (PHP/JS).
We will have the same 5 "rooms" (sessions) all the time. A user can join one of the 5 rooms where a moderator will be conducting the chat.
We have gone through the hello world demos and made some various test apps and all seems to be working as we need it.
However, my question lies in managing the sessions/ids for our 5 chat rooms.
Is it (A) necessary to create unique session ids dynamically with the server PHP code? Or, since we are only going to have 5 rooms, can we (B) generate the session ids in our account control panel and hard code the session ids for the five rooms into the client side?
Option B, seems pretty straightforward.
Option A, I am thinking we would have to build an interface for the moderators to choose a room and then generate the room's session id when the moderator "activates" the room for users to then join.
Does anybody have any best practices on how to manage Tokbox session ids when you are using the same sessions over and over?
Thank you!

Adam here from the OpenTok team.
It should be fine to just generate the sessionIds once and reuse them (option B). You are not going to be able to hard-code the tokens though, you will still need to generate those with a server-side SDK in your app server. This is because the tokens expire, by default after 24 hours but you can configure that time. You generally want to generate a new token for every user each time they want to connect to a session.

Related

Firebase as backend for mobile app, that has multiple admins/multisite

The problem is the following.
Client wants an app, that can be sold to different users via Play Store and AppStore. This app has to have a backend server, but users should be able to see only the data that belongs to their user. This is so far a simple authentication/permission problem, but it gets trickier.
If we had a single backend with User Accounts with permission to manage only data that belongs to them, then whoever sells the app will have to pay for the Firebase account for customers traffic usage too.
So the client wants to sell a pair of app + backend, where backends monthly fees are paid by the customer.
Is there a way to configure something like that in Firebase, and make it easy and friendly enough for the customers to set up their account from the app on first startup?
This format unmanaged user seperator. Firebase has simple authentication. Is is not useful for multicompany. Seperate database or develop custom backend.
It sounds like a fairly standard white-labelled app. I recommend keeping each of the re-sold apps in a separate project, which makes it trivial to then charge each buyer separately for their usage.

How should i transfer live x and y positions in a MMO like browser game?

my difinition of "MMO" might be a little optimistic (maybe), but i have in mind to create my own online game where other players current (live) position is really important.
From my current reseach i have read that using a database for this matter will draw alot of power from the database and is quite insufficient to this live.
The game will not require to save and location after you logout.
The amount of players needed to be loaded at same time would be 50 players tops, since players will be grouped into diffrent servers / lobby.
So my questions is: How should i most efficient transfer live posistions of other players to other players in a online mulitiplayer browser game?
You should read about "Web Sockets". It is kind of connection that once opened between server side and client side app is does not end. Every moment client can send something, and server can send something without a handshake.
I no pro in web sockets but you will find many free articles and .pdf's on this topic.
If you want to send it to other users think of it like a chat with global room ;)
It's the best what comes to my mind as an example. One user sends a message to server (but in your case repeatedlivly like every 0.5s) and every logged user get's this data to his own browser.

Real-time user notifications from backend with PubNub, scalability, and over 9000 chat rooms

I'm working on a pretty fun web app project that can become rather big, and I have a chance to play around with this handy thing called PubNub as main real-time engine of application.
So it's a web application with Node.js backend, involves potentially huge amount of chat rooms between users and realtime notifications sent to users by backend when some data in DB is updated.
Usually, developing with Sockets.io, I will just subscribe each user to channel of his unique DB id, and also to chanels representing different chat rooms.
This way I can handle chat rooms and authentication on backend and after storing some personal notification in DB I can easily push them to channel named by user id, so if user is online - he gets it, if not - fine, he will see it on next login, notification is already in DB. And theoretically this monstrocity should scale just fine horizontally with help of redis pub/sub.
Thing that worries me about PubNub in this case is scalability. As I obviously have no insight on what is going on in PubNub backend's dark corners, I want to make sure that app is built in the way that it will be prepared to handle some obscure enormously huge amount of simultaneous users.
My question is, what is the best approach to building such a system with PubNub?
Am I correct assuming that it will be better, in need of pushing notification to specific user, to subscribe to this user's pubnub, push note and unsubscribe. As if I will keep all online-user channels open - then there is no point in PubNub instead of websockets on my server, as server will be anyway under load of all of those opened online-user channels and should be scaled just to maintain huge quantity of them.
What about user authorisation? Without involving my backend how can I be sure that user posting some message will not be able to fake his personality and will have exatly the same as he have authenticated inside application?
And generally (and via PubNub) what is the best practice to tackle huge amounts of chats per users? As say during application life each user may accumulate some decent amount of garbage chat rooms that have some users in it, though havn't been touched by anyone for a long time, and users just way too lazy to leave it manually?
Thanks for Your patience in reading this wall of text!
UPDATED Dec 5, 2021
If you are implementing a chat app, please refer to the PubNub Chat use-case documentation for full details. It has new features and UI components that are built upon the PubNub Platform.
UPDATED May 15, 2020
We have some new docs that will explain much of the below in much clearer terms.
And new features that can be applied to many of the questions/answers below:
Message Actions
Message Counts
Batch History (multi-channel message fetch)
Objects (Users, Channels and Memberships Metadata)
NOTE: I've sprinkled some of the above links down in the answers below.
First, let's address this...
Thing that worries me about PubNub, in this case, is scalability. As I
obviously have no insight on what is going on in PubNub backend's dark
corners, I want to make sure that the app is built in a way that it will
be prepared to handle some obscure enormously huge amount of
simultaneous users.
and this...
then there is no point in PubNub instead of WebSockets on my server,
as the server will be anyway under the load of all of those opened online-user
channels and should be scaled just to maintain the huge quantity of them
This is sort of backward because you would use a service like PubNub to ensure that your application scales to handle millions of users. PubNub has thousands of customers that scale to millions of users and 100's of billions of messages. Not knowing how PubNub does this frees you to implement the biz logic of your application.
But I think I get what you are saying. You are under the impression that your server has to be involved in each and every chat room interaction for every user, but that is only partially true. Mostly, your server will be used for authentication, some subscription maintenance (optional), and probably for sending messages out to one, many, or all end users, as required (depends on your requirements).
Here are some attempts to answer your questions although they are kind of a bit all over the place so I will do my best to answer what I think it is you are asking.
Question 1
This question seems to be directed at maintaining lots of subscriptions to channels and the scalability of that.
Generally speaking, every end-user initializes PubNub and subscribes to channels they need to listen to and publish to channels they need to send messages on. Typically, the channels (chat rooms in your case, I assume) they are publishing on are the same channels they are subscribing to, but they are different kinds of use cases. And you can subscribe to thousands of channels at a time (up to 20K per client). If you did this with WebSockets, how would you go about scaling this to millions of users? You would implement and operate (to scale) something similar to PubNub (not easy and not cheap).
Now, if a user is subscribed to a bunch of chat room channels but some or many are stale (user hasn't viewed or posted to in a while), you could have some code on your server (or the client) that monitors the activity of users and unsubscribes them from those stale channels. This is possible using channels groups. Each end-user would have their own channel group that contains all the channels they are listening to. And the client code or the server code and add and remove channels to/from those end users' channel groups.
Question 2
UPDATED DOCS: https://www.pubnub.com/docs/platform/security/access-control
Now this question is a bit more clear and focused and is asking about authentication (login) and how to ensure someone is who they say they are and how to handle authorization (what they can and cannot do) and where/who controls this.
The answer is, you control the authentication (login) to prove that the person is what they say they are. Your log-in process checks for a valid username/password and in the user record, you will have a list of access controls for that user. With that, you generate an auth-key that you grant read and/or write access to one or more channels. This grant is a PubNub operation that your server invokes. The auth-key is passed back to the client and the client code initializes PubNub instance using the pub/sub keys and this auth-key that PubNub servers use to check for access based on the channel and the operation being requested (subscribe to this channel, publish to that channel, etc). If the auth-key does not have the proper access, the PubNub server will deny access (403 response).
There's more to all of this but this is a good start. Read up on PubNub Access Manager for the SDK you will be using on our docs page. For example, you can start with the JavaScript SDK Access Manager docs and tutorials.
Question 3
UPDATED DOCS: https://www.pubnub.com/docs/platform/channels/receive#subscribe-to-channels
I believe I answered this sufficiently with question 1 - Channel Groups. Start with the JavaScript SDK Stream Controller (which provides Channel Group feature) docs and tutorials.
I hope I have managed to move you a few steps further along your journey to a highly successful real-time, data stream application using PubNub. Please reply with any additional questions you may still have.
*Answers to your new comments:*
Thanks for your follow-up comments. It is very clear what you are asking now.
I will need to compare chat room timestamp with personal user last-read timestamp for this, so it seems that I need to listen to those channels from back-end and update user's last-reads, or to trust into the front-end, and get timestamps from a user directly
No, you do not have to listen to the channels on your server. Yes, from the client app, you will keep the timestamp of the last received message. When the user comes back online, you use this timestamp to get history for the channels the client was subscribed to. Many have done this successfully and we are going to be releasing some amazing features in the coming months that will simplify this considerably.
pushing real-time notifications to users from the back-end. Do I need to be subscribed to all of my user channels if I want to push notes to them at any time?
You can publish on any channel without actually subscribing to it first. So your server can publish to channels as it needs to.
And as before, keep coming with more questions as you require.
*Great follow-up questions again. Here's what I suggest*
... it makes sense to not request all of those chat rooms from DB and join via pubnub all of them, but rather implement pagination... how user can be aware of new messages that may appear in his old chat rooms?
Again, you can stay subscribed to 20K channels using channel groups. You can subscribe to 10 channel groups with 2K channels per channel group - but I'd recommend just limiting the user to 100 or less because that seems like a sufficient limit to impose in your app. But pick whatever upper limit you want and when the user hits that limit, force them to leave another chat room first or suggest they leave one of the top 10 most inactive, or some algorithm that makes sense for your app.
UPDATED DOCS: https://www.pubnub.com/docs/platform/channels/receive#subscribe-to-channels
Getting the # of missed messages does require a full history fetch, but we are going to be providing improved APIs to make this simpler in the near future. But if the user is registered for push notifications on all these channels, the device would be able to receive these push messages and your app can keep that count locally. We will have a "how to update the badge count in background" article being published soon. You could also use that to keep track of the number of missed messages per channel (chat room).
For now I just want to limit the number of rooms available for users to let's say a hundred and request and join them without pagination.
UPDATED DOCS: https://www.pubnub.com/docs/platform/channels/retrieve
We do have customers that do this without worrying about pagination. They just retrieve history on the 100 channels the device is subscribed to. With the background badge count updater strategy, you will have the advantage to know which channels to fetch from when the app becomes active. I will post the link to that article here once it is published.

PHP/Javascript Web application invite friends

Application Basics:
Not a game
Native / custom AnjuarlJS UI with PHP server-side code
I am loosing my mind here. I have looked around for over a month for a solution and I am finally posting a question for help.
I have a web application that I am building for a friend. This application is built with a JS(AngularJS) front end and a PHP backend. I have been able to get logic in place for facebook login and allowing users to link a facebook account to their local account in my app. The problem item here now is that we want to be able to allow users with facebook tied to their account to be able to invite their facebook friends to also us our website. With this I want to be able to know the app-scoped ID for the users the invite is sent to to be able to automatically associate the users once the invited friend creates and account via the link.
User A wants to invite User B to the application.
System stored ID of user B
User B clicks on the link and creates an account on the application.
System checks User B's facebook id against list of stored invited ID's
If the system finds the user id the application should be able to now associate them as friends in our native database
Sure I could created a url as such : www.app.com/facebookInvite.php?fromUser=123
but this does not allow the situation where User A AND User C invite User B to the application. Does ANYONE have a solution to this situation? I have yet to find an answer that involves not being a game.
(I hope my question doesn't confuse anyone)
Unfortunately, you cannot know and record B's facebook id without B installing your app. This is changed when they introduced app-scoped ids.
I think the only thing you can do is that store the request with id-name pairs and when B installs the app, check the requests table if B's friends has installed the app and they sent a request to B.
For instance,
Lets say Michael (A here) has id 12, and Dwight has id 11.
inviter_id inviter_name invited_token invited_name
12 Michael as1231e67dqd2e Dwight
When Dwight installed the app, he should have Michael as a friend with id 12. You can then check this table if Dwight is invited by his friends (Michael, Mose etc...) Since the names you stored in invited_name are not unique, this may give wrong results.
I hope I understood your question right :)

Node.js/Socket.io realtime webpage push updates

I am looking to implement/add realtime push notification updates from node.js server to browser (client).
I looked into socket.io (http://socket.io/docs/rooms-and-namespaces/)
business requirement is - users will visit a page displaying customer info & their orders. There will be ~10,000 users visiting the page at any given time (all 10,000 could be for different customers or sometimes a user may have opened the same page in 2 or 3 tabs)
When orders flow in to elasticsearch for a customer (my datastore) i want to push notification to users who have that customer's page opened.
Questions:
Is socket.io the correct framework for this case?
Am I correct in understanding I have to use socket.io' rooms functionality to implement this? (each room identifier equals customer ID?)
Is this implementation scalable and would it be memory intensive for 10k users on node.js server?
Thanks!
Yes, but you could consider socksJS as well and write your own simple back-end.
Yes, it's the easiest way if you need authentication.
Worst case scenario you'd need to cluster your socket.io servers and use a back-end adapter. Redis should be fast enough for 10.000 connections.
EDIT: memory will depend on your specific implementation.
Also consider https://github.com/Automattic/socket.io/issues/1393

Categories

Resources