-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-insight-bitpay.js
39 lines (37 loc) · 1.06 KB
/
test-insight-bitpay.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var urls = ["https://insight.bitpay.com/", "https://www.localbitcoinschain.com/", "https://search.bitaccess.co/"]
var io = require('socket.io-client')
var connected = false
var connect_to_insight = function() {
if (connected === false) {
var url = urls.shift()
if (url != undefined) {
var socket = io(url);
setTimeout(function() {
console.log('trying again...')
if (connected === false) {
socket.disconnect()
connect_to_insight()
}
}, 5000)
socket.on('connect', function() {
console.log('connect!')
connected = true
console.log()
socket.emit('subscribe', 'inv')
});
socket.on('tx', function(data) {
console.log("New transaction received: " + JSON.stringify(data))
})
socket.on('event', function(data) {
console.log('event', data)
});
socket.on('disconnect', function() {
console.log('disconnect!')
});
socket.on('error', function() {
console.log('error!')
});
}
}
}
connect_to_insight()