1 | [![NPM version][npm-version-image]][npm-url]
|
2 | [![Document][doc-version-image]][doc-url]
|
3 | [![Build Status][build-status-image]][build-status-url]
|
4 |
|
5 | # ZetaPush JavaScript SDK
|
6 |
|
7 | ## Install
|
8 |
|
9 | From bower
|
10 |
|
11 | ```console
|
12 | bower install zetapush-js --save
|
13 | ```
|
14 |
|
15 | ```html
|
16 | <script src="/bower_components/zetapush-js/dist/zetapush.min.js"></script>
|
17 | ```
|
18 |
|
19 | From npm
|
20 |
|
21 | ```console
|
22 | npm install zetapush-js --save
|
23 | ```
|
24 |
|
25 | ```js
|
26 | import { Client, Authentication, services } from 'zetapush-js'
|
27 | ```
|
28 |
|
29 | From CDN (unpkg recommended)
|
30 |
|
31 | ```html
|
32 | <script src="//unpkg.com/zetapush-js/dist/zetapush.min.js"></script>
|
33 | ```
|
34 |
|
35 | ```js
|
36 | const { Client, Authentication, services } = ZetaPush
|
37 | ```
|
38 |
|
39 | ## Usage
|
40 |
|
41 | ```js
|
42 | // Create new ZetaPush Client
|
43 | const client = new Client({
|
44 | sandboxId: '<YOUR-SANDBOX-ID>',
|
45 | authentication() {
|
46 | return Authentication.weak({
|
47 | token: null
|
48 | })
|
49 | }
|
50 | })
|
51 | // Create a Stack service
|
52 | const service = client.createService({
|
53 | Type: services.Stack,
|
54 | listener: {
|
55 | list(message) {
|
56 | console.log('list callback', message)
|
57 | }
|
58 | }
|
59 | })
|
60 | // Add connection listener
|
61 | client.onConnectionEstablished(() => {
|
62 | // Call service methods
|
63 | service.list({
|
64 | stack: '<YOUR-STACK-ID>'
|
65 | })
|
66 | })
|
67 | // Connect client to ZetaPush BaaS
|
68 | client.connect()
|
69 | ```
|
70 |
|
71 | ## Any questions?
|
72 |
|
73 | * :warning: ZetaPush v1.x users? Please check [Migration Guide](./docs/MIGRATION.md)
|
74 | * [Frequently Asked Questions](./docs/FAQ.md)
|
75 |
|
76 | [npm-version-image]: http://img.shields.io/npm/v/zetapush-js.svg?style=flat-square
|
77 | [npm-url]: https://npmjs.org/package/zetapush-js
|
78 |
|
79 | [doc-version-image]: http://zetapush.github.io/zetapush-js/badge.svg?t=0
|
80 | [doc-url]: http://zetapush.github.io/zetapush-js/
|
81 |
|
82 | [build-status-image]: http://img.shields.io/travis/zetapush/zetapush-js.svg?style=flat
|
83 | [build-status-url]: http://travis-ci.org/zetapush/zetapush-js
|