jsir 2.4.8 → 2.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deps/room.js +14 -7
- package/package.json +1 -1
package/deps/room.js
CHANGED
|
@@ -118,19 +118,26 @@ function getSelfIP(nodes) {
|
|
|
118
118
|
|
|
119
119
|
async function getTailscaleNodes() {
|
|
120
120
|
let resp = await e(`${tailscalePath} status`);
|
|
121
|
-
let nodes =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
let nodes = {}
|
|
122
|
+
for (let line of resp.split("\n").map(trim)) {
|
|
123
|
+
if (line.indexOf('offline') !== -1) {
|
|
124
|
+
continue
|
|
125
|
+
}
|
|
126
|
+
let ss = line.split(/\s+/);
|
|
127
|
+
if (/^\d+\.\d+\.\d+\.\d+$/.test(ss[0])) {
|
|
128
|
+
nodes[ss[0]] = ss[1]
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return nodes;
|
|
126
132
|
}
|
|
127
133
|
|
|
128
134
|
async function updateRoomInfo() {
|
|
129
|
-
let
|
|
135
|
+
let nodeMap = await getTailscaleNodes();
|
|
136
|
+
let nodes = Object.keys(nodeMap)
|
|
130
137
|
let ip = getSelfIP(nodes)
|
|
131
138
|
await fileJson(roomDataFile, async room => {
|
|
132
139
|
// 设置roomName
|
|
133
|
-
let name = os.hostname();
|
|
140
|
+
let name = nodeMap[ip] || os.hostname();
|
|
134
141
|
if (!vl(room.name) || room.name !== name) {
|
|
135
142
|
room.name = name;
|
|
136
143
|
debug("set roomName", name)
|