Frequently Asked Questions
Can I use zetapush-js in a NodeJS Context?
Yes, you have to install ~latest~ (>=3.2.0) version of zetapush-js enable NodeJS support.
const { WeakClient } = require('zetapush-js')
const NodeJSTransports = require('zetapush-cometd/lib/node/Transports')
// Create new ZetaPush Client
const client = new WeakClient({
transports: NodeJSTransports,
sandboxId: '<YOUR-SANDBOX-ID>'
})
// Add connection establised listener
client.onConnectionEstablished(() => {
console.log('onConnectionEstablished')
})
client.connect()
Can I use zetapush-js with TypeScript?
Yes, since 3.1.2 zetapush-js include typings definition.
How to use ES2015 features (const, class, arrow functions, ...) on my project today ?
ZetaPush source code and examples are written in plain ES2015, you can use Babel to transpile your code
How to subscribe and publish to a ZetaPush service ?
ZetaPush Client provide a function createService({ type, listener })
const client = new ZetaPush.Client({ ... })
// Create a service publisher mapping Stack service
const service = client.createService({
type: ZetaPush.services.Stack,
listener: {
// callback fired when a list message is fired by ZetaPush
list(message) {
console.log('list callback', message)
}
}
})
// Request a list
service.list({
stack: '<YOUR-STACK-ID>'
})
How force ZetaPush SDK to use https instead http ?
ZetaPush client allow you to declare a specific apiUrl
const client = new ZetaPush.Client({
forceHttps: true,
sandboxId: '<YOUR-SANDBOX-ID>'
})
How to use ZetaPush with my on-premise backend ?
ZetaPush client allow you to declare a specific apiUrl
const client = new ZetaPush.Client({
apiUrl: '<YOUR-ON-PREMISE-URL>',
sandboxId: '<YOUR-SANDBOX-ID>'
})
How to know my ZetaPush SDK version ?
ZetaPush SDK provide a top level constant VERSION
console.log(ZetaPush.VERSION)
How to change log level ?
ZetaPush Client provide a function setLogLevel
const client = new ZetaPush.Client({
sandboxId: '<YOUR-SANDBOX-ID>'
})
client.setLogLevel('debug')
How to force long polling instead of websocket ?
ZetaPush Client provide an option to specify active transports
const client = new ZetaPush.WeakClient({
sandboxId: 'Y1k3xBDc',
transports: [ZetaPush.TransportTypes.LONG_POLLING]
})
How ZetaPush client call my service without explicit deployment id ?
ZetaPush Client provide optional deployment id, according to the following convention ${ServiceType.toLowerCase()_0}
// Create service with implicit service deployment id
const service = client.createService({
type: ZetaPush.services.Stack,
listener: {
list(message) {
console.log('on stack list', message)
}
}
})
service.list({
stack: '<YOUR-STACK-ID>'
})
In the previous example, deployment id is stack_0
// Create service with explicit service deployment id
const service = client.createService({
deploymentId: 'stack_0',
type: ZetaPush.services.Stack,
listener: {
list(message) {
console.log('on stack list', message)
}
}
})
service.list({
stack: '<YOUR-STACK-ID>'
})