July 27, 2023
-
2
Min Read

Adding chat functionality to your games and apps

Deploy to a hosting service like Vercel and Netlify and have it running in minutes
Kirk Kirkconnell
Matt Straathof
Headshot of the blog author
by
Kirk Kirkconnell
,
Matt Straathof
,
by
Kirk Kirkconnell
by
Matt Straathof
green squirrel logo for momento
Kirk Kirkconnell
,
Matt Straathof
,
Topics

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 or 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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.

For more information, check out our documentation on Momento Topics, Momento’s auth token security, and Momento Auth API this app is built with.
Kirk Kirkconnell
Matt Straathof
by
Kirk Kirkconnell
,
Matt Straathof
,
by
Kirk Kirkconnell
by
Matt Straathof
green squirrel logo for momento
by
Kirk Kirkconnell
,
Matt Straathof
,
Author
Kirk Kirkconnell

Kirk Kirkconnell is a Principal Database Advocate at Fauna Inc. He is super passionate about technology, helping people build better serverless applications, and NoSQL databases. He has experience from being a developer to working operations on tier 0 applications for Fortune 100 companies. He has most recently worked in various roles for companies such as Couchbase, Redis, and AWS on the Amazon DynamoDB team.

Author
Matt Straathof

Matt is a software engineer originating from Maryland, currently residing in Southern California. He is a full stack engineer who came from Intuit and joined Momento as one of the founding engineers. At Momento, he helped build out their serverless cache infrastructure and is currently leading a team developing the web console for Momento. When not writing code or building home servers, he enjoys mountain biking, skiing, and scuba diving.

Author
Open