Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Connection

Connection to the backend.

The standard template is to create a connection first, then use it to wire all UI elements, to add custom callback functions and at last to run Connection.connect to create a WebSocket connection to the backend server (see example below).

The other two essential functions to know about are Connection.on and Connection.emit.

Logging across frontend and backend can be done by emitting log, warn or error, e.g. emit('log', 'Hello World').

var databench = new Databench.Connection();
Databench.ui.wire(databench);


// put custom databench.on() methods here


databench.connect();

Hierarchy

  • Connection

Index

Constructors

constructor

  • new Connection(wsUrl?: undefined | string, requestArgs?: undefined | string, analysisId?: undefined | string): Connection
  • Parameters

    • Optional wsUrl: undefined | string

      URL of WebSocket endpoint or undefined to guess it.

    • Optional requestArgs: undefined | string

      search part of request url or undefined to take from window.location.search.

    • Optional analysisId: undefined | string

      Specify an analysis id or undefined to have one generated. The connection will try to connect to a previously created analysis with that id.

    Returns Connection

Properties

Optional analysesVersion

analysesVersion: undefined | string

Optional analysisId

analysisId: undefined | string

Optional databenchBackendVersion

databenchBackendVersion: undefined | string

errorCB

errorCB: function

Type declaration

    • (message?: undefined | string): void
    • Parameters

      • Optional message: undefined | string

      Returns void

Optional requestArgs

requestArgs: undefined | string

wsUrl

wsUrl: string

Methods

_on_object

  • _on_object(signal: object | object, callback: function): Connection
  • Parameters

    • signal: object | object
    • callback: function
        • (message: any, key?: undefined | string): void
        • Parameters

          • message: any
          • Optional key: undefined | string

          Returns void

    Returns Connection

connect

  • connect(callback?: undefined | function): Connection

disconnect

  • disconnect(): void

emit

  • emit(signalName: string, message?: any): Connection
  • Emit a signal/action to the backend.

    Parameters

    • signalName: string

      A signal name. Usually an action name.

    • Optional message: any

      Payload attached to the action.

    Returns Connection

on

  • on(signal: string | object | object, callback: function): Connection
  • Register a callback that listens for a signal.

    The signal can be a simple string (the name for a signal/action), but it can also be an Object of the form {data: 'current_value'} which would trigger on data actions that are sending a JSON dictionary that contains the key current_value. In this case, the value that is given to the callback function is the value assigned to current_value.

    d.on('data', value => { console.log(value); });
    // If the backend sends an action called 'data' with a message
    // {current_value: 3.0}, this function would log `{current_value: 3.0}`.
    
    d.on({data: 'current_value'}, value => { console.log(value); });
    // If the backend sends an action called 'data' with a
    // message {current_value: 3.0}, this function would log `3.0`.
    // This callback is not triggered when the message does not contain a
    // `current_value` key.
    

    Parameters

    • signal: string | object | object

      Signal name to listen for.

    • callback: function

      A callback function that takes the attached data.

        • (message: any, key?: undefined | string): void
        • Parameters

          • message: any
          • Optional key: undefined | string

          Returns void

    Returns Connection

onProcess

  • onProcess(processID: number, callback: function): Connection
  • Parameters

    • processID: number
    • callback: function
        • (message: any): void
        • Parameters

          • message: any

          Returns void

    Returns Connection

once

  • once(signal: string | object | object): Promise<object>
  • Listen for a signal once.

    Similar to [on] but returns a Promise instead of taking a callback. This is mostly useful for unit tests.

    Parameters

    • signal: string | object | object

      Signal name to listen for.

    Returns Promise<object>

preEmit

  • preEmit(signalName: string, callback: function): Connection
  • Set a pre-emit hook.

    Parameters

    • signalName: string

      A signal name.

    • callback: function

      Callback function.

        • (message: any): any
        • Parameters

          • message: any

          Returns any

    Returns Connection

trigger

  • trigger(signal: string, message?: any): void
  • Trigger all callbacks for this signal with this message.

    Parameters

    • signal: string

      Name of the signal to trigger.

    • Optional message: any

      Payload for the triggered signal.

    Returns void

wsCheckOpen

  • wsCheckOpen(): void

wsOnClose

  • wsOnClose(): void

wsOnMessage

  • wsOnMessage(event: object): void

wsOnOpen

  • wsOnOpen(): void

Static guessWSUrl

  • guessWSUrl(): string

Generated using TypeDoc