New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@jamsocket/client

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jamsocket/client

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

  • 1.1.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-58.33%
Maintainers
0
Weekly downloads
 
Created
Source

@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 = new Jamsocket({
   account: '[YOUR ACCOUNT]',
   token: '[YOUR TOKEN]',
   service: '[YOUR SERVICE]',
   // during development, you can simply pass { dev: true }
})

const connectResponse = await jamsocket.connect() // returns an instance of ConnectResponse
import { SessionBackend } from '@jamsocket/client'

const sessionBackend = new SessionBackend(connectResponse)

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(connectResponse)
isReady()

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

isReady()

import { SessionBackend } from '@jamsocket/client'

const sessionBackend = new SessionBackend(connectResponse)

const isReady = sessionBackend.isReady()
onReadyPromise

onReadyPromise is a Promise that resolves when the session backend is ready.

import { SessionBackend } from '@jamsocket/client'

const sessionBackend = new SessionBackend(connectResponse)

await sessionBackend.onReadyPromise
onReady()

onReady may be used as an alternative to the onReadyPromise. It may be called with a callback function that is called when the session backend is ready.

import { SessionBackend } from '@jamsocket/client'

const sessionBackend = new SessionBackend(connectResponse)

sessionBackend.onReady(() => {
    // your logic here
})
isTerminated()

isTerminated returns a boolean value that is true if the backend is no longer running.

isTerminated()

import { SessionBackend } from '@jamsocket/client'

const sessionBackend = new SessionBackend(connectResponse)

const isTerminated = sessionBackend.isTerminated()
onTerminatedPromise

onTerminatedPromise is a Promise that resolves when the session backend has stopped running.

import { SessionBackend } from '@jamsocket/client'

const sessionBackend = new SessionBackend(connectResponse)

await sessionBackend.onTerminatedPromise
onTerminated()

onTerminated may be used as an alternative to the onTerminatedPromise. It may be called with a callback function that is called when the session backend has stopped running.

import { SessionBackend } from '@jamsocket/client'

const sessionBackend = new SessionBackend(connectResponse)

sessionBackend.onTerminated(() => {
    // your logic here
})
status()

status returns a Promise that resolves with the backend's current BackendState.

import { SessionBackend } from '@jamsocket/client'

const sessionBackend = new SessionBackend(connectResponse)

const currentState = await sessionBackend.status()
onStatus()

onStatus takes a callback which is called when the backend's status changes. It returns an unsubscribe function that may be called to unsubscribes the callback from the status changes.

import { SessionBackend } from '@jamsocket/client'

const sessionBackend = new SessionBackend(connectResponse)

const unsubcribe = sessionBackend.onStatus((state: BackendState) => {
    // your logic here
})

// later, you can unsubscribe by calling the returned function
unsubscribe()
destroy()

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

import { SessionBackend } from '@jamsocket/client'

const sessionBackend = new SessionBackend(connectResponse)

sessionBackend.destroy()

Types

type ConnectResponse = {
  backend_id: string
  spawned: boolean
  status: BackendStatus
  token: string
  url: string
  secret_token?: string | null
  status_url: string
  ready_url: string
}

type BackendStatus =
  | 'scheduled'
  | 'loading'
  | 'starting'
  | 'waiting'
  | 'ready'
  | 'terminating'
  | 'hard-terminating'
  | 'terminated'

type TerminationKind = 'soft' | 'hard'
type TerminationReason = 'swept' | 'external' | 'keyexpired' | 'lost' | 'startuptimeout' | 'internalerror'

type BackendState =
  | { status: 'scheduled'; time: string }
  | { status: 'loading'; time: string }
  | { status: 'starting'; time: string }
  | { status: 'waiting'; time: string }
  | { status: 'ready'; time: string }
  | { status: 'terminating'; time: string; termination_reason: TerminationReason }
  | { status: 'hard-terminating'; time: string; termination_reason: TerminationReason }
  | {
      status: 'terminated'
      time: string
      termination_reason?: TerminationReason | null
      termination_kind?: TerminationKind | null
      exit_error?: boolean | null
    }

FAQs

Package last updated on 25 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc