Skip to content

Mantil chat example using ngs global NATs network for transport

Notifications You must be signed in to change notification settings

mantil-io/example-ngs-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

example-ngs-chat

Example of NGS and Mantil.

Using example from nats.ws project. All HTML and JavaScript are just slightly modified version of nats.ws chat example.

Instead of posting message to the NATS subject we are sending it to the backend. There we have stored state of all messages. When client connects it gets list of all messages from the backend. Backend is now place to add additional logic, for example to moderate messages.

Backend currently holds chat state in memory so on each Lambda function restart we will start with empty state. For testing purpose this works just fine.

Both backend and client needs credentials to connect to NGS. Backend needs credentials in api/chat/tester.creds file and client in api/chat/tester.creds.

Here is described how to get required tools (ngs, nsc) and how to create NGS free tier account.

Once you have tools (ngs, nsc) installed this will create credentials for tester user and put them in the right place.

nsc add operator -u synadia
nsc add account myaccount
nsc add user tester
nsc generate creds -a myaccount -n tester -o ./tester.creds

cp tester.creds public
cp tester.creds api/chat

To setup new Mantil project:

  1. Create new Mantil project from this as template:
mantil new mychat  --from https://github.com/mantil-io/example-ngs-chat
  1. Create credentials and put the to the right place

  2. Create project stage and open entrypoint

mantil stage new dev
open $(mantil env --url)

About

Mantil chat example using ngs global NATs network for transport

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published