truehear-audio-library-node 1.0.0
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 +220 -0
- package/binding.gyp +45 -0
- package/dist/domain/audio-device.types.d.ts +240 -0
- package/dist/domain/audio-device.types.d.ts.map +1 -0
- package/dist/domain/audio-device.types.js +13 -0
- package/dist/domain/audio-device.types.js.map +1 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +154 -0
- package/dist/index.js.map +1 -0
- package/include/audio_device_types.h +169 -0
- package/include/ipolicy_config.h +420 -0
- package/include/mmdevice_guids.h +9 -0
- package/include/truehear_audio.h +348 -0
- package/package.json +85 -0
- package/prebuilds/win32-x64/truehear_audio_native.node +0 -0
- package/src/addon.c +612 -0
- package/src/mmdevice_guids.c +8 -0
- package/src/policy_config_guids.c +26 -0
- package/src/truehear_audio_win.c +888 -0
package/src/addon.c
ADDED
|
@@ -0,0 +1,612 @@
|
|
|
1
|
+
#include "truehear_audio.h"
|
|
2
|
+
|
|
3
|
+
#include <node_api.h>
|
|
4
|
+
|
|
5
|
+
#include <stdbool.h>
|
|
6
|
+
#include <stdio.h>
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
#include <string.h>
|
|
9
|
+
|
|
10
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
11
|
+
/* N-API helpers */
|
|
12
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* Convert an N-API status into a JavaScript exception.
|
|
16
|
+
*
|
|
17
|
+
* Most napi_* functions return napi_status.
|
|
18
|
+
* If the status is not napi_ok, something failed while talking to Node.js.
|
|
19
|
+
*/
|
|
20
|
+
static int truehear_napi_check(
|
|
21
|
+
napi_env env,
|
|
22
|
+
napi_status status,
|
|
23
|
+
const char *operation) {
|
|
24
|
+
if (status == napi_ok) {
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const napi_extended_error_info *error_info = NULL;
|
|
29
|
+
napi_get_last_error_info(env, &error_info);
|
|
30
|
+
|
|
31
|
+
const char *details = "Unknown N-API error";
|
|
32
|
+
|
|
33
|
+
if (error_info != NULL && error_info->error_message != NULL) {
|
|
34
|
+
details = error_info->error_message;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
char message[512];
|
|
38
|
+
|
|
39
|
+
snprintf(
|
|
40
|
+
message,
|
|
41
|
+
sizeof(message),
|
|
42
|
+
"%s failed: %s",
|
|
43
|
+
operation,
|
|
44
|
+
details);
|
|
45
|
+
|
|
46
|
+
bool exception_pending = false;
|
|
47
|
+
napi_is_exception_pending(env, &exception_pending);
|
|
48
|
+
|
|
49
|
+
if (!exception_pending) {
|
|
50
|
+
napi_throw_error(env, NULL, message);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
* Throw a TypeError from C.
|
|
58
|
+
*/
|
|
59
|
+
static void truehear_throw_type_error(
|
|
60
|
+
napi_env env,
|
|
61
|
+
const char *message) {
|
|
62
|
+
napi_throw_type_error(env, NULL, message);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/*
|
|
66
|
+
* Throw a normal Error from C.
|
|
67
|
+
*/
|
|
68
|
+
static void truehear_throw_error(
|
|
69
|
+
napi_env env,
|
|
70
|
+
const char *message) {
|
|
71
|
+
napi_throw_error(env, NULL, message);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
75
|
+
/* String helpers */
|
|
76
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
77
|
+
|
|
78
|
+
/*
|
|
79
|
+
* Read a JavaScript string argument into a newly allocated UTF-8 C string.
|
|
80
|
+
*
|
|
81
|
+
* Caller must free the returned pointer.
|
|
82
|
+
*/
|
|
83
|
+
static char *truehear_get_utf8_string(
|
|
84
|
+
napi_env env,
|
|
85
|
+
napi_value value,
|
|
86
|
+
const char *argument_name) {
|
|
87
|
+
napi_valuetype value_type;
|
|
88
|
+
|
|
89
|
+
if (!truehear_napi_check(
|
|
90
|
+
env,
|
|
91
|
+
napi_typeof(env, value, &value_type),
|
|
92
|
+
"napi_typeof")) {
|
|
93
|
+
return NULL;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (value_type != napi_string) {
|
|
97
|
+
char message[256];
|
|
98
|
+
|
|
99
|
+
snprintf(
|
|
100
|
+
message,
|
|
101
|
+
sizeof(message),
|
|
102
|
+
"%s must be a string",
|
|
103
|
+
argument_name);
|
|
104
|
+
|
|
105
|
+
truehear_throw_type_error(env, message);
|
|
106
|
+
return NULL;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
size_t length = 0;
|
|
110
|
+
|
|
111
|
+
if (!truehear_napi_check(
|
|
112
|
+
env,
|
|
113
|
+
napi_get_value_string_utf8(env, value, NULL, 0, &length),
|
|
114
|
+
"napi_get_value_string_utf8(length)")) {
|
|
115
|
+
return NULL;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
char *buffer = (char *)malloc(length + 1);
|
|
119
|
+
|
|
120
|
+
if (buffer == NULL) {
|
|
121
|
+
truehear_throw_error(env, "Failed to allocate string buffer");
|
|
122
|
+
return NULL;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
size_t copied = 0;
|
|
126
|
+
|
|
127
|
+
if (!truehear_napi_check(
|
|
128
|
+
env,
|
|
129
|
+
napi_get_value_string_utf8(env, value, buffer, length + 1, &copied),
|
|
130
|
+
"napi_get_value_string_utf8(value)")) {
|
|
131
|
+
free(buffer);
|
|
132
|
+
return NULL;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return buffer;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
139
|
+
/* Audio type conversion */
|
|
140
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
141
|
+
|
|
142
|
+
/*
|
|
143
|
+
* Convert JavaScript:
|
|
144
|
+
*
|
|
145
|
+
* "playback"
|
|
146
|
+
* "recording"
|
|
147
|
+
*
|
|
148
|
+
* into the C enum:
|
|
149
|
+
*
|
|
150
|
+
* TRUEHEAR_AUDIO_DEVICE_TYPE_PLAYBACK
|
|
151
|
+
* TRUEHEAR_AUDIO_DEVICE_TYPE_RECORDING
|
|
152
|
+
*/
|
|
153
|
+
static int truehear_parse_device_type(
|
|
154
|
+
napi_env env,
|
|
155
|
+
napi_value value,
|
|
156
|
+
TruehearAudioDeviceType *out_type) {
|
|
157
|
+
if (out_type == NULL) {
|
|
158
|
+
truehear_throw_error(env, "out_type pointer is NULL");
|
|
159
|
+
return 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
char *type = truehear_get_utf8_string(env, value, "type");
|
|
163
|
+
|
|
164
|
+
if (type == NULL) {
|
|
165
|
+
return 0;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (strcmp(type, "playback") == 0) {
|
|
169
|
+
*out_type = TRUEHEAR_AUDIO_DEVICE_TYPE_PLAYBACK;
|
|
170
|
+
free(type);
|
|
171
|
+
return 1;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (strcmp(type, "recording") == 0) {
|
|
175
|
+
*out_type = TRUEHEAR_AUDIO_DEVICE_TYPE_RECORDING;
|
|
176
|
+
free(type);
|
|
177
|
+
return 1;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
free(type);
|
|
181
|
+
|
|
182
|
+
truehear_throw_type_error(
|
|
183
|
+
env,
|
|
184
|
+
"type must be either \"playback\" or \"recording\"");
|
|
185
|
+
|
|
186
|
+
return 0;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/*
|
|
190
|
+
* Convert C enum back to JavaScript string.
|
|
191
|
+
*/
|
|
192
|
+
static const char *truehear_device_type_to_string(
|
|
193
|
+
TruehearAudioDeviceType type) {
|
|
194
|
+
switch (type) {
|
|
195
|
+
case TRUEHEAR_AUDIO_DEVICE_TYPE_PLAYBACK:
|
|
196
|
+
return "playback";
|
|
197
|
+
|
|
198
|
+
case TRUEHEAR_AUDIO_DEVICE_TYPE_RECORDING:
|
|
199
|
+
return "recording";
|
|
200
|
+
|
|
201
|
+
default:
|
|
202
|
+
return "unknown";
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
207
|
+
/* JavaScript object helpers */
|
|
208
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
209
|
+
|
|
210
|
+
static int truehear_set_string_property(
|
|
211
|
+
napi_env env,
|
|
212
|
+
napi_value object,
|
|
213
|
+
const char *name,
|
|
214
|
+
const char *value) {
|
|
215
|
+
napi_value js_value;
|
|
216
|
+
|
|
217
|
+
if (value == NULL) {
|
|
218
|
+
value = "";
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (!truehear_napi_check(
|
|
222
|
+
env,
|
|
223
|
+
napi_create_string_utf8(env, value, NAPI_AUTO_LENGTH, &js_value),
|
|
224
|
+
"napi_create_string_utf8")) {
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (!truehear_napi_check(
|
|
229
|
+
env,
|
|
230
|
+
napi_set_named_property(env, object, name, js_value),
|
|
231
|
+
"napi_set_named_property(string)")) {
|
|
232
|
+
return 0;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return 1;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static int truehear_set_boolean_property(
|
|
239
|
+
napi_env env,
|
|
240
|
+
napi_value object,
|
|
241
|
+
const char *name,
|
|
242
|
+
int value) {
|
|
243
|
+
napi_value js_value;
|
|
244
|
+
|
|
245
|
+
if (!truehear_napi_check(
|
|
246
|
+
env,
|
|
247
|
+
napi_get_boolean(env, value ? true : false, &js_value),
|
|
248
|
+
"napi_get_boolean")) {
|
|
249
|
+
return 0;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (!truehear_napi_check(
|
|
253
|
+
env,
|
|
254
|
+
napi_set_named_property(env, object, name, js_value),
|
|
255
|
+
"napi_set_named_property(boolean)")) {
|
|
256
|
+
return 0;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return 1;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/*
|
|
263
|
+
* Convert one C TruehearAudioDeviceInfo into one JS object:
|
|
264
|
+
*
|
|
265
|
+
* {
|
|
266
|
+
* default: boolean,
|
|
267
|
+
* defaultCommunication: boolean,
|
|
268
|
+
* type: 'playback' | 'recording',
|
|
269
|
+
* name: string,
|
|
270
|
+
* id: string
|
|
271
|
+
* }
|
|
272
|
+
*/
|
|
273
|
+
static int truehear_create_js_device_object(
|
|
274
|
+
napi_env env,
|
|
275
|
+
const TruehearAudioDeviceInfo *device,
|
|
276
|
+
napi_value *out_object) {
|
|
277
|
+
if (device == NULL || out_object == NULL) {
|
|
278
|
+
truehear_throw_error(env, "Invalid device object pointer");
|
|
279
|
+
return 0;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
napi_value object;
|
|
283
|
+
|
|
284
|
+
if (!truehear_napi_check(
|
|
285
|
+
env,
|
|
286
|
+
napi_create_object(env, &object),
|
|
287
|
+
"napi_create_object")) {
|
|
288
|
+
return 0;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (!truehear_set_boolean_property(
|
|
292
|
+
env,
|
|
293
|
+
object,
|
|
294
|
+
"default",
|
|
295
|
+
device->is_default)) {
|
|
296
|
+
return 0;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (!truehear_set_boolean_property(
|
|
300
|
+
env,
|
|
301
|
+
object,
|
|
302
|
+
"defaultCommunication",
|
|
303
|
+
device->is_default_communication)) {
|
|
304
|
+
return 0;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (!truehear_set_string_property(
|
|
308
|
+
env,
|
|
309
|
+
object,
|
|
310
|
+
"type",
|
|
311
|
+
truehear_device_type_to_string(device->type))) {
|
|
312
|
+
return 0;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (!truehear_set_string_property(
|
|
316
|
+
env,
|
|
317
|
+
object,
|
|
318
|
+
"name",
|
|
319
|
+
device->name)) {
|
|
320
|
+
return 0;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (!truehear_set_string_property(
|
|
324
|
+
env,
|
|
325
|
+
object,
|
|
326
|
+
"id",
|
|
327
|
+
device->id)) {
|
|
328
|
+
return 0;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
*out_object = object;
|
|
332
|
+
return 1;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
336
|
+
/* JS function: listDevices(type) */
|
|
337
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
338
|
+
|
|
339
|
+
/*
|
|
340
|
+
* JavaScript:
|
|
341
|
+
*
|
|
342
|
+
* listDevices('playback')
|
|
343
|
+
* listDevices('recording')
|
|
344
|
+
*/
|
|
345
|
+
static napi_value truehear_js_list_devices(
|
|
346
|
+
napi_env env,
|
|
347
|
+
napi_callback_info info) {
|
|
348
|
+
size_t argc = 1;
|
|
349
|
+
napi_value argv[1];
|
|
350
|
+
|
|
351
|
+
if (!truehear_napi_check(
|
|
352
|
+
env,
|
|
353
|
+
napi_get_cb_info(env, info, &argc, argv, NULL, NULL),
|
|
354
|
+
"napi_get_cb_info")) {
|
|
355
|
+
return NULL;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (argc < 1) {
|
|
359
|
+
truehear_throw_type_error(env, "listDevices(type) requires 1 argument");
|
|
360
|
+
return NULL;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
TruehearAudioDeviceType type;
|
|
364
|
+
|
|
365
|
+
if (!truehear_parse_device_type(env, argv[0], &type)) {
|
|
366
|
+
return NULL;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
TruehearAudioDeviceInfoList list;
|
|
370
|
+
|
|
371
|
+
int result = truehear_audio_list_devices(type, &list);
|
|
372
|
+
|
|
373
|
+
if (result != 0) {
|
|
374
|
+
truehear_throw_error(env, truehear_audio_get_last_error());
|
|
375
|
+
return NULL;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
napi_value js_array;
|
|
379
|
+
|
|
380
|
+
if (!truehear_napi_check(
|
|
381
|
+
env,
|
|
382
|
+
napi_create_array_with_length(env, (size_t)list.count, &js_array),
|
|
383
|
+
"napi_create_array_with_length")) {
|
|
384
|
+
truehear_audio_free_device_list(&list);
|
|
385
|
+
return NULL;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
for (int i = 0; i < list.count; i++) {
|
|
389
|
+
napi_value js_device;
|
|
390
|
+
|
|
391
|
+
if (!truehear_create_js_device_object(env, &list.items[i], &js_device)) {
|
|
392
|
+
truehear_audio_free_device_list(&list);
|
|
393
|
+
return NULL;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
if (!truehear_napi_check(
|
|
397
|
+
env,
|
|
398
|
+
napi_set_element(env, js_array, (uint32_t)i, js_device),
|
|
399
|
+
"napi_set_element")) {
|
|
400
|
+
truehear_audio_free_device_list(&list);
|
|
401
|
+
return NULL;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
truehear_audio_free_device_list(&list);
|
|
406
|
+
|
|
407
|
+
return js_array;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
411
|
+
/* JS function: setDefaultDevice(type, deviceId) */
|
|
412
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
413
|
+
|
|
414
|
+
/*
|
|
415
|
+
* JavaScript:
|
|
416
|
+
*
|
|
417
|
+
* setDefaultDevice('playback', deviceId)
|
|
418
|
+
* setDefaultDevice('recording', deviceId)
|
|
419
|
+
*/
|
|
420
|
+
static napi_value truehear_js_set_default_device(
|
|
421
|
+
napi_env env,
|
|
422
|
+
napi_callback_info info) {
|
|
423
|
+
size_t argc = 2;
|
|
424
|
+
napi_value argv[2];
|
|
425
|
+
|
|
426
|
+
if (!truehear_napi_check(
|
|
427
|
+
env,
|
|
428
|
+
napi_get_cb_info(env, info, &argc, argv, NULL, NULL),
|
|
429
|
+
"napi_get_cb_info")) {
|
|
430
|
+
return NULL;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
if (argc < 2) {
|
|
434
|
+
truehear_throw_type_error(
|
|
435
|
+
env,
|
|
436
|
+
"setDefaultDevice(type, deviceId) requires 2 arguments");
|
|
437
|
+
return NULL;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
TruehearAudioDeviceType type;
|
|
441
|
+
|
|
442
|
+
if (!truehear_parse_device_type(env, argv[0], &type)) {
|
|
443
|
+
return NULL;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
char *device_id = truehear_get_utf8_string(env, argv[1], "deviceId");
|
|
447
|
+
|
|
448
|
+
if (device_id == NULL) {
|
|
449
|
+
return NULL;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if (device_id[0] == '\0') {
|
|
453
|
+
free(device_id);
|
|
454
|
+
truehear_throw_type_error(env, "deviceId must not be empty");
|
|
455
|
+
return NULL;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
int result = truehear_audio_set_default_device(type, device_id);
|
|
459
|
+
|
|
460
|
+
free(device_id);
|
|
461
|
+
|
|
462
|
+
if (result != 0) {
|
|
463
|
+
truehear_throw_error(env, truehear_audio_get_last_error());
|
|
464
|
+
return NULL;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
napi_value undefined_value;
|
|
468
|
+
|
|
469
|
+
if (!truehear_napi_check(
|
|
470
|
+
env,
|
|
471
|
+
napi_get_undefined(env, &undefined_value),
|
|
472
|
+
"napi_get_undefined")) {
|
|
473
|
+
return NULL;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return undefined_value;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
480
|
+
/* JS function: setDefaultCommunicationDevice(type, deviceId) */
|
|
481
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
482
|
+
|
|
483
|
+
/*
|
|
484
|
+
* JavaScript:
|
|
485
|
+
*
|
|
486
|
+
* setDefaultCommunicationDevice('playback', deviceId)
|
|
487
|
+
* setDefaultCommunicationDevice('recording', deviceId)
|
|
488
|
+
*/
|
|
489
|
+
static napi_value truehear_js_set_default_communication_device(
|
|
490
|
+
napi_env env,
|
|
491
|
+
napi_callback_info info) {
|
|
492
|
+
size_t argc = 2;
|
|
493
|
+
napi_value argv[2];
|
|
494
|
+
|
|
495
|
+
if (!truehear_napi_check(
|
|
496
|
+
env,
|
|
497
|
+
napi_get_cb_info(env, info, &argc, argv, NULL, NULL),
|
|
498
|
+
"napi_get_cb_info")) {
|
|
499
|
+
return NULL;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (argc < 2) {
|
|
503
|
+
truehear_throw_type_error(
|
|
504
|
+
env,
|
|
505
|
+
"setDefaultCommunicationDevice(type, deviceId) requires 2 arguments");
|
|
506
|
+
return NULL;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
TruehearAudioDeviceType type;
|
|
510
|
+
|
|
511
|
+
if (!truehear_parse_device_type(env, argv[0], &type)) {
|
|
512
|
+
return NULL;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
char *device_id = truehear_get_utf8_string(env, argv[1], "deviceId");
|
|
516
|
+
|
|
517
|
+
if (device_id == NULL) {
|
|
518
|
+
return NULL;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (device_id[0] == '\0') {
|
|
522
|
+
free(device_id);
|
|
523
|
+
truehear_throw_type_error(env, "deviceId must not be empty");
|
|
524
|
+
return NULL;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
int result = truehear_audio_set_default_communication_device(type, device_id);
|
|
528
|
+
|
|
529
|
+
free(device_id);
|
|
530
|
+
|
|
531
|
+
if (result != 0) {
|
|
532
|
+
truehear_throw_error(env, truehear_audio_get_last_error());
|
|
533
|
+
return NULL;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
napi_value undefined_value;
|
|
537
|
+
|
|
538
|
+
if (!truehear_napi_check(
|
|
539
|
+
env,
|
|
540
|
+
napi_get_undefined(env, &undefined_value),
|
|
541
|
+
"napi_get_undefined")) {
|
|
542
|
+
return NULL;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return undefined_value;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
549
|
+
/* Module registration */
|
|
550
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
551
|
+
|
|
552
|
+
static int truehear_export_function(
|
|
553
|
+
napi_env env,
|
|
554
|
+
napi_value exports,
|
|
555
|
+
const char *name,
|
|
556
|
+
napi_callback callback) {
|
|
557
|
+
napi_value function;
|
|
558
|
+
|
|
559
|
+
if (!truehear_napi_check(
|
|
560
|
+
env,
|
|
561
|
+
napi_create_function(
|
|
562
|
+
env,
|
|
563
|
+
name,
|
|
564
|
+
NAPI_AUTO_LENGTH,
|
|
565
|
+
callback,
|
|
566
|
+
NULL,
|
|
567
|
+
&function),
|
|
568
|
+
"napi_create_function")) {
|
|
569
|
+
return 0;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
if (!truehear_napi_check(
|
|
573
|
+
env,
|
|
574
|
+
napi_set_named_property(env, exports, name, function),
|
|
575
|
+
"napi_set_named_property(function)")) {
|
|
576
|
+
return 0;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
return 1;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
static napi_value truehear_audio_init(
|
|
583
|
+
napi_env env,
|
|
584
|
+
napi_value exports) {
|
|
585
|
+
if (!truehear_export_function(
|
|
586
|
+
env,
|
|
587
|
+
exports,
|
|
588
|
+
"listDevices",
|
|
589
|
+
truehear_js_list_devices)) {
|
|
590
|
+
return NULL;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
if (!truehear_export_function(
|
|
594
|
+
env,
|
|
595
|
+
exports,
|
|
596
|
+
"setDefaultDevice",
|
|
597
|
+
truehear_js_set_default_device)) {
|
|
598
|
+
return NULL;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
if (!truehear_export_function(
|
|
602
|
+
env,
|
|
603
|
+
exports,
|
|
604
|
+
"setDefaultCommunicationDevice",
|
|
605
|
+
truehear_js_set_default_communication_device)) {
|
|
606
|
+
return NULL;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
return exports;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
NAPI_MODULE(NODE_GYP_MODULE_NAME, truehear_audio_init)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#include <windows.h>
|
|
2
|
+
#include "mmdevice_guids.h"
|
|
3
|
+
|
|
4
|
+
const CLSID CLSID_MMDeviceEnumerator =
|
|
5
|
+
{0xbcde0395, 0xe52f, 0x467c, {0x8e, 0x3d, 0xc4, 0x57, 0x92, 0x91, 0x69, 0x2e}};
|
|
6
|
+
|
|
7
|
+
const IID IID_IMMDeviceEnumerator =
|
|
8
|
+
{0xa95664d2, 0x9614, 0x4f35, {0xa7, 0x46, 0xde, 0x8d, 0xb6, 0x36, 0x17, 0xe6}};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#include <windows.h>
|
|
2
|
+
#include "ipolicy_config.h"
|
|
3
|
+
|
|
4
|
+
const IID IID_IPolicyConfig = {
|
|
5
|
+
0xf8679f50,
|
|
6
|
+
0x850a,
|
|
7
|
+
0x41cf,
|
|
8
|
+
{0x9c, 0x72, 0x43, 0x0f, 0x29, 0x02, 0x90, 0xc8}};
|
|
9
|
+
|
|
10
|
+
const CLSID CLSID_CPolicyConfigClient = {
|
|
11
|
+
0x870af99c,
|
|
12
|
+
0x171d,
|
|
13
|
+
0x4f9e,
|
|
14
|
+
{0xaf, 0x0d, 0xe6, 0x3d, 0xf4, 0x0c, 0x2b, 0xc9}};
|
|
15
|
+
|
|
16
|
+
const IID IID_IPolicyConfigVista = {
|
|
17
|
+
0x568b9108,
|
|
18
|
+
0x44bf,
|
|
19
|
+
0x40b4,
|
|
20
|
+
{0x90, 0x06, 0x86, 0xaf, 0xe5, 0xb5, 0xa6, 0x20}};
|
|
21
|
+
|
|
22
|
+
const CLSID CLSID_CPolicyConfigVistaClient = {
|
|
23
|
+
0x294935ce,
|
|
24
|
+
0xf637,
|
|
25
|
+
0x4e7c,
|
|
26
|
+
{0xa4, 0x1b, 0xab, 0x25, 0x54, 0x60, 0xb8, 0x62}};
|