Skip to main content

JavaScript

Ditto's JavaScript SDK can run either in the browser, NodeJS, or Electron environments. React Native support is currently under development. For more information about browser support or NodeJS and Electron support click here.

  1. Add the JS package with either npm or yarn.
# using npmnpm install @dittolive/ditto@1.0.17 --save
# using yarnyarn add @dittolive/ditto@1.0.17
npm install --save @dittolive/ditto# or with yarnyarn add @dittolive/ditto
  1. Import it like any other NPM package in your source and start using it:
import { init, Ditto } from '@dittolive/ditto'
(async () => {  await init() // you need to call this at least once before using any of the Ditto API  const identity = { type: 'onlinePlayground', appID: 'com.example.ditto' }  const ditto = new Ditto(identity, 'playground')})()
info

Need to run NodeJS on a Linux or Raspberry Pi? Make sure to read this.