@stoprocent/noble 1.11.1 → 1.11.2
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/lib/hci-socket/hci.js
CHANGED
|
@@ -3,7 +3,7 @@ const debug = require('debug')('hci');
|
|
|
3
3
|
const events = require('events');
|
|
4
4
|
const util = require('util');
|
|
5
5
|
|
|
6
|
-
const BluetoothHciSocket = require('@
|
|
6
|
+
const BluetoothHciSocket = require('@stoprocent/bluetooth-hci-socket');
|
|
7
7
|
|
|
8
8
|
const HCI_COMMAND_PKT = 0x01;
|
|
9
9
|
const HCI_ACLDATA_PKT = 0x02;
|
package/package.json
CHANGED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const should = require('should');
|
|
2
|
+
const proxyquire = require('proxyquire').noCallThru();
|
|
3
|
+
const { EventEmitter } = require('events');
|
|
4
|
+
|
|
5
|
+
let chosenPlatform;
|
|
6
|
+
let chosenRelease;
|
|
7
|
+
const platform = () => chosenPlatform;
|
|
8
|
+
const release = () => chosenRelease;
|
|
9
|
+
|
|
10
|
+
class NobleMac {}
|
|
11
|
+
|
|
12
|
+
class NobleWinrt {}
|
|
13
|
+
|
|
14
|
+
const NobleMacImport = proxyquire('../../lib/mac/bindings', {
|
|
15
|
+
'node-gyp-build': () => ({ NobleMac })
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const NobleWinrtImport = proxyquire('../../lib/win/bindings', {
|
|
19
|
+
'node-gyp-build': () => ({ NobleWinrt })
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const WebSocket = require('../../lib/websocket/bindings');
|
|
23
|
+
const NobleBindings = proxyquire('../../lib/distributed/bindings', {
|
|
24
|
+
ws: { Server: EventEmitter }
|
|
25
|
+
});
|
|
26
|
+
const HciNobleBindings = proxyquire('../../lib/hci-socket/bindings', {
|
|
27
|
+
'./hci': EventEmitter
|
|
28
|
+
});
|
|
29
|
+
const resolver = proxyquire('../../lib/resolve-bindings', {
|
|
30
|
+
'./distributed/bindings': NobleBindings,
|
|
31
|
+
'./hci-socket/bindings': HciNobleBindings,
|
|
32
|
+
'./mac/bindings': NobleMacImport,
|
|
33
|
+
'./win/bindings': NobleWinrtImport,
|
|
34
|
+
os: { platform, release }
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('resolve-bindings', () => {
|
|
38
|
+
const OLD_ENV = process.env;
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
// Clone initial environment
|
|
42
|
+
process.env = Object.assign({}, OLD_ENV);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
// Restore initial environment
|
|
47
|
+
process.env = OLD_ENV;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('web socket', () => {
|
|
51
|
+
process.env.NOBLE_WEBSOCKET = true;
|
|
52
|
+
|
|
53
|
+
const bindings = resolver({});
|
|
54
|
+
should(bindings).instanceof(WebSocket);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('distributed', () => {
|
|
58
|
+
process.env.NOBLE_DISTRIBUTED = true;
|
|
59
|
+
|
|
60
|
+
const bindings = resolver({});
|
|
61
|
+
should(bindings).instanceof(NobleBindings);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('mac', () => {
|
|
65
|
+
chosenPlatform = 'darwin';
|
|
66
|
+
|
|
67
|
+
const bindings = resolver({});
|
|
68
|
+
should(bindings).instanceof(NobleMac);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('linux', () => {
|
|
72
|
+
chosenPlatform = 'linux';
|
|
73
|
+
|
|
74
|
+
const bindings = resolver({});
|
|
75
|
+
should(bindings).instanceof(HciNobleBindings);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('freebsd', () => {
|
|
79
|
+
chosenPlatform = 'freebsd';
|
|
80
|
+
|
|
81
|
+
const bindings = resolver({});
|
|
82
|
+
should(bindings).instanceof(HciNobleBindings);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('win32', () => {
|
|
86
|
+
chosenPlatform = 'win32';
|
|
87
|
+
chosenRelease = '10.0.22000';
|
|
88
|
+
|
|
89
|
+
const bindings = resolver({});
|
|
90
|
+
should(bindings).instanceof(NobleWinrt);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('unknwon', () => {
|
|
94
|
+
chosenPlatform = 'unknwon';
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
resolver({});
|
|
98
|
+
} catch (e) {
|
|
99
|
+
should(e).have.property('message', 'Unsupported platform');
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|