Home Manual Reference Source
public class | source

Connection

Controller class for managing connection interaction.

Static Method Summary

Static Public Methods
public static

logRPCError(result: Object)

Log an error caught from an RPC call.

Static Private Methods
private static

Logs browser compatibility for required and optional SDK capabilities.

Constructor Summary

Public Constructor
public

constructor(options: Object)

Member Summary

Private Members
private
private
private
private
private
private

Method Summary

Public Methods
public

Add an access token to the given URL.

public

addEventListener(name: string, handler: Function)

Add an event listener.

public

call(rpc: string, args: ...any): Promise

Make an RPC to active current session.

public

Cancel any current streaming audio recording.

public

Ask the server for an OAuth2 token.

public

getUserAuth(auth: BasicAuth | EmailCredentials, organisationId: string): *

Request authentication for a User.

public

Remove an event listener of the websocket connection.

public

Create a connection to the websocket server.

public
Private Methods
private

Perform a HTTP DELETE to the API using authentication.

private

Perform a HTTP GET to the API using authentication.

private

_secureAjaxPost(url: string, formdata: FormData): Promise

Perform a HTTP POST to the API using authentication.

private

fireEvent(name: string, args: [])

Fire an event.

Static Public Methods

public static logRPCError(result: Object) source

Log an error caught from an RPC call.

Params:

NameTypeAttributeDescription
result Object

Error object.

Static Private Methods

private static _sdkCompatibility() source

Logs browser compatibility for required and optional SDK capabilities.

Throw:

Error

In case of compatibility issues.

Public Constructors

public constructor(options: Object) source

Params:

NameTypeAttributeDescription
options Object

Options to configure the connection with. Valid options include:

  • apiUrl - The URL of the REST api.
  • wsUrl - The URL of the Websocket server.
  • oAuth2Token - An OAuth2 token string.
  • adminPrincipal - The username of the admin account.
  • adminPassword - The password of the admin account.

Private Members

private _analysisId: * source

private _connection: * source

private _emitter: * source

private _recognitionId: * source

private _recordingId: * source

private _settings: Object source

Public Methods

public addAccessToken(url: string): string source

Add an access token to the given URL.

Params:

NameTypeAttributeDescription
url string

The URL to add an access token to.

Return:

string

An url with the access token appended.

public addEventListener(name: string, handler: Function) source

Add an event listener. Listens to events emitted from the websocket server connection.

Params:

NameTypeAttributeDescription
name string

Name of the event.

handler Function

Handler function to add.

public call(rpc: string, args: ...any): Promise source

Make an RPC to active current session.

Params:

NameTypeAttributeDescription
rpc string

The RPC to call. It will be prefixed with 'nl.itslanguage.'.

args ...any

Any arguments to pass to the RPC.

Return:

Promise

The result of the call.

public cancelStreaming(recorder: AudioRecorder) source

Cancel any current streaming audio recording.

Params:

NameTypeAttributeDescription
recorder AudioRecorder

The audio recorder currently recording.

public getOauth2Token(auth: BasicAuth | EmailCredentials, scope: string): Promise source

Ask the server for an OAuth2 token.

Params:

NameTypeAttributeDescription
auth BasicAuth | EmailCredentials
  • optional

Auth to obtain credentials from. If omitted we assume impersonation.

scope string
  • optional

The scope which should be available for the requested token. If omitted the current user will be used.

Return:

Promise

Promise containing a access_token, token_type and scope.

Throw:

Promise.<Error>

If the server returned an error.

public getUserAuth(auth: BasicAuth | EmailCredentials, organisationId: string): * source

Request authentication for a User. This will either work for users with BasicAuth or for users with EmailCredentials (EmailAuth).

This method also generates the appropriate scope for the given params.

Params:

NameTypeAttributeDescription
auth BasicAuth | EmailCredentials

Auth to obtain credentials from.

organisationId string
  • optional

Id of the organisation this user is part of.

Return:

*

public removeEventListener(name: string, handler: Function) source

Remove an event listener of the websocket connection.

Params:

NameTypeAttributeDescription
name string

Name of the event.

handler Function

Handler function to remove.

public webSocketConnect() source

Create a connection to the websocket server.

public webSocketDisconnect() source

Private Methods

private _secureAjaxDelete(url: string): Promise source

Perform a HTTP DELETE to the API using authentication.

Params:

NameTypeAttributeDescription
url string

Url to submit to.

Return:

Promise

Promise containing a result.

Throw:

Promise.<Error>

If the server returned an error.

private _secureAjaxGet(url: string): Promise source

Perform a HTTP GET to the API using authentication.

Params:

NameTypeAttributeDescription
url string

Url to retrieve.

Return:

Promise

Promise containing a result.

Throw:

Promise.<Error>

If the server returned an error.

private _secureAjaxPost(url: string, formdata: FormData): Promise source

Perform a HTTP POST to the API using authentication.

Params:

NameTypeAttributeDescription
url string

Url to submit to.

formdata FormData

The form to POST.

Return:

Promise

Promise containing a result.

Throw:

Promise.<Error>

If the server returned an error.

private fireEvent(name: string, args: []) source

Fire an event.

Params:

NameTypeAttributeDescription
name string

Name of the event.

args []

Arguments.