Home Manual Reference Source
import {Client} from 'zetapush-js/src/client/basic.js'
public class | source

Client

Direct Subclass:

SmartClient, WeakClient

ZetaPush Client to connect

Example:

// Securized client with token based connection
const client = new ZetaPush.Client({
  sandboxId: '<YOUR-SANDBOX-ID>',
  authentication() {
    return ZetaPush.Authentication.weak({
      token: null
   })
  }
})
// Client with authentication based connection
const client = new ZetaPush.Client({
  sandboxId: '<YOUR-SANDBOX-ID>',
  authentication() {
    return ZetaPush.Authentication.simple({
      login: '<USER-LOGIN>',
      password: '<USER-PASSWORD>'
   })
  }
})
// Explicit deploymentId
const clientSimple = new ZetaPush.Client({
  sandboxId: '<YOUR-SANDBOX-ID>',
  authentication() {
    return ZetaPush.Authentication.simple({
      deploymentId: '<YOUR-SIMPLE-AUTHENTICATION-DEPLOYMENT-ID>',
      login: '<USER-LOGIN>',
      password: '<USER-PASSWORD>'
   })
  }
})
const clientWeak = new ZetaPush.Client({
  sandboxId: '<YOUR-SANDBOX-ID>',
  authentication() {
    return ZetaPush.Authentication.weak({
      deploymentId: '<YOUR-WEAK-AUTHENTICATION-DEPLOYMENT-ID>',
      token: '<SESSION-TOKEN>'
   })
  }
})

Constructor Summary

Public Constructor
public

Create a new ZetaPush Client

Method Summary

Public Methods
public

Add a connection listener to handle life cycle connection events

public

Safely connect client to ZetaPush

public

createAsyncMacroService(parameters: {listener: Object, Type: class, deploymentId: string}): Object

Create a promise based service instance

public

createService(parameters: {listener: Object, Type: class, deploymentId: string}): Object

Create a publish/subscribe for a service type

public

Disonnect client from ZetaPush

public

Get the client resource

public

Get the client sandbox id

public

Get server urls list

public

Get the client user id

public
public

Is client connected to ZetaPush

public

Remove a connection status listener

public

setAuthentication(authentication: function(): AbstractHandshake)

Set a new authentication methods

public

Set logging level Valid values are the strings 'error', 'warn', 'info' and 'debug', from less verbose to more verbose.

public

setResource(resource: string)

Set new client resource value

public

unsubscribe(service: Object): *

Remove all subscriptions

Public Constructors

public constructor(config: ClientConfig) source

Create a new ZetaPush Client

Params:

NameTypeAttributeDescription
config ClientConfig

Public Methods

public addConnectionStatusListener(listener: ConnectionStatusListener): number source

Add a connection listener to handle life cycle connection events

Params:

NameTypeAttributeDescription
listener ConnectionStatusListener

Return:

number

handler

public connect() source

Safely connect client to ZetaPush

public createAsyncMacroService(parameters: {listener: Object, Type: class, deploymentId: string}): Object source

Create a promise based service instance

Params:

NameTypeAttributeDescription
parameters {listener: Object, Type: class, deploymentId: string}

Return:

Object

service

Example:

const api = client.createAsyncMacroService({
  Type: WelcomeMacro
})
api.welcome({
  message: Hello'
}).then(({ message }) => {
  console.log(message)
})

public createService(parameters: {listener: Object, Type: class, deploymentId: string}): Object source

Create a publish/subscribe for a service type

Params:

NameTypeAttributeDescription
parameters {listener: Object, Type: class, deploymentId: string}

Return:

Object

service

Example:

const service = client.createService({
  listener: {
    list(message) {
      console.log('Stack list callback', message)
    },
    push(message) {
      console.log('Stack push callback', message)
    }
  },
  Type: ZetaPush.services.Stack
})
service.list({
  stack: '<STACK-ID>'
})
// Explicit deploymentId
// Authentication provide optional deployment id, according to the following convention `${ServiceType.toLowerCase()_0}`
const service = client.createService({
  deploymentId: 'stack_0'
  listener: {
    list(message) {
      console.log('Stack list callback', message)
    },
    push(message) {
      console.log('Stack push callback', message)
    }
  },
  Type: ZetaPush.services.Stack
})
service.list({
  stack: '<STACK-ID>'
})

public disconnect() source

Disonnect client from ZetaPush

public getResource(): string source

Get the client resource

Return:

string

public getSandboxId(): string source

Get the client sandbox id

Return:

string

public getServers(): Promise source

Get server urls list

Return:

Promise

servers

public getUserId(): string source

Get the client user id

Return:

string

public getUserInfo(): * source

Return:

*

public isConnected(): boolean source

Is client connected to ZetaPush

Return:

boolean

public removeConnectionStatusListener(handler: number): * source

Remove a connection status listener

Params:

NameTypeAttributeDescription
handler number

Return:

*

public setAuthentication(authentication: function(): AbstractHandshake) source

Set a new authentication methods

Params:

NameTypeAttributeDescription
authentication function(): AbstractHandshake

public setLogLevel(level: string) source

Set logging level Valid values are the strings 'error', 'warn', 'info' and 'debug', from less verbose to more verbose.

Params:

NameTypeAttributeDescription
level string

public setResource(resource: string) source

Set new client resource value

Params:

NameTypeAttributeDescription
resource string

public unsubscribe(service: Object): * source

Remove all subscriptions

Params:

NameTypeAttributeDescription
service Object

Return:

*