@jamsocket/client
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

@jamsocket/client

GitHub Repo stars Chat on Discord npm

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

Read the docs here

Installation

npm install @jamsocket/client

Example

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
})

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
}

Readme

Keywords

none

Package Sidebar

Install

npm i @jamsocket/client

Weekly Downloads

10

Version

0.2.3

License

MIT

Unpacked Size

21.6 kB

Total Files

8

Last publish

Collaborators

  • driftingpaul
  • felchang
  • rolyatmax