@irdk/usbmux 0.2.0 → 0.2.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/LICENSE +2 -2
- package/README.md +3 -3
- package/dist/usbmux.cjs +317 -0
- package/dist/usbmux.cjs.map +1 -0
- package/dist/usbmux.d.cts +196 -0
- package/dist/usbmux.d.ts +196 -0
- package/dist/usbmux.js +275 -0
- package/dist/usbmux.js.map +1 -0
- package/package.json +12 -6
- package/test/tests.cjs +0 -328
package/test/tests.cjs
DELETED
@@ -1,328 +0,0 @@
|
|
1
|
-
var net = require("net"),
|
2
|
-
should = require("should"),
|
3
|
-
rewire = require("rewire");
|
4
|
-
|
5
|
-
var usbmux = rewire("../dist/usbmux.cjs"),
|
6
|
-
protocol = usbmux.__get__("protocol");
|
7
|
-
|
8
|
-
// tests connect to port 22 on attached ios device (or set env var)
|
9
|
-
var port = process.env.TESTPORT || 22;
|
10
|
-
|
11
|
-
//
|
12
|
-
// TESTS AND EXPECTED RESULTS
|
13
|
-
//
|
14
|
-
|
15
|
-
var tests = {
|
16
|
-
// for testing protocol.listen
|
17
|
-
listen:
|
18
|
-
"gwEAAAEAAAAIAAAAAQAAADw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04Ij8+CjwhRE9DVFlQRSBwbGlzdCBQVUJMSUMgIi0vL0FwcGxlLy9EVEQgUExJU1QgMS4wLy9FTiIgImh0dHA6Ly93d3cuYXBwbGUuY29tL0RURHMvUHJvcGVydHlMaXN0LTEuMC5kdGQiPgo8cGxpc3QgdmVyc2lvbj0iMS4wIj4KICA8ZGljdD4KICAgIDxrZXk+TWVzc2FnZVR5cGU8L2tleT4KICAgIDxzdHJpbmc+TGlzdGVuPC9zdHJpbmc+CiAgICA8a2V5PkNsaWVudFZlcnNpb25TdHJpbmc8L2tleT4KICAgIDxzdHJpbmc+bm9kZS11c2JtdXg8L3N0cmluZz4KICAgIDxrZXk+UHJvZ05hbWU8L2tleT4KICAgIDxzdHJpbmc+bm9kZS11c2JtdXg8L3N0cmluZz4KICA8L2RpY3Q+CjwvcGxpc3Q+",
|
19
|
-
|
20
|
-
// for testing
|
21
|
-
// - protocol.connect(12, 22)
|
22
|
-
// - protocol.connect(21, 1234)
|
23
|
-
connect: {
|
24
|
-
_12_22:
|
25
|
-
"7AEAAAEAAAAIAAAAAQAAADw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04Ij8+CjwhRE9DVFlQRSBwbGlzdCBQVUJMSUMgIi0vL0FwcGxlLy9EVEQgUExJU1QgMS4wLy9FTiIgImh0dHA6Ly93d3cuYXBwbGUuY29tL0RURHMvUHJvcGVydHlMaXN0LTEuMC5kdGQiPgo8cGxpc3QgdmVyc2lvbj0iMS4wIj4KICA8ZGljdD4KICAgIDxrZXk+TWVzc2FnZVR5cGU8L2tleT4KICAgIDxzdHJpbmc+Q29ubmVjdDwvc3RyaW5nPgogICAgPGtleT5DbGllbnRWZXJzaW9uU3RyaW5nPC9rZXk+CiAgICA8c3RyaW5nPm5vZGUtdXNibXV4PC9zdHJpbmc+CiAgICA8a2V5PlByb2dOYW1lPC9rZXk+CiAgICA8c3RyaW5nPm5vZGUtdXNibXV4PC9zdHJpbmc+CiAgICA8a2V5PkRldmljZUlEPC9rZXk+CiAgICA8aW50ZWdlcj4xMjwvaW50ZWdlcj4KICAgIDxrZXk+UG9ydE51bWJlcjwva2V5PgogICAgPGludGVnZXI+NTYzMjwvaW50ZWdlcj4KICA8L2RpY3Q+CjwvcGxpc3Q+",
|
26
|
-
_21_1234:
|
27
|
-
"7QEAAAEAAAAIAAAAAQAAADw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04Ij8+CjwhRE9DVFlQRSBwbGlzdCBQVUJMSUMgIi0vL0FwcGxlLy9EVEQgUExJU1QgMS4wLy9FTiIgImh0dHA6Ly93d3cuYXBwbGUuY29tL0RURHMvUHJvcGVydHlMaXN0LTEuMC5kdGQiPgo8cGxpc3QgdmVyc2lvbj0iMS4wIj4KICA8ZGljdD4KICAgIDxrZXk+TWVzc2FnZVR5cGU8L2tleT4KICAgIDxzdHJpbmc+Q29ubmVjdDwvc3RyaW5nPgogICAgPGtleT5DbGllbnRWZXJzaW9uU3RyaW5nPC9rZXk+CiAgICA8c3RyaW5nPm5vZGUtdXNibXV4PC9zdHJpbmc+CiAgICA8a2V5PlByb2dOYW1lPC9rZXk+CiAgICA8c3RyaW5nPm5vZGUtdXNibXV4PC9zdHJpbmc+CiAgICA8a2V5PkRldmljZUlEPC9rZXk+CiAgICA8aW50ZWdlcj4yMTwvaW50ZWdlcj4KICAgIDxrZXk+UG9ydE51bWJlcjwva2V5PgogICAgPGludGVnZXI+NTM3NjQ8L2ludGVnZXI+CiAgPC9kaWN0Pgo8L3BsaXN0Pg==",
|
28
|
-
},
|
29
|
-
|
30
|
-
// for testing the message parser
|
31
|
-
makeParser: {
|
32
|
-
// a confirmation message
|
33
|
-
confirmation: {
|
34
|
-
msg: {
|
35
|
-
MessageType: "Result",
|
36
|
-
Number: 0,
|
37
|
-
},
|
38
|
-
data: new Buffer(
|
39
|
-
"JgEAAAEAAAAIAAAAAQAAADw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04Ij8+CjwhRE9DVFlQRSBwbGlzdCBQVUJMSUMgIi0vL0FwcGxlLy9EVEQgUExJU1QgMS4wLy9FTiIgImh0dHA6Ly93d3cuYXBwbGUuY29tL0RURHMvUHJvcGVydHlMaXN0LTEuMC5kdGQiPgo8cGxpc3QgdmVyc2lvbj0iMS4wIj4KPGRpY3Q+Cgk8a2V5Pk1lc3NhZ2VUeXBlPC9rZXk+Cgk8c3RyaW5nPlJlc3VsdDwvc3RyaW5nPgoJPGtleT5OdW1iZXI8L2tleT4KCTxpbnRlZ2VyPjA8L2ludGVnZXI+CjwvZGljdD4KPC9wbGlzdD4K",
|
40
|
-
"base64",
|
41
|
-
),
|
42
|
-
},
|
43
|
-
|
44
|
-
// a device report message
|
45
|
-
device: {
|
46
|
-
msg: {
|
47
|
-
DeviceID: 7,
|
48
|
-
MessageType: "Attached",
|
49
|
-
Properties: {
|
50
|
-
ConnectionType: "USB",
|
51
|
-
DeviceID: 7,
|
52
|
-
LocationID: 0,
|
53
|
-
ProductID: 4776,
|
54
|
-
SerialNumber: "22226dd59068c222f46522221f8222da222d394b",
|
55
|
-
},
|
56
|
-
},
|
57
|
-
data: new Buffer(
|
58
|
-
"qAIAAAAAAAAAAAAAAAAAADw/eG1sIHZlcnNpb249IjEuMCIgZW5jb2Rpbmc9IlVURi04Ij8+CjwhRE9DVFlQRSBwbGlzdCBQVUJMSUMgIi0vL0FwcGxlLy9EVEQgUExJU1QgMS4wLy9FTiIgImh0dHA6Ly93d3cuYXBwbGUuY29tL0RURHMvUHJvcGVydHlMaXN0LTEuMC5kdGQiPgo8cGxpc3QgdmVyc2lvbj0iMS4wIj4KICA8ZGljdD4KICAgIDxrZXk+RGV2aWNlSUQ8L2tleT4KICAgIDxpbnRlZ2VyPjc8L2ludGVnZXI+CiAgICA8a2V5Pk1lc3NhZ2VUeXBlPC9rZXk+CiAgICA8c3RyaW5nPkF0dGFjaGVkPC9zdHJpbmc+CiAgICA8a2V5PlByb3BlcnRpZXM8L2tleT4KICAgIDxkaWN0PgogICAgICA8a2V5PkNvbm5lY3Rpb25UeXBlPC9rZXk+CiAgICAgIDxzdHJpbmc+VVNCPC9zdHJpbmc+CiAgICAgIDxrZXk+RGV2aWNlSUQ8L2tleT4KICAgICAgPGludGVnZXI+NzwvaW50ZWdlcj4KICAgICAgPGtleT5Mb2NhdGlvbklEPC9rZXk+CiAgICAgIDxpbnRlZ2VyPjA8L2ludGVnZXI+CiAgICAgIDxrZXk+UHJvZHVjdElEPC9rZXk+CiAgICAgIDxpbnRlZ2VyPjQ3NzY8L2ludGVnZXI+CiAgICAgIDxrZXk+U2VyaWFsTnVtYmVyPC9rZXk+CiAgICAgIDxzdHJpbmc+MjIyMjZkZDU5MDY4YzIyMmY0NjUyMjIyMWY4MjIyZGEyMjJkMzk0Yjwvc3RyaW5nPgogICAgPC9kaWN0PgogIDwvZGljdD4KPC9wbGlzdD4=",
|
59
|
-
"base64",
|
60
|
-
),
|
61
|
-
},
|
62
|
-
},
|
63
|
-
};
|
64
|
-
|
65
|
-
//
|
66
|
-
// RUNNER
|
67
|
-
//
|
68
|
-
|
69
|
-
// Test the building and parsing of usbmuxd messages
|
70
|
-
//
|
71
|
-
describe("protocol", function () {
|
72
|
-
// Test packing a listen request obj -> a usbmuxd msg with header
|
73
|
-
// Comparing against a known working example
|
74
|
-
//
|
75
|
-
describe(".listen", function () {
|
76
|
-
it("matches test buffer", function () {
|
77
|
-
protocol.listen.toString("base64").should.be.eql(tests.listen);
|
78
|
-
});
|
79
|
-
});
|
80
|
-
|
81
|
-
// Test packing a connect request obj -> a usbmuxd msg with header
|
82
|
-
// Compare against known working examples
|
83
|
-
//
|
84
|
-
describe(".connect()", function () {
|
85
|
-
it("connect(12, 22)", function () {
|
86
|
-
protocol
|
87
|
-
.connect(12, 22)
|
88
|
-
.toString("base64")
|
89
|
-
.should.be.eql(tests.connect._12_22);
|
90
|
-
});
|
91
|
-
it("connect(21, 1234)", function () {
|
92
|
-
protocol
|
93
|
-
.connect(21, 1234)
|
94
|
-
.toString("base64")
|
95
|
-
.should.be.eql(tests.connect._21_1234);
|
96
|
-
});
|
97
|
-
});
|
98
|
-
|
99
|
-
// Test parse function, comparing known data & messages
|
100
|
-
//
|
101
|
-
// This is probably the most important test because there's a few cases that
|
102
|
-
// need to be handled and everything breaks if the messages don't get parsed
|
103
|
-
// correctly.
|
104
|
-
//
|
105
|
-
describe(".parse()", function () {
|
106
|
-
//
|
107
|
-
// Case 1: a whole message
|
108
|
-
//
|
109
|
-
|
110
|
-
/**
|
111
|
-
* Test conversion of one data buf -> one usbmuxd message
|
112
|
-
*
|
113
|
-
* @param {string} messageType - 'confirmation' or 'device'
|
114
|
-
* @param {Function} done
|
115
|
-
*/
|
116
|
-
function one_data_to_one_msg(messageType, done) {
|
117
|
-
var test = tests.makeParser[messageType].data,
|
118
|
-
expected = tests.makeParser[messageType].msg;
|
119
|
-
|
120
|
-
var build = protocol.makeParser(function (msg) {
|
121
|
-
msg.should.eql(expected);
|
122
|
-
done();
|
123
|
-
});
|
124
|
-
|
125
|
-
build(test);
|
126
|
-
}
|
127
|
-
|
128
|
-
describe("where 1 data event makes up 1 complete msg", function () {
|
129
|
-
it("confirmation msg", function (done) {
|
130
|
-
one_data_to_one_msg("confirmation", done);
|
131
|
-
});
|
132
|
-
|
133
|
-
it("device report msg", function (done) {
|
134
|
-
one_data_to_one_msg("device", done);
|
135
|
-
});
|
136
|
-
});
|
137
|
-
|
138
|
-
//
|
139
|
-
// Case 2: messages broken up across data events
|
140
|
-
//
|
141
|
-
|
142
|
-
/**
|
143
|
-
* Test conversion of multiple data buf -> one usbmuxd message
|
144
|
-
*
|
145
|
-
* @param {string} messageType - 'confirmation' or 'device'
|
146
|
-
* @param {integer} numSegments - Number of segments to break data buf into
|
147
|
-
* @param {Function} done
|
148
|
-
*/
|
149
|
-
function more_datas_to_one_msg(messageType, numSegments, done) {
|
150
|
-
var test = tests.makeParser[messageType].data,
|
151
|
-
expected = tests.makeParser[messageType].msg;
|
152
|
-
|
153
|
-
var build = protocol.makeParser(function (msg) {
|
154
|
-
msg.should.eql(expected);
|
155
|
-
done();
|
156
|
-
});
|
157
|
-
|
158
|
-
for (var i = 0; i < numSegments; i++) {
|
159
|
-
var previous = (test.length / numSegments) * i,
|
160
|
-
next = (test.length / numSegments) * (i + 1);
|
161
|
-
|
162
|
-
build(test.slice(previous, next));
|
163
|
-
}
|
164
|
-
}
|
165
|
-
|
166
|
-
describe("where >1 data events make up 1 complete msg", function () {
|
167
|
-
it("confirmation msg (split in 2)", function (done) {
|
168
|
-
more_datas_to_one_msg("confirmation", 2, done);
|
169
|
-
});
|
170
|
-
|
171
|
-
it("device report msg (split in 3)", function (done) {
|
172
|
-
more_datas_to_one_msg("device", 3, done);
|
173
|
-
});
|
174
|
-
});
|
175
|
-
|
176
|
-
//
|
177
|
-
// Case 3: multiple messages (w/ headers) in a data event
|
178
|
-
//
|
179
|
-
|
180
|
-
/**
|
181
|
-
* Call cb after getting called n times
|
182
|
-
*
|
183
|
-
* Accumulates return values in array each time its called, then passes to cb
|
184
|
-
*
|
185
|
-
* @param {integer} n - Number of times to call
|
186
|
-
* @param {Function} done
|
187
|
-
*/
|
188
|
-
function callAfter(n, cb) {
|
189
|
-
var count = 0,
|
190
|
-
acc = [];
|
191
|
-
|
192
|
-
return function (item) {
|
193
|
-
count++;
|
194
|
-
acc.push(item);
|
195
|
-
if (count === n) cb(acc);
|
196
|
-
};
|
197
|
-
}
|
198
|
-
|
199
|
-
/**
|
200
|
-
* Test conversion of one data buf -> multiple usbmuxd messages
|
201
|
-
*
|
202
|
-
* @param {string[]} messageTypes - [] of 'confirmation's or 'device's
|
203
|
-
* @param {Function} done
|
204
|
-
*/
|
205
|
-
function one_data_to_many_msg(messageTypes, done) {
|
206
|
-
var test = Buffer.concat(
|
207
|
-
messageTypes.map(function (messageType) {
|
208
|
-
return tests.makeParser[messageType].data;
|
209
|
-
}),
|
210
|
-
);
|
211
|
-
|
212
|
-
var expected = messageTypes.map(function (messageType) {
|
213
|
-
return tests.makeParser[messageType].msg;
|
214
|
-
});
|
215
|
-
|
216
|
-
var onFinished = callAfter(messageTypes.length, function (msgs) {
|
217
|
-
msgs.should.eql(expected);
|
218
|
-
done();
|
219
|
-
});
|
220
|
-
|
221
|
-
var build = protocol.makeParser(onFinished);
|
222
|
-
|
223
|
-
build(test);
|
224
|
-
}
|
225
|
-
|
226
|
-
describe("where 1 data event makes up >1 complete msg", function () {
|
227
|
-
it("confirmation + report", function (done) {
|
228
|
-
one_data_to_many_msg(["confirmation", "device"], done);
|
229
|
-
});
|
230
|
-
|
231
|
-
it("report + report", function (done) {
|
232
|
-
one_data_to_many_msg(["device", "device"], done);
|
233
|
-
});
|
234
|
-
|
235
|
-
it("confirmation + report + report", function (done) {
|
236
|
-
one_data_to_many_msg(["confirmation", "device", "device"], done);
|
237
|
-
});
|
238
|
-
});
|
239
|
-
});
|
240
|
-
});
|
241
|
-
|
242
|
-
// From here on testing depends on a real plugged in device; its just easier to
|
243
|
-
// test the methods directly than mock out a tcp connection with fake buffers.
|
244
|
-
//
|
245
|
-
// These methods make up the core, so if they pass the rest of the module is
|
246
|
-
// probably in good shape.
|
247
|
-
//
|
248
|
-
|
249
|
-
describe("createListener()", function () {
|
250
|
-
it("fires attached event when a device is plugged in", function (done) {
|
251
|
-
const listener = usbmux
|
252
|
-
.createListener()
|
253
|
-
.on("error", done)
|
254
|
-
.on("attached", function () {
|
255
|
-
listener.end();
|
256
|
-
done();
|
257
|
-
});
|
258
|
-
});
|
259
|
-
});
|
260
|
-
|
261
|
-
describe("connect()", function () {
|
262
|
-
it("resolves a tunneled connection (id from above)", function (done) {
|
263
|
-
const listener = usbmux
|
264
|
-
.createListener()
|
265
|
-
.on("error", done)
|
266
|
-
.once("attached", function (udid) {
|
267
|
-
const deviceID = usbmux.devices[udid].DeviceID;
|
268
|
-
usbmux
|
269
|
-
.__get__("connect")(deviceID, port)
|
270
|
-
.then(function (tunnel) {
|
271
|
-
tunnel.should.be.instanceof(net.Socket);
|
272
|
-
tunnel.end();
|
273
|
-
listener.end();
|
274
|
-
done();
|
275
|
-
})
|
276
|
-
.catch(done);
|
277
|
-
});
|
278
|
-
});
|
279
|
-
});
|
280
|
-
|
281
|
-
describe("getTunnel()", function () {
|
282
|
-
describe("resolves a tunneled connection", function () {
|
283
|
-
it("with the udid option", function (done) {
|
284
|
-
const listener = usbmux
|
285
|
-
.createListener()
|
286
|
-
.on("error", done)
|
287
|
-
.once("attached", function (udid) {
|
288
|
-
usbmux
|
289
|
-
.getTunnel(port, { udid: udid })
|
290
|
-
.then(function (tunnel) {
|
291
|
-
tunnel.should.be.instanceof(net.Socket);
|
292
|
-
tunnel.end();
|
293
|
-
listener.end();
|
294
|
-
done();
|
295
|
-
})
|
296
|
-
.catch(done);
|
297
|
-
});
|
298
|
-
});
|
299
|
-
|
300
|
-
it("and without udid option", function (done) {
|
301
|
-
// emptying out device cache to test that case too
|
302
|
-
usbmux.__set__("devices", {});
|
303
|
-
|
304
|
-
usbmux
|
305
|
-
.getTunnel(port)
|
306
|
-
.then(function (tunnel) {
|
307
|
-
tunnel.should.be.instanceof(net.Socket);
|
308
|
-
tunnel.end();
|
309
|
-
done();
|
310
|
-
})
|
311
|
-
.catch(done);
|
312
|
-
});
|
313
|
-
});
|
314
|
-
});
|
315
|
-
|
316
|
-
describe("Relay()", function () {
|
317
|
-
it("has a server, a listener, and fires a ready event", function (done) {
|
318
|
-
var relay = new usbmux.Relay(port, 2222)
|
319
|
-
.on("error", done)
|
320
|
-
.on("warning", done)
|
321
|
-
.on("ready", function () {
|
322
|
-
relay._server.should.instanceof(net.Server);
|
323
|
-
relay._listener.should.instanceof(net.Socket);
|
324
|
-
relay.stop();
|
325
|
-
done();
|
326
|
-
});
|
327
|
-
});
|
328
|
-
});
|