-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip: getwindows command on desktop-capturer * wip: getPidLists * wip: get pids in windows * wip: add pid to streaming param * wip: windows getwindowrect * wip: get windows w,h * fix: ToJson error * wip: add pid on screen-capture option * wip: step record * feat: capture window process * feat: on windows capture apply width,height * refactor: gdc to get screenId, pid as surface param * fix: surface not playing * feat: kill previously running safari instance and capture safari * fix: reviewed code, validate deviceWindowInfo, add isStepMessageEventHandler() function * fix: apply reviewed code check GetWindowThreadProcessId return
- Loading branch information
Showing
80 changed files
with
2,818 additions
and
769 deletions.
There are no files selected for viewing
5 changes: 4 additions & 1 deletion
5
packages/typescript-private/device-server/src/bootstrap/bootstrap.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { BootstrapService } from './bootstrap.service'; | ||
|
||
@Module({}) | ||
@Module({ | ||
providers: [BootstrapService], | ||
}) | ||
export class BootstrapModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/typescript-private/device-server/src/internal/externals/cli/desktop-capturer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { DeviceWindowInfo } from '@dogu-private/types'; | ||
import { Printable, stringify, transformAndValidate } from '@dogu-tech/common'; | ||
import { ChildProcess, HostPaths } from '@dogu-tech/node'; | ||
import fs from 'fs'; | ||
import { isArray } from 'lodash'; | ||
import { registerBootstrapHandler } from '../../../bootstrap/bootstrap.service'; | ||
|
||
const binPath = (): string => HostPaths.thirdParty.pathMap().common.desktopCapturer; | ||
|
||
export async function getWindows(printable: Printable): Promise<DeviceWindowInfo[]> { | ||
tryAccessAndFix(); | ||
const res = await ChildProcess.exec(`${binPath()} windows --info`, {}, printable); | ||
if (0 == res.stdout.length) { | ||
return []; | ||
} | ||
const infos = JSON.parse(res.stdout) as DeviceWindowInfo[]; | ||
if (!isArray(infos)) { | ||
throw new Error(`Invalid result: ${res.stdout}`); | ||
} | ||
for (const info of infos) { | ||
await transformAndValidate(DeviceWindowInfo, info, { printable }); | ||
} | ||
|
||
return infos; | ||
} | ||
|
||
const tryAccessAndFix = (): void => { | ||
const bin = binPath(); | ||
try { | ||
fs.accessSync(bin, fs.constants.X_OK); | ||
} catch (error) { | ||
makeAccessableSync(); | ||
} | ||
}; | ||
|
||
const makeAccessableSync = (): void => { | ||
try { | ||
fs.chmodSync(binPath(), 0o777); | ||
} catch (error) { | ||
const cause = error instanceof Error ? error : new Error(stringify(error)); | ||
throw new Error(`Failed to chmod desktop-capturer`, { cause }); | ||
} | ||
}; | ||
|
||
registerBootstrapHandler(__filename, async () => { | ||
try { | ||
await fs.promises.chmod(binPath(), 0o777); | ||
} catch (error) { | ||
const cause = error instanceof Error ? error : new Error(stringify(error)); | ||
throw new Error(`Failed to chmod desktop-capturer`, { cause }); | ||
} | ||
}); |
1 change: 1 addition & 0 deletions
1
packages/typescript-private/device-server/src/internal/externals/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/typescript-private/device-server/src/ws/device/find-windows.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { OnWebSocketClose, OnWebSocketMessage, WebSocketGatewayBase, WebSocketRegistryValueAccessor, WebSocketService } from '@dogu-private/nestjs-common'; | ||
import { categoryFromPlatform, platformTypeFromPlatform, Serial } from '@dogu-private/types'; | ||
import { closeWebSocketWithTruncateReason, DuplicatedCallGuarder, errorify, Instance } from '@dogu-tech/common'; | ||
import { DeviceFindWindows } from '@dogu-tech/device-client-common'; | ||
import { getChildProcessIds, getProcessesMapMacos } from '@dogu-tech/node'; | ||
import { IncomingMessage } from 'http'; | ||
import WebSocket from 'ws'; | ||
import { DoguLogger } from '../../logger/logger'; | ||
import { ScanService } from '../../scan/scan.service'; | ||
|
||
interface Value { | ||
serial: Serial; | ||
parentPid: number; | ||
timer: NodeJS.Timer | null; | ||
updateGuard: DuplicatedCallGuarder; | ||
} | ||
|
||
@WebSocketService(DeviceFindWindows) | ||
export class DeviceFindWindowsService | ||
extends WebSocketGatewayBase<Value, typeof DeviceFindWindows.sendMessage, typeof DeviceFindWindows.receiveMessage> | ||
implements OnWebSocketMessage<Value, typeof DeviceFindWindows.sendMessage, typeof DeviceFindWindows.receiveMessage>, OnWebSocketClose<Value> | ||
{ | ||
constructor(private readonly scanService: ScanService, private readonly logger: DoguLogger) { | ||
super(DeviceFindWindows, logger); | ||
} | ||
|
||
override onWebSocketOpen(webSocket: WebSocket, incommingMessage: IncomingMessage): Value { | ||
return { serial: '', parentPid: 0, timer: null, updateGuard: new DuplicatedCallGuarder() }; | ||
} | ||
|
||
async onWebSocketMessage(webSocket: WebSocket, message: Instance<typeof DeviceFindWindows.sendMessage>, valueAccessor: WebSocketRegistryValueAccessor<Value>): Promise<void> { | ||
const { updateGuard } = valueAccessor.get(); | ||
const { serial, parentPid, isSafari } = message; | ||
const deviceChannel = this.scanService.findChannel(serial); | ||
if (deviceChannel === null) { | ||
throw new Error(`Device with serial ${serial} not found`); | ||
} | ||
|
||
const categoryPlatform = categoryFromPlatform(platformTypeFromPlatform(deviceChannel.platform)); | ||
if (categoryPlatform !== 'desktop') { | ||
throw new Error(`Device with serial ${serial} is not desktop`); | ||
} | ||
|
||
const timer = setInterval(() => { | ||
updateGuard | ||
.guard(async () => { | ||
const deviceChannel = this.scanService.findChannel(serial); | ||
if (deviceChannel === null) { | ||
throw new Error(`Device with serial ${serial} not found`); | ||
} | ||
const windows = await deviceChannel.getWindows(); | ||
const childProcess = await getChildProcessIds(parentPid, this.logger); | ||
if (isSafari && process.platform === 'darwin') { | ||
const procs = await getProcessesMapMacos(this.logger); | ||
const safariProc = Array.from(procs).find((proc) => proc[1].commandLine.includes('Safari.app/Contents/MacOS/Safari')); | ||
if (safariProc) { | ||
childProcess.push(safariProc[0]); | ||
} | ||
} | ||
const targetWindow = windows.find((window) => childProcess.includes(window.pid)); | ||
if (!targetWindow) { | ||
return; | ||
} | ||
this.send(webSocket, { | ||
pid: targetWindow.pid, | ||
width: targetWindow.width, | ||
height: targetWindow.height, | ||
}); | ||
await Promise.resolve(); | ||
}) | ||
.catch((error) => { | ||
this.logger.error('Failed to find windows', { error: errorify(error) }); | ||
}); | ||
}, 1000); | ||
valueAccessor.update({ serial, parentPid, timer, updateGuard }); | ||
await Promise.resolve(); | ||
} | ||
|
||
async onWebSocketClose(webSocket: WebSocket, event: WebSocket.CloseEvent, valueAccessor: WebSocketRegistryValueAccessor<Value>): Promise<void> { | ||
const { timer } = valueAccessor.get(); | ||
if (timer) { | ||
clearInterval(timer); | ||
} | ||
closeWebSocketWithTruncateReason(webSocket, 1000, 'Finding windows finished'); | ||
await Promise.resolve(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.