Client Libraries
@jamsocket/client

@jamsocket/client

JavaScript/TypeScript library for interacting with session backends and the Jamsocket platform.

Installation

npm install @jamsocket/client

Example

Here's an example of how different parts of Jamsocket's client libraries work together.

server.tsx
import Jamsocket from '@jamsocket/server'
 
const jamsocket = Jamsocket.init({
   account: '[YOUR ACCOUNT]',
   token: '[YOUR TOKEN]',
   service: '[YOUR SERVICE]',
   // during develpment, you can simply pass { dev: true }
})
 
const spawnResult = await jamsocket.spawn() // returns an instance of SpawnResult
client.ts
import { SessionBackend } from '@jamsocket/client'
 
const sessionBackend = new SessionBackend(spawnResult.url, spawnResult.statusUrl)
 
sessionBackend.isReady() // returns a boolean indicating if the session backend has started and is ready to receive connections
sessionBackend.onReady(() => {
    // do something here once the session backend has reached a Ready status
})

Library Reference

@jamsocket/client

SessionBackend

import { SessionBackend } from '@jamsocket/client'
 
const sessionBackend = new SessionBackend(spawnResultUrl, statusUrl)

isReady()

isReady returns a boolean value that is true if the backend is ready.

isReady()

import { SessionBackend } from '@jamsocket/client'
 
const sessionBackend = new SessionBackend(spawnResultUrl, statusUrl)
 
const isReady = sessionBackend.isReady()

onReady()

onReady takes a callback function that is called when the session backend is ready.

import { SessionBackend } from '@jamsocket/client'
 
const sessionBackend = new SessionBackend(spawnResultUrl, statusUrl)
 
sessionBackend.onReady(() => {
    // your logic here
})

destroy()

destroy terminates your client connection, but it does not terminate the session backend.

import { SessionBackend } from '@jamsocket/client'
 
const sessionBackend = new SessionBackend(spawnResultUrl, statusUrl)
 
sessionBackend.destroy()

Types

type SpawnResult = {
  url: string
  name: string
  readyUrl: string
  statusUrl: string
  spawned: boolean
}
Jamsocket is built by Drifting in Space.