JavaScript/TypeScript library for interacting with session backends and the Jamsocket platform.
Read the docs here
npm install @jamsocket/client
Here's an example of how different parts of Jamsocket's client libraries work together.
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
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
})
import { SessionBackend } from '@jamsocket/client'
const sessionBackend = new SessionBackend(spawnResultUrl, statusUrl)
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
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
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()
type SpawnResult = {
url: string
name: string
readyUrl: string
statusUrl: string
spawned: boolean
}