Client
Direct Subclass:
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 |
constructor(config: ClientConfig) Create a new ZetaPush Client |
Method Summary
Public Methods | ||
public |
Add a connection listener to handle life cycle connection events |
|
public |
connect() 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 |
getUserInfo(): * |
|
public |
Is client connected to ZetaPush |
|
public |
removeConnectionStatusListener(handler: number): * Remove a connection status listener |
|
public |
setAuthentication(authentication: function(): AbstractHandshake) Set a new authentication methods |
|
public |
setLogLevel(level: string) 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:
Name | Type | Attribute | Description |
config | ClientConfig |
Public Methods
public addConnectionStatusListener(listener: ConnectionStatusListener): number source
Add a connection listener to handle life cycle connection events
Params:
Name | Type | Attribute | Description |
listener | ConnectionStatusListener |
public createAsyncMacroService(parameters: {listener: Object, Type: class, deploymentId: string}): Object source
Create a promise based service instance
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
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 removeConnectionStatusListener(handler: number): * source
Remove a connection status listener
Params:
Name | Type | Attribute | Description |
handler | number |
Return:
* |
public setAuthentication(authentication: function(): AbstractHandshake) source
Set a new authentication methods
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
level | string |