Installation

npm
yarn
pnpm
bun
npm install teamplay

TeamPlay can run in three different modes. Pick the one that matches your needs for persistence and synchronization:

Modes

  • In-memory (default): in-memory only, no server, no persistence across reloads.
  • Offline Mode: client-only with local persistence (browser or React Native), no server.
  • Server Sync: real-time synchronization with a backend server.

In-memory Mode

By default, TeamPlay runs in in-memory mode. It keeps everything in memory, so your data is not persisted between page reloads. If you want a client-only setup with local persistence, use the Offline Mode.

Offline Mode

Offline Mode persists data locally (browser or React Native) without a server. Use the offline connector:

import connect from 'teamplay/connect-offline'
await connect()

See Offline Mode for details and React Native setup.

Synchronization with Server

To enable synchronization with the server, follow these steps:

Client Setup

Enable the connection on the client somewhere early in your client app:

import connect from 'teamplay/connect'
await connect()

Server Setup

On the server, you need to create the TeamPlay backend and then create a connection handler for WebSockets:

import { createBackend, initConnection } from 'teamplay/server'

const backend = createBackend()
const { upgrade } = initConnection(backend)
server.on('upgrade', upgrade) // Node's 'http' server instance

Database Configuration

By default no extra database setup is needed and the data is gonna be saved into an SQLite file local.db in the root of your project.

You can still use the MongoDB query syntax with aggregations which is emulated using mingo.

  • For production use, it's recommended to use MongoDB. It will be automatically used if you set the environment variable MONGO_URL.
  • When deploying to a cluster with multiple instances, you also have to provide the environment variable REDIS_URL (Redis).
NOTE

TeamPlay's createBackend() is a wrapper around creating a ShareDB's backend. You can instead manually create a ShareDB backend yourself and pass it to initConnection(). ShareDB is re-exported from teamplay/server, you can get it as import { ShareDB } from 'teamplay/server'.

Now that you have TeamPlay installed and configured, you're ready to start using it in your application!