@yume-chan/adb 0.0.8 → 0.0.11
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/CHANGELOG.json +49 -0
- package/CHANGELOG.md +30 -0
- package/LICENSE +21 -21
- package/README.md +240 -257
- package/esm/adb.d.ts +48 -0
- package/esm/adb.d.ts.map +1 -0
- package/esm/adb.js +141 -145
- package/esm/adb.js.map +1 -1
- package/{dts → esm}/auth.d.ts +17 -7
- package/esm/auth.d.ts.map +1 -0
- package/esm/auth.js +69 -109
- package/esm/auth.js.map +1 -1
- package/esm/backend.d.ts +9 -0
- package/esm/backend.d.ts.map +1 -0
- package/{dts → esm}/commands/base.d.ts +1 -1
- package/esm/commands/base.d.ts.map +1 -0
- package/esm/commands/base.js +1 -0
- package/esm/commands/base.js.map +1 -1
- package/{dts → esm}/commands/framebuffer.d.ts +3 -3
- package/esm/commands/framebuffer.d.ts.map +1 -0
- package/esm/commands/framebuffer.js +15 -18
- package/esm/commands/framebuffer.js.map +1 -1
- package/esm/commands/index.d.ts +9 -0
- package/esm/commands/index.d.ts.map +1 -0
- package/esm/commands/index.js +8 -8
- package/esm/commands/index.js.map +1 -1
- package/esm/commands/install.d.ts +4 -0
- package/esm/commands/install.d.ts.map +1 -0
- package/esm/commands/install.js +21 -13
- package/esm/commands/install.js.map +1 -1
- package/esm/commands/power.d.ts +23 -0
- package/esm/commands/power.d.ts.map +1 -0
- package/esm/commands/power.js +45 -0
- package/esm/commands/power.js.map +1 -0
- package/{dts → esm}/commands/reverse.d.ts +3 -3
- package/esm/commands/reverse.d.ts.map +1 -0
- package/esm/commands/reverse.js +50 -60
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +57 -0
- package/esm/commands/subprocess/index.d.ts.map +1 -0
- package/esm/commands/subprocess/index.js +83 -0
- package/esm/commands/subprocess/index.js.map +1 -0
- package/esm/commands/subprocess/legacy.d.ts +28 -0
- package/esm/commands/subprocess/legacy.d.ts.map +1 -0
- package/esm/commands/subprocess/legacy.js +44 -0
- package/esm/commands/subprocess/legacy.js.map +1 -0
- package/esm/commands/subprocess/protocol.d.ts +38 -0
- package/esm/commands/subprocess/protocol.d.ts.map +1 -0
- package/esm/commands/subprocess/protocol.js +155 -0
- package/esm/commands/subprocess/protocol.js.map +1 -0
- package/esm/commands/subprocess/types.d.ts +47 -0
- package/esm/commands/subprocess/types.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess}/types.js +0 -0
- package/{cjs/commands/shell → esm/commands/subprocess}/types.js.map +1 -1
- package/{dts/commands/shell → esm/commands/subprocess}/utils.d.ts +0 -0
- package/esm/commands/subprocess/utils.d.ts.map +1 -0
- package/esm/commands/{shell → subprocess}/utils.js +0 -0
- package/esm/commands/subprocess/utils.js.map +1 -0
- package/esm/commands/sync/index.d.ts +8 -0
- package/esm/commands/sync/index.d.ts.map +1 -0
- package/esm/commands/sync/index.js +7 -7
- package/esm/commands/sync/index.js.map +1 -1
- package/{dts → esm}/commands/sync/list.d.ts +4 -4
- package/esm/commands/sync/list.d.ts.map +1 -0
- package/esm/commands/sync/list.js +16 -19
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +11 -0
- package/esm/commands/sync/pull.d.ts.map +1 -0
- package/esm/commands/sync/pull.js +17 -11
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +8 -0
- package/esm/commands/sync/push.d.ts.map +1 -0
- package/esm/commands/sync/push.js +19 -37
- package/esm/commands/sync/push.js.map +1 -1
- package/{dts → esm}/commands/sync/request.d.ts +3 -3
- package/esm/commands/sync/request.d.ts.map +1 -0
- package/esm/commands/sync/request.js +24 -26
- package/esm/commands/sync/request.js.map +1 -1
- package/{dts → esm}/commands/sync/response.d.ts +3 -3
- package/esm/commands/sync/response.d.ts.map +1 -0
- package/esm/commands/sync/response.js +16 -19
- package/esm/commands/sync/response.js.map +1 -1
- package/{dts → esm}/commands/sync/stat.d.ts +4 -4
- package/esm/commands/sync/stat.d.ts.map +1 -0
- package/esm/commands/sync/stat.js +22 -27
- package/esm/commands/sync/stat.js.map +1 -1
- package/esm/commands/sync/sync.d.ts +83 -0
- package/esm/commands/sync/sync.d.ts.map +1 -0
- package/esm/commands/sync/sync.js +92 -89
- package/esm/commands/sync/sync.js.map +1 -1
- package/{dts → esm}/commands/tcpip.d.ts +1 -1
- package/{dts → esm}/commands/tcpip.d.ts.map +1 -1
- package/esm/commands/tcpip.js +14 -19
- package/esm/commands/tcpip.js.map +1 -1
- package/esm/crypto.d.ts +24 -0
- package/esm/crypto.d.ts.map +1 -0
- package/esm/crypto.js +33 -31
- package/esm/crypto.js.map +1 -1
- package/{dts → esm}/features.d.ts +0 -0
- package/{dts → esm}/features.d.ts.map +0 -0
- package/esm/features.js +1 -1
- package/esm/features.js.map +1 -1
- package/esm/index.d.ts +11 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +10 -10
- package/esm/index.js.map +1 -1
- package/esm/packet.d.ts +28 -0
- package/esm/packet.d.ts.map +1 -0
- package/esm/packet.js +26 -53
- package/esm/packet.js.map +1 -1
- package/esm/socket/controller.d.ts +37 -0
- package/esm/socket/controller.d.ts.map +1 -0
- package/esm/socket/controller.js +52 -66
- package/esm/socket/controller.js.map +1 -1
- package/{dts → esm}/socket/dispatcher.d.ts +10 -23
- package/esm/socket/dispatcher.d.ts.map +1 -0
- package/esm/socket/dispatcher.js +148 -164
- package/esm/socket/dispatcher.js.map +1 -1
- package/esm/socket/index.d.ts +3 -0
- package/esm/socket/index.d.ts.map +1 -0
- package/esm/socket/index.js +2 -6
- package/esm/socket/index.js.map +1 -1
- package/esm/socket/socket.d.ts +34 -0
- package/esm/socket/socket.d.ts.map +1 -0
- package/esm/socket/socket.js +69 -14
- package/esm/socket/socket.js.map +1 -1
- package/esm/stream/buffered.d.ts +35 -0
- package/esm/stream/buffered.d.ts.map +1 -0
- package/esm/stream/buffered.js +123 -0
- package/esm/stream/buffered.js.map +1 -0
- package/esm/stream/detect.bak.d.ts +240 -0
- package/esm/stream/detect.bak.d.ts.map +1 -0
- package/esm/stream/detect.bak.js +60 -0
- package/esm/stream/detect.bak.js.map +1 -0
- package/esm/stream/detect.d.ts +18 -0
- package/esm/stream/detect.d.ts.map +1 -0
- package/esm/stream/detect.js +6 -0
- package/esm/stream/detect.js.map +1 -0
- package/esm/stream/detect.native.d.ts +240 -0
- package/esm/stream/detect.native.d.ts.map +1 -0
- package/esm/stream/detect.native.js +60 -0
- package/esm/stream/detect.native.js.map +1 -0
- package/esm/stream/detect.polyfill.d.ts +18 -0
- package/esm/stream/detect.polyfill.d.ts.map +1 -0
- package/esm/stream/detect.polyfill.js +6 -0
- package/esm/stream/detect.polyfill.js.map +1 -0
- package/esm/stream/index.d.ts +4 -0
- package/esm/stream/index.d.ts.map +1 -0
- package/esm/stream/index.js +3 -2
- package/esm/stream/index.js.map +1 -1
- package/esm/stream/transform.d.ts +98 -0
- package/esm/stream/transform.d.ts.map +1 -0
- package/esm/stream/transform.js +352 -0
- package/esm/stream/transform.js.map +1 -0
- package/{dts → esm}/utils/auto-reset-event.d.ts +1 -1
- package/esm/utils/auto-reset-event.d.ts.map +1 -0
- package/esm/utils/auto-reset-event.js +2 -1
- package/esm/utils/auto-reset-event.js.map +1 -1
- package/esm/utils/base64.d.ts +5 -0
- package/esm/utils/base64.d.ts.map +1 -0
- package/esm/utils/base64.js +116 -80
- package/esm/utils/base64.js.map +1 -1
- package/esm/utils/encoding.d.ts +3 -0
- package/esm/utils/encoding.d.ts.map +1 -0
- package/esm/utils/encoding.js +11 -0
- package/esm/utils/encoding.js.map +1 -0
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.d.ts.map +1 -0
- package/esm/utils/index.js +3 -4
- package/esm/utils/index.js.map +1 -1
- package/package.json +49 -50
- package/src/adb.ts +247 -242
- package/src/auth.ts +170 -156
- package/src/backend.ts +11 -24
- package/src/commands/base.ts +11 -11
- package/src/commands/framebuffer.ts +73 -73
- package/src/commands/index.ts +8 -8
- package/src/commands/install.ts +32 -21
- package/src/commands/power.ts +54 -0
- package/src/commands/reverse.ts +136 -133
- package/src/commands/subprocess/index.ts +124 -0
- package/src/commands/subprocess/legacy.ts +58 -0
- package/src/commands/subprocess/protocol.ts +185 -0
- package/src/commands/subprocess/types.ts +55 -0
- package/src/commands/{shell → subprocess}/utils.ts +20 -20
- package/src/commands/sync/index.ts +7 -7
- package/src/commands/sync/list.ts +40 -39
- package/src/commands/sync/pull.ts +43 -34
- package/src/commands/sync/push.ts +41 -46
- package/src/commands/sync/request.ts +49 -48
- package/src/commands/sync/response.ts +58 -57
- package/src/commands/sync/stat.ts +123 -121
- package/src/commands/sync/sync.ts +145 -113
- package/src/commands/tcpip.ts +21 -21
- package/src/crypto.ts +280 -280
- package/src/features.ts +5 -5
- package/src/index.ts +11 -10
- package/src/packet.ts +69 -89
- package/src/socket/dispatcher.ts +256 -269
- package/src/socket/index.ts +2 -6
- package/src/socket/socket.ts +129 -28
- package/src/stream/buffered.ts +147 -0
- package/src/stream/detect.native.ts +362 -0
- package/src/stream/detect.polyfill.ts +25 -0
- package/src/stream/detect.ts +25 -0
- package/src/stream/index.ts +3 -2
- package/src/stream/transform.ts +427 -0
- package/src/utils/auto-reset-event.ts +41 -41
- package/src/utils/base64.ts +306 -274
- package/src/utils/encoding.ts +13 -0
- package/src/utils/index.ts +3 -4
- package/tsconfig.build.json +3 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.test.json +10 -0
- package/cjs/adb.js +0 -205
- package/cjs/adb.js.map +0 -1
- package/cjs/auth.js +0 -141
- package/cjs/auth.js.map +0 -1
- package/cjs/backend.js +0 -3
- package/cjs/backend.js.map +0 -1
- package/cjs/commands/base.js +0 -12
- package/cjs/commands/base.js.map +0 -1
- package/cjs/commands/demo-mode.js +0 -174
- package/cjs/commands/demo-mode.js.map +0 -1
- package/cjs/commands/framebuffer.js +0 -66
- package/cjs/commands/framebuffer.js.map +0 -1
- package/cjs/commands/index.js +0 -12
- package/cjs/commands/index.js.map +0 -1
- package/cjs/commands/install.js +0 -20
- package/cjs/commands/install.js.map +0 -1
- package/cjs/commands/reverse.js +0 -105
- package/cjs/commands/reverse.js.map +0 -1
- package/cjs/commands/shell/index.js +0 -56
- package/cjs/commands/shell/index.js.map +0 -1
- package/cjs/commands/shell/legacy.js +0 -37
- package/cjs/commands/shell/legacy.js.map +0 -1
- package/cjs/commands/shell/protocol.js +0 -83
- package/cjs/commands/shell/protocol.js.map +0 -1
- package/cjs/commands/shell/types.js +0 -3
- package/cjs/commands/shell/utils.js +0 -23
- package/cjs/commands/shell/utils.js.map +0 -1
- package/cjs/commands/sync/index.js +0 -11
- package/cjs/commands/sync/index.js.map +0 -1
- package/cjs/commands/sync/list.js +0 -36
- package/cjs/commands/sync/list.js.map +0 -1
- package/cjs/commands/sync/pull.js +0 -34
- package/cjs/commands/sync/pull.js.map +0 -1
- package/cjs/commands/sync/push.js +0 -49
- package/cjs/commands/sync/push.js.map +0 -1
- package/cjs/commands/sync/request.js +0 -48
- package/cjs/commands/sync/request.js.map +0 -1
- package/cjs/commands/sync/response.js +0 -53
- package/cjs/commands/sync/response.js.map +0 -1
- package/cjs/commands/sync/stat.js +0 -109
- package/cjs/commands/sync/stat.js.map +0 -1
- package/cjs/commands/sync/sync.js +0 -118
- package/cjs/commands/sync/sync.js.map +0 -1
- package/cjs/commands/tcpip.js +0 -28
- package/cjs/commands/tcpip.js.map +0 -1
- package/cjs/crypto.js +0 -231
- package/cjs/crypto.js.map +0 -1
- package/cjs/features.js +0 -10
- package/cjs/features.js.map +0 -1
- package/cjs/index.js +0 -14
- package/cjs/index.js.map +0 -1
- package/cjs/packet.js +0 -77
- package/cjs/packet.js.map +0 -1
- package/cjs/socket/close-event-emitter.js +0 -32
- package/cjs/socket/close-event-emitter.js.map +0 -1
- package/cjs/socket/controller.js +0 -84
- package/cjs/socket/controller.js.map +0 -1
- package/cjs/socket/data-event-emitter.js +0 -29
- package/cjs/socket/data-event-emitter.js.map +0 -1
- package/cjs/socket/dispatcher.js +0 -219
- package/cjs/socket/dispatcher.js.map +0 -1
- package/cjs/socket/index.js +0 -10
- package/cjs/socket/index.js.map +0 -1
- package/cjs/socket/logger.js +0 -3
- package/cjs/socket/logger.js.map +0 -1
- package/cjs/socket/socket.js +0 -24
- package/cjs/socket/socket.js.map +0 -1
- package/cjs/stream/buffered-stream.js +0 -78
- package/cjs/stream/buffered-stream.js.map +0 -1
- package/cjs/stream/index.js +0 -6
- package/cjs/stream/index.js.map +0 -1
- package/cjs/stream/stream.js +0 -45
- package/cjs/stream/stream.js.map +0 -1
- package/cjs/utils/auto-reset-event.js +0 -37
- package/cjs/utils/auto-reset-event.js.map +0 -1
- package/cjs/utils/base64.js +0 -210
- package/cjs/utils/base64.js.map +0 -1
- package/cjs/utils/chunk.js +0 -75
- package/cjs/utils/chunk.js.map +0 -1
- package/cjs/utils/event-queue.js +0 -108
- package/cjs/utils/event-queue.js.map +0 -1
- package/cjs/utils/index.js +0 -8
- package/cjs/utils/index.js.map +0 -1
- package/dts/adb.d.ts +0 -46
- package/dts/adb.d.ts.map +0 -1
- package/dts/auth.d.ts.map +0 -1
- package/dts/backend.d.ts +0 -15
- package/dts/backend.d.ts.map +0 -1
- package/dts/commands/base.d.ts.map +0 -1
- package/dts/commands/demo-mode.d.ts +0 -41
- package/dts/commands/demo-mode.d.ts.map +0 -1
- package/dts/commands/framebuffer.d.ts.map +0 -1
- package/dts/commands/index.d.ts +0 -9
- package/dts/commands/index.d.ts.map +0 -1
- package/dts/commands/install.d.ts +0 -3
- package/dts/commands/install.d.ts.map +0 -1
- package/dts/commands/reverse.d.ts.map +0 -1
- package/dts/commands/shell/index.d.ts +0 -20
- package/dts/commands/shell/index.d.ts.map +0 -1
- package/dts/commands/shell/legacy.d.ts +0 -27
- package/dts/commands/shell/legacy.d.ts.map +0 -1
- package/dts/commands/shell/protocol.d.ts +0 -37
- package/dts/commands/shell/protocol.d.ts.map +0 -1
- package/dts/commands/shell/types.d.ts +0 -15
- package/dts/commands/shell/types.d.ts.map +0 -1
- package/dts/commands/shell/utils.d.ts.map +0 -1
- package/dts/commands/sync/index.d.ts +0 -8
- package/dts/commands/sync/index.d.ts.map +0 -1
- package/dts/commands/sync/list.d.ts.map +0 -1
- package/dts/commands/sync/pull.d.ts +0 -11
- package/dts/commands/sync/pull.d.ts.map +0 -1
- package/dts/commands/sync/push.d.ts +0 -8
- package/dts/commands/sync/push.d.ts.map +0 -1
- package/dts/commands/sync/request.d.ts.map +0 -1
- package/dts/commands/sync/response.d.ts.map +0 -1
- package/dts/commands/sync/stat.d.ts.map +0 -1
- package/dts/commands/sync/sync.d.ts +0 -68
- package/dts/commands/sync/sync.d.ts.map +0 -1
- package/dts/crypto.d.ts +0 -17
- package/dts/crypto.d.ts.map +0 -1
- package/dts/index.d.ts +0 -11
- package/dts/index.d.ts.map +0 -1
- package/dts/packet.d.ts +0 -27
- package/dts/packet.d.ts.map +0 -1
- package/dts/socket/close-event-emitter.d.ts +0 -8
- package/dts/socket/close-event-emitter.d.ts.map +0 -1
- package/dts/socket/controller.d.ts +0 -43
- package/dts/socket/controller.d.ts.map +0 -1
- package/dts/socket/data-event-emitter.d.ts +0 -10
- package/dts/socket/data-event-emitter.d.ts.map +0 -1
- package/dts/socket/dispatcher.d.ts.map +0 -1
- package/dts/socket/index.d.ts +0 -7
- package/dts/socket/index.d.ts.map +0 -1
- package/dts/socket/logger.d.ts +0 -9
- package/dts/socket/logger.d.ts.map +0 -1
- package/dts/socket/socket.d.ts +0 -22
- package/dts/socket/socket.d.ts.map +0 -1
- package/dts/stream/buffered-stream.d.ts +0 -30
- package/dts/stream/buffered-stream.d.ts.map +0 -1
- package/dts/stream/index.d.ts +0 -3
- package/dts/stream/index.d.ts.map +0 -1
- package/dts/stream/stream.d.ts +0 -15
- package/dts/stream/stream.d.ts.map +0 -1
- package/dts/utils/auto-reset-event.d.ts.map +0 -1
- package/dts/utils/base64.d.ts +0 -7
- package/dts/utils/base64.d.ts.map +0 -1
- package/dts/utils/chunk.d.ts +0 -3
- package/dts/utils/chunk.d.ts.map +0 -1
- package/dts/utils/event-queue.d.ts +0 -35
- package/dts/utils/event-queue.d.ts.map +0 -1
- package/dts/utils/index.d.ts +0 -5
- package/dts/utils/index.d.ts.map +0 -1
- package/esm/commands/demo-mode.js +0 -170
- package/esm/commands/demo-mode.js.map +0 -1
- package/esm/commands/shell/index.js +0 -52
- package/esm/commands/shell/index.js.map +0 -1
- package/esm/commands/shell/legacy.js +0 -33
- package/esm/commands/shell/legacy.js.map +0 -1
- package/esm/commands/shell/protocol.js +0 -79
- package/esm/commands/shell/protocol.js.map +0 -1
- package/esm/commands/shell/types.js.map +0 -1
- package/esm/commands/shell/utils.js.map +0 -1
- package/esm/socket/close-event-emitter.js +0 -28
- package/esm/socket/close-event-emitter.js.map +0 -1
- package/esm/socket/data-event-emitter.js +0 -25
- package/esm/socket/data-event-emitter.js.map +0 -1
- package/esm/socket/logger.js +0 -2
- package/esm/socket/logger.js.map +0 -1
- package/esm/stream/buffered-stream.js +0 -73
- package/esm/stream/buffered-stream.js.map +0 -1
- package/esm/stream/stream.js +0 -41
- package/esm/stream/stream.js.map +0 -1
- package/esm/utils/chunk.js +0 -70
- package/esm/utils/chunk.js.map +0 -1
- package/esm/utils/event-queue.js +0 -104
- package/esm/utils/event-queue.js.map +0 -1
- package/src/commands/demo-mode.ts +0 -160
- package/src/commands/shell/index.ts +0 -68
- package/src/commands/shell/legacy.ts +0 -42
- package/src/commands/shell/protocol.ts +0 -94
- package/src/commands/shell/types.ts +0 -21
- package/src/socket/close-event-emitter.ts +0 -28
- package/src/socket/controller.ts +0 -105
- package/src/socket/data-event-emitter.ts +0 -27
- package/src/socket/logger.ts +0 -12
- package/src/stream/buffered-stream.ts +0 -100
- package/src/stream/stream.ts +0 -50
- package/src/utils/chunk.ts +0 -70
- package/src/utils/event-queue.ts +0 -145
- package/tsconfig.cjs.json +0 -11
- package/tsconfig.esm.json +0 -28
- package/tsconfig.esm.tsbuildinfo +0 -1305
- package/tsconfig.json +0 -18
package/src/socket/controller.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { AutoDisposable } from '@yume-chan/event';
|
|
2
|
-
import { AdbBackend } from '../backend';
|
|
3
|
-
import { AdbCommand } from '../packet';
|
|
4
|
-
import { AutoResetEvent, chunkArrayLike } from '../utils';
|
|
5
|
-
import { CloseEventEmitter } from './close-event-emitter';
|
|
6
|
-
import { DataEventEmitter } from './data-event-emitter';
|
|
7
|
-
import { AdbPacketDispatcher } from './dispatcher';
|
|
8
|
-
|
|
9
|
-
export interface AdbSocketInfo {
|
|
10
|
-
backend: AdbBackend;
|
|
11
|
-
|
|
12
|
-
localId: number;
|
|
13
|
-
|
|
14
|
-
remoteId: number;
|
|
15
|
-
|
|
16
|
-
localCreated: boolean;
|
|
17
|
-
|
|
18
|
-
serviceString: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface AdbSocketConstructionOptions {
|
|
22
|
-
dispatcher: AdbPacketDispatcher;
|
|
23
|
-
|
|
24
|
-
localId: number;
|
|
25
|
-
|
|
26
|
-
remoteId: number;
|
|
27
|
-
|
|
28
|
-
localCreated: boolean;
|
|
29
|
-
|
|
30
|
-
serviceString: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export class AdbSocketController extends AutoDisposable implements AdbSocketInfo {
|
|
34
|
-
private readonly writeChunkLock = this.addDisposable(new AutoResetEvent());
|
|
35
|
-
private readonly writeLock = this.addDisposable(new AutoResetEvent());
|
|
36
|
-
|
|
37
|
-
private readonly dispatcher!: AdbPacketDispatcher;
|
|
38
|
-
public get backend() { return this.dispatcher.backend; }
|
|
39
|
-
|
|
40
|
-
public readonly localId!: number;
|
|
41
|
-
public readonly remoteId!: number;
|
|
42
|
-
public readonly localCreated!: boolean;
|
|
43
|
-
public readonly serviceString!: string;
|
|
44
|
-
|
|
45
|
-
public readonly dataEvent = this.addDisposable(new DataEventEmitter<ArrayBuffer>());
|
|
46
|
-
|
|
47
|
-
private _closed = false;
|
|
48
|
-
public get closed() { return this._closed; }
|
|
49
|
-
|
|
50
|
-
private readonly closeEvent = this.addDisposable(new CloseEventEmitter());
|
|
51
|
-
public get onClose() { return this.closeEvent.event; }
|
|
52
|
-
|
|
53
|
-
public constructor(options: AdbSocketConstructionOptions) {
|
|
54
|
-
super();
|
|
55
|
-
Object.assign(this, options);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private async writeChunk(data: ArrayBuffer): Promise<void> {
|
|
59
|
-
try {
|
|
60
|
-
// Wait for an ack packet
|
|
61
|
-
await this.writeChunkLock.wait();
|
|
62
|
-
} catch {
|
|
63
|
-
// Lock has been disposed, which means the socket has been closed
|
|
64
|
-
throw new Error('Can not write after closed');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
await this.dispatcher.sendPacket(AdbCommand.Write, this.localId, this.remoteId, data);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public async write(data: ArrayBuffer): Promise<void> {
|
|
71
|
-
try {
|
|
72
|
-
// Keep write operations in order
|
|
73
|
-
await this.writeLock.wait();
|
|
74
|
-
} catch {
|
|
75
|
-
// Lock has been disposed, which means the socket has been closed
|
|
76
|
-
throw new Error('Can not write after closed');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
for await (const chunk of chunkArrayLike(data, this.dispatcher.maxPayloadSize)) {
|
|
80
|
-
await this.writeChunk(chunk);
|
|
81
|
-
}
|
|
82
|
-
this.writeLock.notify();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
public ack() {
|
|
86
|
-
this.writeChunkLock.notify();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public async close(): Promise<void> {
|
|
90
|
-
if (!this._closed) {
|
|
91
|
-
// Immediately cancel all pending writes
|
|
92
|
-
this.writeLock.dispose();
|
|
93
|
-
this.writeChunkLock.dispose();
|
|
94
|
-
|
|
95
|
-
await this.dispatcher.sendPacket(AdbCommand.Close, this.localId, this.remoteId);
|
|
96
|
-
this._closed = true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public dispose() {
|
|
101
|
-
this._closed = true;
|
|
102
|
-
this.closeEvent.fire();
|
|
103
|
-
super.dispose();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { PromiseResolver } from '@yume-chan/async';
|
|
2
|
-
import { Event, EventEmitter, EventListenerInfo } from '@yume-chan/event';
|
|
3
|
-
import { ValueOrPromise } from '@yume-chan/struct';
|
|
4
|
-
|
|
5
|
-
export type AsyncEventResult = ValueOrPromise<void>;
|
|
6
|
-
|
|
7
|
-
export type AsyncEvent<TEvent> = Event<TEvent, AsyncEventResult>;
|
|
8
|
-
|
|
9
|
-
export class DataEventEmitter<TEvent> extends EventEmitter<TEvent, AsyncEventResult> {
|
|
10
|
-
private dispatchLock = new PromiseResolver<void>();
|
|
11
|
-
|
|
12
|
-
protected addEventListener(info: EventListenerInfo<TEvent, AsyncEventResult>) {
|
|
13
|
-
const remove = super.addEventListener(info);
|
|
14
|
-
if (this.listeners.length === 1) {
|
|
15
|
-
this.dispatchLock.resolve();
|
|
16
|
-
}
|
|
17
|
-
return remove;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public async fire(e: TEvent) {
|
|
21
|
-
await this.dispatchLock.promise;
|
|
22
|
-
|
|
23
|
-
for (const info of this.listeners) {
|
|
24
|
-
await info.listener.apply(info.thisArg, [e, ...info.args]);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
package/src/socket/logger.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { AdbPacket, AdbPacketInit } from '../packet';
|
|
2
|
-
import { AdbSocket } from './socket';
|
|
3
|
-
|
|
4
|
-
export interface AdbLogger {
|
|
5
|
-
onIncomingPacket?(packet: AdbPacket): void;
|
|
6
|
-
|
|
7
|
-
onOutgoingPacket?(packet: AdbPacketInit): void;
|
|
8
|
-
|
|
9
|
-
onSocketOpened?(socket: AdbSocket): void;
|
|
10
|
-
|
|
11
|
-
onSocketClosed?(socket: AdbSocket): void;
|
|
12
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { StructDeserializationContext } from '@yume-chan/struct';
|
|
2
|
-
import { AdbSocket, AdbSocketInfo } from '../socket';
|
|
3
|
-
import { AdbSocketStream } from './stream';
|
|
4
|
-
|
|
5
|
-
export interface Stream {
|
|
6
|
-
/**
|
|
7
|
-
* @param length A hint of how much data should be read.
|
|
8
|
-
* @returns Data, which can be either more or less than `length`
|
|
9
|
-
*/
|
|
10
|
-
read(length: number): ArrayBuffer | Promise<ArrayBuffer>;
|
|
11
|
-
|
|
12
|
-
close?(): void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class BufferedStream<T extends Stream> {
|
|
16
|
-
private buffer: Uint8Array | undefined;
|
|
17
|
-
|
|
18
|
-
protected readonly stream: T;
|
|
19
|
-
|
|
20
|
-
public constructor(stream: T) {
|
|
21
|
-
this.stream = stream;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public async read(length: number): Promise<ArrayBuffer> {
|
|
25
|
-
let array: Uint8Array;
|
|
26
|
-
let index: number;
|
|
27
|
-
if (this.buffer) {
|
|
28
|
-
const buffer = this.buffer;
|
|
29
|
-
if (buffer.byteLength > length) {
|
|
30
|
-
this.buffer = buffer.subarray(length);
|
|
31
|
-
return buffer.slice(0, length).buffer;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
array = new Uint8Array(length);
|
|
35
|
-
array.set(buffer);
|
|
36
|
-
index = buffer.byteLength;
|
|
37
|
-
this.buffer = undefined;
|
|
38
|
-
} else {
|
|
39
|
-
const buffer = await this.stream.read(length);
|
|
40
|
-
if (buffer.byteLength === length) {
|
|
41
|
-
return buffer;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (buffer.byteLength > length) {
|
|
45
|
-
this.buffer = new Uint8Array(buffer, length);
|
|
46
|
-
return buffer.slice(0, length);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
array = new Uint8Array(length);
|
|
50
|
-
array.set(new Uint8Array(buffer), 0);
|
|
51
|
-
index = buffer.byteLength;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
while (index < length) {
|
|
55
|
-
const left = length - index;
|
|
56
|
-
|
|
57
|
-
const buffer = await this.stream.read(left);
|
|
58
|
-
if (buffer.byteLength > left) {
|
|
59
|
-
array.set(new Uint8Array(buffer, 0, left), index);
|
|
60
|
-
this.buffer = new Uint8Array(buffer, left);
|
|
61
|
-
return array.buffer;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
array.set(new Uint8Array(buffer), index);
|
|
65
|
-
index += buffer.byteLength;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return array.buffer;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public close() {
|
|
72
|
-
this.stream.close?.();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export class AdbBufferedStream
|
|
77
|
-
extends BufferedStream<AdbSocketStream>
|
|
78
|
-
implements AdbSocketInfo, StructDeserializationContext {
|
|
79
|
-
public get backend() { return this.stream.backend; }
|
|
80
|
-
public get localId() { return this.stream.localId; }
|
|
81
|
-
public get remoteId() { return this.stream.remoteId; }
|
|
82
|
-
public get localCreated() { return this.stream.localCreated; }
|
|
83
|
-
public get serviceString() { return this.stream.serviceString; }
|
|
84
|
-
|
|
85
|
-
public constructor(socket: AdbSocket) {
|
|
86
|
-
super(new AdbSocketStream(socket));
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public write(data: ArrayBuffer): Promise<void> {
|
|
90
|
-
return this.stream.write(data);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public decodeUtf8(buffer: ArrayBuffer): string {
|
|
94
|
-
return this.backend.decodeUtf8(buffer);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
public encodeUtf8(input: string): ArrayBuffer {
|
|
98
|
-
return this.backend.encodeUtf8(input);
|
|
99
|
-
}
|
|
100
|
-
}
|
package/src/stream/stream.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { once } from '@yume-chan/event';
|
|
2
|
-
import { ValueOrPromise } from '@yume-chan/struct';
|
|
3
|
-
import { AdbSocket, AdbSocketInfo } from '../socket';
|
|
4
|
-
import { EventQueue } from '../utils';
|
|
5
|
-
|
|
6
|
-
export class AdbSocketStream implements AdbSocketInfo {
|
|
7
|
-
private socket: AdbSocket;
|
|
8
|
-
|
|
9
|
-
private queue: EventQueue<ArrayBuffer>;
|
|
10
|
-
|
|
11
|
-
public get backend() { return this.socket.backend; }
|
|
12
|
-
public get localId() { return this.socket.localId; }
|
|
13
|
-
public get remoteId() { return this.socket.remoteId; }
|
|
14
|
-
public get localCreated() { return this.socket.localCreated; }
|
|
15
|
-
public get serviceString() { return this.socket.serviceString; }
|
|
16
|
-
|
|
17
|
-
public constructor(socket: AdbSocket) {
|
|
18
|
-
this.socket = socket;
|
|
19
|
-
|
|
20
|
-
this.queue = new EventQueue<ArrayBuffer>({
|
|
21
|
-
highWaterMark: 16 * 1024,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
this.socket.onData((buffer): ValueOrPromise<void> => {
|
|
25
|
-
if (!this.queue.enqueue(buffer, buffer.byteLength)) {
|
|
26
|
-
return once(this.queue.onDrain);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
this.socket.onClose(() => {
|
|
31
|
-
this.queue.end();
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public async read(): Promise<ArrayBuffer> {
|
|
36
|
-
try {
|
|
37
|
-
return await this.queue.dequeue();
|
|
38
|
-
} catch {
|
|
39
|
-
throw new Error('Can not read after AdbSocketStream has been closed');
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public write(data: ArrayBuffer): Promise<void> {
|
|
44
|
-
return this.socket.write(data);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
close(): void {
|
|
48
|
-
this.socket.close();
|
|
49
|
-
}
|
|
50
|
-
}
|
package/src/utils/chunk.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
export function* chunkArrayLike(
|
|
2
|
-
value: ArrayLike<number> | ArrayBufferLike,
|
|
3
|
-
size: number
|
|
4
|
-
): Generator<ArrayBuffer, void, void> {
|
|
5
|
-
if ('length' in value) {
|
|
6
|
-
value = new Uint8Array(value).buffer;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if (value.byteLength <= size) {
|
|
10
|
-
return yield value;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
for (let i = 0; i < value.byteLength; i += size) {
|
|
14
|
-
yield value.slice(i, i + size);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function* chunkAsyncIterable(
|
|
19
|
-
value: AsyncIterable<ArrayBuffer>,
|
|
20
|
-
size: number
|
|
21
|
-
): AsyncGenerator<ArrayBuffer, void, void> {
|
|
22
|
-
let result = new Uint8Array(size);
|
|
23
|
-
let index = 0;
|
|
24
|
-
for await (let buffer of value) {
|
|
25
|
-
// `result` has some data, `result + buffer` is enough
|
|
26
|
-
if (index !== 0 && index + buffer.byteLength >= size) {
|
|
27
|
-
const remainder = size - index;
|
|
28
|
-
result.set(new Uint8Array(buffer, 0, remainder), index);
|
|
29
|
-
yield result.buffer;
|
|
30
|
-
|
|
31
|
-
result = new Uint8Array(size);
|
|
32
|
-
index = 0;
|
|
33
|
-
|
|
34
|
-
if (buffer.byteLength > remainder) {
|
|
35
|
-
// `buffer` still has some data
|
|
36
|
-
buffer = buffer.slice(remainder);
|
|
37
|
-
} else {
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// `result` is empty, `buffer` alone is enough
|
|
43
|
-
if (buffer.byteLength >= size) {
|
|
44
|
-
let remainder = false;
|
|
45
|
-
for (const chunk of chunkArrayLike(buffer, size)) {
|
|
46
|
-
if (chunk.byteLength === size) {
|
|
47
|
-
yield chunk;
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// `buffer` still has some data
|
|
52
|
-
remainder = true;
|
|
53
|
-
buffer = chunk;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (!remainder) {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// `result` has some data but `result + buffer` is still not enough
|
|
62
|
-
// or after previous steps `buffer` still has some data
|
|
63
|
-
result.set(new Uint8Array(buffer), index);
|
|
64
|
-
index += buffer.byteLength;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (index !== 0) {
|
|
68
|
-
yield result.buffer.slice(0, index);
|
|
69
|
-
}
|
|
70
|
-
}
|
package/src/utils/event-queue.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { PromiseResolver } from '@yume-chan/async';
|
|
2
|
-
import { EventEmitter } from '@yume-chan/event';
|
|
3
|
-
|
|
4
|
-
export interface EventQueueOptions {
|
|
5
|
-
maxWaitCount: number;
|
|
6
|
-
|
|
7
|
-
highWaterMark: number;
|
|
8
|
-
|
|
9
|
-
lowWaterMark: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const EventQueueDefaultOptions: EventQueueOptions = {
|
|
13
|
-
maxWaitCount: Infinity,
|
|
14
|
-
highWaterMark: 10,
|
|
15
|
-
lowWaterMark: 0,
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
interface LinkedListItem<T> {
|
|
19
|
-
value: T;
|
|
20
|
-
|
|
21
|
-
next?: LinkedListItem<T>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
class LinkedList<T>{
|
|
25
|
-
private head?: LinkedListItem<T>;
|
|
26
|
-
|
|
27
|
-
private tail?: LinkedListItem<T>;
|
|
28
|
-
|
|
29
|
-
private _length = 0;
|
|
30
|
-
public get length() { return this._length; }
|
|
31
|
-
|
|
32
|
-
public push(value: T): void {
|
|
33
|
-
const item: LinkedListItem<T> = { value };
|
|
34
|
-
|
|
35
|
-
if (this._length === 0) {
|
|
36
|
-
this.head = item;
|
|
37
|
-
} else {
|
|
38
|
-
this.tail!.next = item;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
this._length += 1;
|
|
42
|
-
this.tail = item;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public shift(): T | undefined {
|
|
46
|
-
if (this._length === 0) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const { next, value } = this.head!;
|
|
51
|
-
if (!next) {
|
|
52
|
-
this.tail = undefined;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
this.head = next;
|
|
56
|
-
this._length -= 1;
|
|
57
|
-
return value;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Basically an object-mode ReadableStream with Promise-based API
|
|
63
|
-
*
|
|
64
|
-
* It's called `EventQueue` because it usually converts events ("push system") to "pull system"
|
|
65
|
-
*
|
|
66
|
-
* https://github.com/nodejs/node/blob/master/lib/internal/streams/readable.js
|
|
67
|
-
*/
|
|
68
|
-
export class EventQueue<T> {
|
|
69
|
-
// Use linked lists for faster shift operation.
|
|
70
|
-
|
|
71
|
-
/** Already buffered data ready to be served to consumers */
|
|
72
|
-
private buffers = new LinkedList<[value: T, size: number]>();
|
|
73
|
-
|
|
74
|
-
/** Waiting consumers because lack of data */
|
|
75
|
-
private awaiters = new LinkedList<PromiseResolver<T>>();
|
|
76
|
-
|
|
77
|
-
private options: EventQueueOptions;
|
|
78
|
-
|
|
79
|
-
private ended = false;
|
|
80
|
-
|
|
81
|
-
private _length = 0;
|
|
82
|
-
public get length() { return this._length; }
|
|
83
|
-
|
|
84
|
-
private _needDrain = false;
|
|
85
|
-
public get needDrain() { return this._needDrain; }
|
|
86
|
-
|
|
87
|
-
private readonly drainEvent = new EventEmitter<void>();
|
|
88
|
-
public readonly onDrain = this.drainEvent.event;
|
|
89
|
-
|
|
90
|
-
public constructor(options?: Partial<EventQueueOptions>) {
|
|
91
|
-
this.options = { ...EventQueueDefaultOptions, ...options };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
public enqueue(value: T, length = 1): boolean {
|
|
95
|
-
if (this.ended) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (this.awaiters.length) {
|
|
100
|
-
this.awaiters.shift()!.resolve(value);
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
this.buffers.push([value, length]);
|
|
105
|
-
this._length += length;
|
|
106
|
-
if (this._length < this.options.highWaterMark) {
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
this._needDrain = true;
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
public dequeue(): Promise<T> {
|
|
115
|
-
if (this.buffers.length) {
|
|
116
|
-
const [value, size] = this.buffers.shift()!;
|
|
117
|
-
this._length -= size;
|
|
118
|
-
if (this._needDrain &&
|
|
119
|
-
this._length <= this.options.lowWaterMark) {
|
|
120
|
-
this.drainEvent.fire();
|
|
121
|
-
}
|
|
122
|
-
return Promise.resolve(value);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (this.ended) {
|
|
126
|
-
return Promise.reject(new Error('The EventQueue has already ended'));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (this.awaiters.length === this.options.maxWaitCount - 1) {
|
|
130
|
-
throw new Error('Max wait count exceeded');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const resolver = new PromiseResolver<T>();
|
|
134
|
-
this.awaiters.push(resolver);
|
|
135
|
-
return resolver.promise;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
public end(): void {
|
|
139
|
-
this.ended = true;
|
|
140
|
-
let item: PromiseResolver<T> | undefined;
|
|
141
|
-
while (item = this.awaiters.shift()) {
|
|
142
|
-
item.reject(new Error('The EventQueue has already ended'));
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
package/tsconfig.cjs.json
DELETED
package/tsconfig.esm.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": "src",
|
|
5
|
-
"outDir": "esm",
|
|
6
|
-
"target": "ES2016",
|
|
7
|
-
"declarationDir": "dts",
|
|
8
|
-
"types": [
|
|
9
|
-
"@yume-chan/async",
|
|
10
|
-
"@yume-chan/event",
|
|
11
|
-
"@yume-chan/struct",
|
|
12
|
-
],
|
|
13
|
-
},
|
|
14
|
-
"include": [
|
|
15
|
-
"src"
|
|
16
|
-
],
|
|
17
|
-
"exclude": [
|
|
18
|
-
"src/**/*.spec.ts"
|
|
19
|
-
],
|
|
20
|
-
"references": [
|
|
21
|
-
{
|
|
22
|
-
"path": "../event/tsconfig.esm.json"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
"path": "../struct/tsconfig.esm.json"
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
}
|