Adding chat functionality to your games and apps
Deploy to a hosting service like Vercel and Netlify and have it running in minutes
Chat is one of those things that many need and should be simple, but developers keep reinventing the code for or just buy a service to not mess with it. Then costs balloon… If you do host it yourself, security is always a concern. Worse yet, when chat functionality fails, users notice quickly! What if you could add chat to your games and apps and it was easy? The security is already done for you, scales to meet your needs, and relatively cheap?
We recently created and released a sample app using Momento Topics, our serverless publish and subscribe messaging service, so you don’t have to toil with creating one from scratch. You can take ours, integrate it into your own apps, customize to your heart’s content, or simply pick what you need and leave the rest behind. This example app uses Next.js, a React framework, for the browser app, and uses Momento’s Web SDK to allow direct pub/sub communication from the browser to the Momento Topic service. With this example, there are no websockets, no extra services to host, no intermediary apps, etm. You can deploy it to a hosting service like Vercel または Netlify and have it up, running, and publicly available in minutes!
There are a few key things about this example app and Momento Topics I want to call out.
- This app can support multiple simple “chat rooms,” by using multiple topics. This is important because you can support the creation of chat rooms just by instantiating a new topic client object for Momento Topics. There’s no admin work to create a room, and they are disposable. As always, you are only charged for the amount of data transferred and nothing else.
- This is a secure direct connection from the browser to Momento Topics. No intermediary data services to shuffle data between the browser and Momento services. This solution has a built-in Momento auth token “vending machine” to issue short-lived tokens to browsers for their session and give the user access only to rooms they should have. These tokens time out, can be automatically refreshed if you want, and keep your data and services secure. This same token vending machine could issue tokens to any client, but in this example app, it is a browser that’s connecting to Momento Topics directly.
- The tokens being used by the chat app are narrowly scoped and short-lived. They only grant access to the one chat room and only for 30 minutes, though they can be refreshed automatically as you might notice in the code.
- Using this code, you’re around 80 percent of the way there to an internet scale chat application for your users. I like easy buttons!
If you want to tinker with an easy to start and use chat application to integrate with your games or app, definitely give this example app and Momento Topics a spin.