Skip to content

Commit

Permalink
refactor: rename AdbDaemonConnection to AdbDaemonDevice
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed May 25, 2023
1 parent e42e1a7 commit 1006571
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
31 changes: 15 additions & 16 deletions packages/adb-daemon-direct-sockets/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AdbDaemonConnection } from "@yume-chan/adb";
import type { AdbDaemonDevice } from "@yume-chan/adb";
import { AdbPacket, AdbPacketSerializeStream } from "@yume-chan/adb";
import type { ReadableStream, WritableStream } from "@yume-chan/stream-extra";
import {
Expand All @@ -20,13 +20,7 @@ declare global {
localPort: number;
}

class TCPSocket {
constructor(
remoteAddress: string,
remotePort: number,
options?: TCPSocketOptions
);

interface TCPSocket {
opened: Promise<TCPSocketOpenInfo>;
closed: Promise<void>;

Expand All @@ -41,16 +35,19 @@ declare global {
keepAliveDelay?: number;
}

interface Window {
TCPSocket: typeof TCPSocket;
}
// eslint-disable-next-line no-var
var TCPSocket: {
new (
remoteAddress: string,
remotePort: number,
options?: TCPSocketOptions
): TCPSocket;
};
}

export default class AdbDaemonDirectSocketsConnection
implements AdbDaemonConnection
{
export default class AdbDaemonDirectSocketsDevice implements AdbDaemonDevice {
public static isSupported(): boolean {
return typeof window !== "undefined" && !!window.TCPSocket;
return typeof globalThis.TCPSocket !== "undefined";
}

public readonly serial: string;
Expand All @@ -69,7 +66,9 @@ export default class AdbDaemonDirectSocketsConnection
}

public async connect() {
const socket = new TCPSocket(this.host, this.port, { noDelay: true });
const socket = new globalThis.TCPSocket(this.host, this.port, {
noDelay: true,
});
const { readable, writable } = await socket.opened;

return {
Expand Down
6 changes: 2 additions & 4 deletions packages/adb-daemon-ws/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AdbDaemonConnection } from "@yume-chan/adb";
import type { AdbDaemonDevice } from "@yume-chan/adb";
import {
AdbPacket,
AdbPacketSerializeStream,
Expand All @@ -13,9 +13,7 @@ import {
pipeFrom,
} from "@yume-chan/stream-extra";

export default class AdbDaemonWebSocketConnection
implements AdbDaemonConnection
{
export default class AdbDaemonWebSocketDevice implements AdbDaemonDevice {
public readonly serial: string;

public name: string | undefined;
Expand Down

0 comments on commit 1006571

Please sign in to comment.