systeminformation 5.9.16 → 5.10.1

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/README.md CHANGED
@@ -62,7 +62,7 @@ Lightweight collection of 50+ functions to retrieve detailed hardware, system an
62
62
 
63
63
  - simple to use
64
64
  - get detailed information about system, cpu, baseboard, battery, memory, disks/filesystem, network, docker, software, services and processes
65
- - supports Linux, macOS, partial Windows, FreeBSD, OpenBSD, NetBSD and SunOS support
65
+ - supports Linux, macOS, partial Windows, FreeBSD, OpenBSD, NetBSD, SunOS and Android support
66
66
  - no npm dependencies
67
67
 
68
68
  **Attention**: this is a `node.js` library. It is supposed to be used as a backend/server-side library and will definitely not work within a browser.
@@ -101,6 +101,7 @@ si.cpu()
101
101
 
102
102
  (last 7 major and minor version releases)
103
103
 
104
+ - Version 5.10.0: basic `android` support
104
105
  - Version 5.9.0: `graphics()` added properties (macOS)
105
106
  - Version 5.8.0: `disksIO()` added waitTime, waitPercent (linux)
106
107
  - Version 5.7.0: `diskLayout()` added S.M.A.R.T for Windows (if installed)
package/lib/audio.js CHANGED
@@ -1,219 +1,219 @@
1
- 'use strict';
2
- // @ts-check
3
- // ==================================================================================
4
- // audio.js
5
- // ----------------------------------------------------------------------------------
6
- // Description: System Information - library
7
- // for Node.js
8
- // Copyright: (c) 2014 - 2021
9
- // Author: Sebastian Hildebrandt
10
- // ----------------------------------------------------------------------------------
11
- // License: MIT
12
- // ==================================================================================
13
- // 16. audio
14
- // ----------------------------------------------------------------------------------
15
-
16
- const exec = require('child_process').exec;
17
- const execSync = require('child_process').execSync;
18
- const util = require('./util');
19
- // const fs = require('fs');
20
-
21
- let _platform = process.platform;
22
-
23
- const _linux = (_platform === 'linux');
24
- const _darwin = (_platform === 'darwin');
25
- const _windows = (_platform === 'win32');
26
- const _freebsd = (_platform === 'freebsd');
27
- const _openbsd = (_platform === 'openbsd');
28
- const _netbsd = (_platform === 'netbsd');
29
- const _sunos = (_platform === 'sunos');
30
-
31
- function parseAudioType(str, input, output) {
32
- let result = '';
33
-
34
- if (str.indexOf('speak') >= 0) { result = 'Speaker'; }
35
- if (str.indexOf('laut') >= 0) { result = 'Speaker'; }
36
- if (str.indexOf('loud') >= 0) { result = 'Speaker'; }
37
- if (str.indexOf('head') >= 0) { result = 'Headset'; }
38
- if (str.indexOf('mic') >= 0) { result = 'Microphone'; }
39
- if (str.indexOf('mikr') >= 0) { result = 'Microphone'; }
40
- if (str.indexOf('phone') >= 0) { result = 'Phone'; }
41
- if (str.indexOf('controll') >= 0) { result = 'Controller'; }
42
- if (str.indexOf('line o') >= 0) { result = 'Line Out'; }
43
- if (str.indexOf('digital o') >= 0) { result = 'Digital Out'; }
44
-
45
- if (!result && output) {
46
- result = 'Speaker';
47
- } else if (!result && input) {
48
- result = 'Microphone';
49
- }
50
- return result;
51
- }
52
-
53
-
54
- function getLinuxAudioPci() {
55
- let cmd = 'lspci -v 2>/dev/null';
56
- let result = [];
57
- try {
58
- const parts = execSync(cmd).toString().split('\n\n');
59
- for (let i = 0; i < parts.length; i++) {
60
- const lines = parts[i].split('\n');
61
- if (lines && lines.length && lines[0].toLowerCase().indexOf('audio') >= 0) {
62
- const audio = {};
63
- audio.slotId = lines[0].split(' ')[0];
64
- audio.driver = util.getValue(lines, 'Kernel driver in use', ':', true) || util.getValue(lines, 'Kernel modules', ':', true);
65
- result.push(audio);
66
- }
67
- }
68
- return result;
69
- } catch (e) {
70
- return result;
71
- }
72
- }
73
-
74
- function parseLinuxAudioPciMM(lines, audioPCI) {
75
- const result = {};
76
- const slotId = util.getValue(lines, 'Slot');
77
-
78
- const pciMatch = audioPCI.filter(function (item) { return item.slotId === slotId; });
79
-
80
- result.id = slotId;
81
- result.name = util.getValue(lines, 'SDevice');
82
- // result.type = util.getValue(lines, 'Class');
83
- result.manufacturer = util.getValue(lines, 'SVendor');
84
- result.revision = util.getValue(lines, 'Rev');
85
- result.driver = pciMatch && pciMatch.length === 1 && pciMatch[0].driver ? pciMatch[0].driver : '';
86
- result.default = null;
87
- result.channel = 'PCIe';
88
- result.type = parseAudioType(result.name, null, null);
89
- result.in = null;
90
- result.out = null;
91
- result.status = 'online';
92
-
93
- return result;
94
- }
95
-
96
- function parseDarwinChannel(str) {
97
- let result = '';
98
-
99
- if (str.indexOf('builtin') >= 0) { result = 'Built-In'; }
100
- if (str.indexOf('extern') >= 0) { result = 'Audio-Jack'; }
101
- if (str.indexOf('hdmi') >= 0) { result = 'HDMI'; }
102
- if (str.indexOf('displayport') >= 0) { result = 'Display-Port'; }
103
- if (str.indexOf('usb') >= 0) { result = 'USB'; }
104
- if (str.indexOf('pci') >= 0) { result = 'PCIe'; }
105
-
106
- return result;
107
- }
108
-
109
- function parseDarwinAudio(audioObject, id) {
110
- const result = {};
111
- const channelStr = ((audioObject.coreaudio_device_transport || '') + ' ' + (audioObject._name || '')).toLowerCase();
112
-
113
- result.id = id;
114
- result.name = audioObject._name;
115
- result.manufacturer = audioObject.coreaudio_device_manufacturer;
116
- result.revision = null;
117
- result.driver = null;
118
- result.default = !!(audioObject.coreaudio_default_audio_input_device || '') || !!(audioObject.coreaudio_default_audio_output_device || '');
119
- result.channel = parseDarwinChannel(channelStr);
120
- result.type = parseAudioType(result.name, !!(audioObject.coreaudio_device_input || ''), !!(audioObject.coreaudio_device_output || ''));
121
- result.in = !!(audioObject.coreaudio_device_input || '');
122
- result.out = !!(audioObject.coreaudio_device_output || '');
123
- result.status = 'online';
124
-
125
- return result;
126
- }
127
-
128
- function parseWindowsAudio(lines) {
129
- const result = {};
130
- const status = util.getValue(lines, 'StatusInfo', ':');
131
- // const description = util.getValue(lines, 'Description', ':');
132
-
133
- result.id = util.getValue(lines, 'DeviceID', ':'); // PNPDeviceID??
134
- result.name = util.getValue(lines, 'name', ':');
135
- result.manufacturer = util.getValue(lines, 'manufacturer', ':');
136
- result.revision = null;
137
- result.driver = null;
138
- result.default = null;
139
- result.channel = null;
140
- result.type = parseAudioType(result.name, null, null);
141
- result.in = null;
142
- result.out = null;
143
- result.status = status;
144
-
145
- return result;
146
- }
147
-
148
- function audio(callback) {
149
-
150
- return new Promise((resolve) => {
151
- process.nextTick(() => {
152
- let result = [];
153
- if (_linux || _freebsd || _openbsd || _netbsd) {
154
- let cmd = 'lspci -vmm 2>/dev/null';
155
- exec(cmd, function (error, stdout) {
156
- // PCI
157
- if (!error) {
158
- const audioPCI = getLinuxAudioPci();
159
- const parts = stdout.toString().split('\n\n');
160
- for (let i = 0; i < parts.length; i++) {
161
- const lines = parts[i].split('\n');
162
- if (util.getValue(lines, 'class', ':', true).toLowerCase().indexOf('audio') >= 0) {
163
- const audio = parseLinuxAudioPciMM(lines, audioPCI);
164
- result.push(audio);
165
- }
166
- }
167
- }
168
- if (callback) {
169
- callback(result);
170
- }
171
- resolve(result);
172
- });
173
- }
174
- if (_darwin) {
175
- let cmd = 'system_profiler SPAudioDataType -json';
176
- exec(cmd, function (error, stdout) {
177
- if (!error) {
178
- try {
179
- const outObj = JSON.parse(stdout.toString());
180
- if (outObj.SPAudioDataType && outObj.SPAudioDataType.length && outObj.SPAudioDataType[0] && outObj.SPAudioDataType[0]['_items'] && outObj.SPAudioDataType[0]['_items'].length) {
181
- for (let i = 0; i < outObj.SPAudioDataType[0]['_items'].length; i++) {
182
- const audio = parseDarwinAudio(outObj.SPAudioDataType[0]['_items'][i], i);
183
- result.push(audio);
184
- }
185
- }
186
- } catch (e) {
187
- util.noop();
188
- }
189
- }
190
- if (callback) {
191
- callback(result);
192
- }
193
- resolve(result);
194
- });
195
- }
196
- if (_windows) {
197
- util.powerShell('Get-WmiObject Win32_SoundDevice | fl *').then((stdout, error) => {
198
- if (!error) {
199
- const parts = stdout.toString().split(/\n\s*\n/);
200
- for (let i = 0; i < parts.length; i++) {
201
- if (util.getValue(parts[i].split('\n'), 'name', ':')) {
202
- result.push(parseWindowsAudio(parts[i].split('\n')));
203
- }
204
- }
205
- }
206
- if (callback) {
207
- callback(result);
208
- }
209
- resolve(result);
210
- });
211
- }
212
- if (_sunos) {
213
- resolve(null);
214
- }
215
- });
216
- });
217
- }
218
-
219
- exports.audio = audio;
1
+ 'use strict';
2
+ // @ts-check
3
+ // ==================================================================================
4
+ // audio.js
5
+ // ----------------------------------------------------------------------------------
6
+ // Description: System Information - library
7
+ // for Node.js
8
+ // Copyright: (c) 2014 - 2022
9
+ // Author: Sebastian Hildebrandt
10
+ // ----------------------------------------------------------------------------------
11
+ // License: MIT
12
+ // ==================================================================================
13
+ // 16. audio
14
+ // ----------------------------------------------------------------------------------
15
+
16
+ const exec = require('child_process').exec;
17
+ const execSync = require('child_process').execSync;
18
+ const util = require('./util');
19
+ // const fs = require('fs');
20
+
21
+ let _platform = process.platform;
22
+
23
+ const _linux = (_platform === 'linux' || _platform === 'android');
24
+ const _darwin = (_platform === 'darwin');
25
+ const _windows = (_platform === 'win32');
26
+ const _freebsd = (_platform === 'freebsd');
27
+ const _openbsd = (_platform === 'openbsd');
28
+ const _netbsd = (_platform === 'netbsd');
29
+ const _sunos = (_platform === 'sunos');
30
+
31
+ function parseAudioType(str, input, output) {
32
+ let result = '';
33
+
34
+ if (str.indexOf('speak') >= 0) { result = 'Speaker'; }
35
+ if (str.indexOf('laut') >= 0) { result = 'Speaker'; }
36
+ if (str.indexOf('loud') >= 0) { result = 'Speaker'; }
37
+ if (str.indexOf('head') >= 0) { result = 'Headset'; }
38
+ if (str.indexOf('mic') >= 0) { result = 'Microphone'; }
39
+ if (str.indexOf('mikr') >= 0) { result = 'Microphone'; }
40
+ if (str.indexOf('phone') >= 0) { result = 'Phone'; }
41
+ if (str.indexOf('controll') >= 0) { result = 'Controller'; }
42
+ if (str.indexOf('line o') >= 0) { result = 'Line Out'; }
43
+ if (str.indexOf('digital o') >= 0) { result = 'Digital Out'; }
44
+
45
+ if (!result && output) {
46
+ result = 'Speaker';
47
+ } else if (!result && input) {
48
+ result = 'Microphone';
49
+ }
50
+ return result;
51
+ }
52
+
53
+
54
+ function getLinuxAudioPci() {
55
+ let cmd = 'lspci -v 2>/dev/null';
56
+ let result = [];
57
+ try {
58
+ const parts = execSync(cmd).toString().split('\n\n');
59
+ for (let i = 0; i < parts.length; i++) {
60
+ const lines = parts[i].split('\n');
61
+ if (lines && lines.length && lines[0].toLowerCase().indexOf('audio') >= 0) {
62
+ const audio = {};
63
+ audio.slotId = lines[0].split(' ')[0];
64
+ audio.driver = util.getValue(lines, 'Kernel driver in use', ':', true) || util.getValue(lines, 'Kernel modules', ':', true);
65
+ result.push(audio);
66
+ }
67
+ }
68
+ return result;
69
+ } catch (e) {
70
+ return result;
71
+ }
72
+ }
73
+
74
+ function parseLinuxAudioPciMM(lines, audioPCI) {
75
+ const result = {};
76
+ const slotId = util.getValue(lines, 'Slot');
77
+
78
+ const pciMatch = audioPCI.filter(function (item) { return item.slotId === slotId; });
79
+
80
+ result.id = slotId;
81
+ result.name = util.getValue(lines, 'SDevice');
82
+ // result.type = util.getValue(lines, 'Class');
83
+ result.manufacturer = util.getValue(lines, 'SVendor');
84
+ result.revision = util.getValue(lines, 'Rev');
85
+ result.driver = pciMatch && pciMatch.length === 1 && pciMatch[0].driver ? pciMatch[0].driver : '';
86
+ result.default = null;
87
+ result.channel = 'PCIe';
88
+ result.type = parseAudioType(result.name, null, null);
89
+ result.in = null;
90
+ result.out = null;
91
+ result.status = 'online';
92
+
93
+ return result;
94
+ }
95
+
96
+ function parseDarwinChannel(str) {
97
+ let result = '';
98
+
99
+ if (str.indexOf('builtin') >= 0) { result = 'Built-In'; }
100
+ if (str.indexOf('extern') >= 0) { result = 'Audio-Jack'; }
101
+ if (str.indexOf('hdmi') >= 0) { result = 'HDMI'; }
102
+ if (str.indexOf('displayport') >= 0) { result = 'Display-Port'; }
103
+ if (str.indexOf('usb') >= 0) { result = 'USB'; }
104
+ if (str.indexOf('pci') >= 0) { result = 'PCIe'; }
105
+
106
+ return result;
107
+ }
108
+
109
+ function parseDarwinAudio(audioObject, id) {
110
+ const result = {};
111
+ const channelStr = ((audioObject.coreaudio_device_transport || '') + ' ' + (audioObject._name || '')).toLowerCase();
112
+
113
+ result.id = id;
114
+ result.name = audioObject._name;
115
+ result.manufacturer = audioObject.coreaudio_device_manufacturer;
116
+ result.revision = null;
117
+ result.driver = null;
118
+ result.default = !!(audioObject.coreaudio_default_audio_input_device || '') || !!(audioObject.coreaudio_default_audio_output_device || '');
119
+ result.channel = parseDarwinChannel(channelStr);
120
+ result.type = parseAudioType(result.name, !!(audioObject.coreaudio_device_input || ''), !!(audioObject.coreaudio_device_output || ''));
121
+ result.in = !!(audioObject.coreaudio_device_input || '');
122
+ result.out = !!(audioObject.coreaudio_device_output || '');
123
+ result.status = 'online';
124
+
125
+ return result;
126
+ }
127
+
128
+ function parseWindowsAudio(lines) {
129
+ const result = {};
130
+ const status = util.getValue(lines, 'StatusInfo', ':');
131
+ // const description = util.getValue(lines, 'Description', ':');
132
+
133
+ result.id = util.getValue(lines, 'DeviceID', ':'); // PNPDeviceID??
134
+ result.name = util.getValue(lines, 'name', ':');
135
+ result.manufacturer = util.getValue(lines, 'manufacturer', ':');
136
+ result.revision = null;
137
+ result.driver = null;
138
+ result.default = null;
139
+ result.channel = null;
140
+ result.type = parseAudioType(result.name, null, null);
141
+ result.in = null;
142
+ result.out = null;
143
+ result.status = status;
144
+
145
+ return result;
146
+ }
147
+
148
+ function audio(callback) {
149
+
150
+ return new Promise((resolve) => {
151
+ process.nextTick(() => {
152
+ let result = [];
153
+ if (_linux || _freebsd || _openbsd || _netbsd) {
154
+ let cmd = 'lspci -vmm 2>/dev/null';
155
+ exec(cmd, function (error, stdout) {
156
+ // PCI
157
+ if (!error) {
158
+ const audioPCI = getLinuxAudioPci();
159
+ const parts = stdout.toString().split('\n\n');
160
+ for (let i = 0; i < parts.length; i++) {
161
+ const lines = parts[i].split('\n');
162
+ if (util.getValue(lines, 'class', ':', true).toLowerCase().indexOf('audio') >= 0) {
163
+ const audio = parseLinuxAudioPciMM(lines, audioPCI);
164
+ result.push(audio);
165
+ }
166
+ }
167
+ }
168
+ if (callback) {
169
+ callback(result);
170
+ }
171
+ resolve(result);
172
+ });
173
+ }
174
+ if (_darwin) {
175
+ let cmd = 'system_profiler SPAudioDataType -json';
176
+ exec(cmd, function (error, stdout) {
177
+ if (!error) {
178
+ try {
179
+ const outObj = JSON.parse(stdout.toString());
180
+ if (outObj.SPAudioDataType && outObj.SPAudioDataType.length && outObj.SPAudioDataType[0] && outObj.SPAudioDataType[0]['_items'] && outObj.SPAudioDataType[0]['_items'].length) {
181
+ for (let i = 0; i < outObj.SPAudioDataType[0]['_items'].length; i++) {
182
+ const audio = parseDarwinAudio(outObj.SPAudioDataType[0]['_items'][i], i);
183
+ result.push(audio);
184
+ }
185
+ }
186
+ } catch (e) {
187
+ util.noop();
188
+ }
189
+ }
190
+ if (callback) {
191
+ callback(result);
192
+ }
193
+ resolve(result);
194
+ });
195
+ }
196
+ if (_windows) {
197
+ util.powerShell('Get-WmiObject Win32_SoundDevice | fl *').then((stdout, error) => {
198
+ if (!error) {
199
+ const parts = stdout.toString().split(/\n\s*\n/);
200
+ for (let i = 0; i < parts.length; i++) {
201
+ if (util.getValue(parts[i].split('\n'), 'name', ':')) {
202
+ result.push(parseWindowsAudio(parts[i].split('\n')));
203
+ }
204
+ }
205
+ }
206
+ if (callback) {
207
+ callback(result);
208
+ }
209
+ resolve(result);
210
+ });
211
+ }
212
+ if (_sunos) {
213
+ resolve(null);
214
+ }
215
+ });
216
+ });
217
+ }
218
+
219
+ exports.audio = audio;