You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+86-68Lines changed: 86 additions & 68 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,19 +35,19 @@ Then to build the file bundle for Parse Cloud:
35
35
To import `Pusher`:
36
36
37
37
```js
38
-
var Pusher =require('cloud/modules/node_modules/pusher/parse');
38
+
var Pusher =require("cloud/modules/node_modules/pusher/parse")
39
39
```
40
40
41
41
## Importing
42
42
43
43
It's possible to use pusher-http-node with typescript or javascript.
44
44
45
45
```javascript
46
-
constPusher=require('pusher');
46
+
constPusher=require("pusher")
47
47
```
48
48
49
49
```typescript
50
-
import*asPusherfrom'pusher';
50
+
import*asPusherfrom"pusher"
51
51
```
52
52
53
53
All external APIs should have types in index.d.ts.
@@ -57,41 +57,41 @@ All external APIs should have types in index.d.ts.
57
57
There are 3 ways to configure the client. First one is just using the Pusher constructor:
58
58
59
59
```javascript
60
-
var Pusher =require('pusher');
60
+
var Pusher =require("pusher")
61
61
62
62
var pusher =newPusher({
63
-
appId:'APP_ID',
64
-
key:'APP_KEY',
65
-
secret:'SECRET_KEY',
63
+
appId:"APP_ID",
64
+
key:"APP_KEY",
65
+
secret:"SECRET_KEY",
66
66
useTLS:USE_TLS, // optional, defaults to false
67
-
cluster:'CLUSTER', // if `host` is present, it will override the `cluster` option.
68
-
host:'HOST', // optional, defaults to api.pusherapp.com
67
+
cluster:"CLUSTER", // if `host` is present, it will override the `cluster` option.
68
+
host:"HOST", // optional, defaults to api.pusherapp.com
69
69
port:PORT, // optional, defaults to 80 for non-TLS connections and 443 for TLS connections
70
70
encryptionMasterKeyBase64:ENCRYPTION_MASTER_KEY, // a base64 string which encodes 32 bytes, used to derive the per-channel encryption keys (see below!)
71
-
});
71
+
})
72
72
```
73
73
74
74
For specific clusters, you can use the `forCluster` function. This is the same as using the `cluster` option in the constructor.
75
75
76
76
```javascript
77
-
var Pusher =require('pusher');
77
+
var Pusher =require("pusher")
78
78
79
79
var pusher =Pusher.forCluster("CLUSTER", {
80
-
appId:'APP_ID',
81
-
key:'APP_KEY',
82
-
secret:'SECRET_KEY',
80
+
appId:"APP_ID",
81
+
key:"APP_KEY",
82
+
secret:"SECRET_KEY",
83
83
useTLS:USE_TLS, // optional, defaults to false
84
84
port:PORT, // optional, defaults to 80 for non-TLS connections and 443 for TLS connections
85
85
encryptionMasterKeyBase64:ENCRYPTION_MASTER_KEY, // a base64 string which encodes 32 bytes, used to derive the per-channel encryption keys (see below!)
86
-
});
86
+
})
87
87
```
88
88
89
89
You can also specify auth and endpoint options by passing an URL:
90
90
91
91
```javascript
92
-
var Pusher =require('pusher');
92
+
var Pusher =require("pusher")
93
93
94
-
var pusher =Pusher.forURL("SCHEME://APP_KEY:SECRET_KEY@HOST:PORT/apps/APP_ID");
94
+
var pusher =Pusher.forURL("SCHEME://APP_KEY:SECRET_KEY@HOST:PORT/apps/APP_ID")
95
95
```
96
96
97
97
You can pass the optional second argument with options, as in `forCluster` function.
@@ -104,14 +104,14 @@ variable to such URL, if you have the Pusher addon installed.
104
104
There are a few additional options that can be used in all above methods:
105
105
106
106
```javascript
107
-
var Pusher =require('pusher');
107
+
var Pusher =require("pusher")
108
108
109
109
var pusher =newPusher({
110
110
// you can set other options in any of the 3 ways described above
111
-
proxy:'HTTP_PROXY_URL', // optional, URL to proxy the requests through
111
+
proxy:"HTTP_PROXY_URL", // optional, URL to proxy the requests through
112
112
timeout:TIMEOUT, // optional, timeout for all requests in milliseconds
113
-
keepAlive:KEEP_ALIVE// optional, enables keep-alive, defaults to false
114
-
});
113
+
keepAlive:KEEP_ALIVE,// optional, enables keep-alive, defaults to false
114
+
})
115
115
```
116
116
117
117
## Usage
@@ -134,20 +134,22 @@ In case accessing data for invalid WebHooks, an Pusher.WebHookError exception wi
134
134
135
135
### Publishing events
136
136
137
-
To send an event to one or more channels use the trigger function. Channel names can contain only characters which are alphanumeric, '_' or '-' and have to be at most 200 characters long. Event name can be at most 200 characters long too.
137
+
To send an event to one or more channels use the trigger function. Channel names can contain only characters which are alphanumeric, '\_' or '-' and have to be at most 200 characters long. Event name can be at most 200 characters long too.
You can trigger an event to at most 100 channels at once. Passing more than 100 channels will cause an exception to be thrown.
@@ -157,18 +159,20 @@ You can trigger an event to at most 100 channels at once. Passing more than 100
157
159
If you wish to send multiple events in a single HTTP request, you can pass an array of events to `pusher.triggerBatch`. You can send up to a maximum of 10 events at once.
158
160
159
161
```javascript
160
-
var events = [{
161
-
channel:"channel-1",
162
-
name:"test-event-1",
163
-
data: {message:"hello world"}
164
-
},
165
-
{
166
-
channel:"channel-2",
167
-
name:"test-event-2",
168
-
data: {message:"hello another world"}
169
-
}];
170
-
171
-
pusher.triggerBatch(events);
162
+
var events = [
163
+
{
164
+
channel:"channel-1",
165
+
name:"test-event-1",
166
+
data: { message:"hello world" },
167
+
},
168
+
{
169
+
channel:"channel-2",
170
+
name:"test-event-2",
171
+
data: { message:"hello another world" },
172
+
},
173
+
]
174
+
175
+
pusher.triggerBatch(events)
172
176
```
173
177
174
178
You can trigger a batch of up to 10 events.
@@ -178,8 +182,8 @@ You can trigger a batch of up to 10 events.
178
182
In order to avoid the client that triggered the event from also receiving it, the `trigger` function takes an optional `socketId` parameter. For more informaiton see: <http://pusher.com/docs/publisher_api_guide/publisher_excluding_recipients>.
179
183
180
184
```javascript
181
-
var socketId ='1302.1081607';
182
-
pusher.trigger(channel, event, data, socketId);
185
+
var socketId ="1302.1081607"
186
+
pusher.trigger(channel, event, data, socketId)
183
187
```
184
188
185
189
### End-to-end encryption [BETA]
@@ -199,24 +203,26 @@ This library supports end-to-end encryption of your private channels. This means
199
203
200
204
```javascript
201
205
var pusher =newPusher({
202
-
appId:'APP_ID',
203
-
key:'APP_KEY',
204
-
secret:'SECRET_KEY',
206
+
appId:"APP_ID",
207
+
key:"APP_KEY",
208
+
secret:"SECRET_KEY",
205
209
useTLS:true,
206
-
encryptionMasterKeyBase64:'<KEY GENERATED BY PREVIOUS COMMAND>',
207
-
});
210
+
encryptionMasterKeyBase64:"<KEY GENERATED BY PREVIOUS COMMAND>",
211
+
})
208
212
```
209
213
210
214
3. Channels where you wish to use end-to-end encryption should be prefixed with `private-encrypted-`.
211
215
212
216
4. Subscribe to these channels in your client, and you're done! You can verify it is working by checking out the debug console on the [https://dashboard.pusher.com/](dashboard) and seeing the scrambled ciphertext.
213
217
214
-
**Important note: This will __not__ encrypt messages on channels that are not prefixed by `private-encrypted-`.**
218
+
**Important note: This will **not** encrypt messages on channels that are not prefixed by `private-encrypted-`.**
215
219
216
220
**Limitation**: you cannot trigger a single event on multiple channels in a call to `trigger`, e.g.
Rationale: the methods in this library map directly to individual Channels HTTP API requests. If we allowed triggering a single event on multiple channels (some encrypted, some unencrypted), then it would require two API requests: one where the event is encrypted to the encrypted channels, and one where the event is unencrypted for unencrypted channels.
@@ -226,7 +232,7 @@ Rationale: the methods in this library map directly to individual Channels HTTP
226
232
To authorise your users to access private channels on Pusher Channels, you can use the `authenticate` function:
227
233
228
234
```javascript
229
-
var auth =pusher.authenticate(socketId, channel);
235
+
var auth =pusher.authenticate(socketId, channel)
230
236
```
231
237
232
238
For more information see: <http://pusher.com/docs/authenticating_users>
@@ -255,48 +261,54 @@ For more information see: <http://pusher.com/docs/authenticating_users>
255
261
It's possible to query the state of the application using the `pusher.get` function.
The `path` property identifies the resource that the request should be made to and the `params` property should be a map of additional query string key and value pairs.
262
268
263
269
Params can't include following keys:
270
+
264
271
- auth_key
265
272
- auth_timestamp
266
273
- auth_version
267
274
- auth_signature
268
275
- body_md5
269
276
270
277
The following example provides the signature of the callback and an example of parsing the result:
Information on the optional `params` and the structure of the returned JSON is defined in the [REST API reference](http://pusher.com/docs/rest_api#method-get-channels).
Information on the optional `params` option property and the structure of the returned JSON is defined in the [REST API reference](http://pusher.com/docs/rest_api#method-get-channel).
The `channel_name` in the path must be a [presence channel](http://pusher.com/docs/presence). The structure of the returned JSON is defined in the [REST API reference](http://pusher.com/docs/rest_api#method-get-users).
@@ -306,16 +318,18 @@ The `channel_name` in the path must be a [presence channel](http://pusher.com/do
306
318
The library provides a simple helper for WebHooks, which can be accessed via Pusher instances:
307
319
308
320
```javascript
309
-
var webhook =pusher.webhook(request);
321
+
var webhook =pusher.webhook(request)
310
322
```
311
323
312
324
Requests must expose following fields:
325
+
313
326
- headers - object with request headers indexed by lowercase header names
314
327
- rawBody - string with the WebHook request body
315
328
316
329
Since neither Node.js nor express provide the body in the request, your application needs to read it and assign to the request object. See examples/webhook_endpoint.js for a simple webhook endpoint implementation using the express framework.
317
330
318
331
Headers object must contain following headers:
332
+
319
333
- x-pusher-key - application key, sent by Channels
320
334
- x-pusher-signature - WebHook signature, generated by Channels
321
335
- content-type - must be set to application/json, what Channels does
@@ -329,11 +343,14 @@ Validates the content type, body format and signature of the WebHook and returns
329
343
Accepts an optional parameter containing additional application tokens (useful e.g. during migrations):
330
344
331
345
```javascript
332
-
var webhook =pusher.webhook(request);
346
+
var webhook =pusher.webhook(request)
333
347
// will check only the key and secret assigned to the pusher object:
0 commit comments