Skip to content

Commit 7a58df6

Browse files
f3rnoJacobPlaster
authored andcommitted
(feature) add tiny notifications example to bump travis
1 parent f0e39af commit 7a58df6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

examples/ws2/notifications.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict'
2+
3+
process.env.DEBUG = 'bfx:examples:notifications'
4+
5+
const debug = require('debug')('bfx:examples:notifications')
6+
const bfx = require('../bfx')
7+
const ws = bfx.ws(2)
8+
9+
const run = async () => {
10+
ws.on('error', (err) => {
11+
debug('error: %s', err instanceof Error ? err.stack : err)
12+
})
13+
14+
ws.onNotification({ type: '*' }, (n) => {
15+
debug('recv notification: %j', n)
16+
})
17+
18+
debug('connecting...')
19+
await ws.open()
20+
debug('connected')
21+
await ws.auth()
22+
debug('authenticated, listening for notifications')
23+
}
24+
25+
try {
26+
run()
27+
} catch (e) {
28+
console.log(`error: ${e.stack}`)
29+
}

0 commit comments

Comments
 (0)