This repository was archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatajo.io.js
More file actions
84 lines (50 loc) · 1.68 KB
/
atajo.io.js
File metadata and controls
84 lines (50 loc) · 1.68 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const io = require('socket.io-client');
const Log = require('./atajo.log');
const Consul = require('./atajo.consul');
const Events = require('./atajo.events');
const path = require('path');
const os = require('os');
global.config = require('./config');
global.log = null;
global.release = null;
class IO {
constructor(release, domain, secret) {
var that = this;
global.release = release;
global.domain = domain;
global.log = new Log(release, config.get("LOGPATH") || path.join(__dirname, 'logs'));
that.consul = new Consul()
this.consul.start().subscribe(
response => {
that.identity = JSON.parse(response.value);
//log.debug("IO:IDENTITY UPDATE : ", that.identity);
if (!this.started) {
this.started = true;
this.connect(domain, secret);
}
},
error => {
log.error("CONSUL UPDATE ERROR : ", error);
},
() => {}
);
this.consul.map(domain);
}
connect(domain, secret) {
var that = this;
let core = that.identity.core[release];
log.debug("CORE IS ", core);
let endpoint = core.protocol + "://" + core.host + ":" + core.port;
let opts = config.get('SOCKET').OPTIONS;
opts.query = {
hostname: os.hostname(),
secret: secret,
domain: domain,
}
log.debug("CONNECTING TO ", endpoint, opts);
that.socket = io.connect(endpoint, opts);
that.events = new Events();
that.events.add(that.socket);
}
}
module.exports = IO;