import { Label, MessageBar, PrimaryButton, Stack, StackItem, Text, TextField } from '@fluentui/react'; import { useId } from '@uifabric/react-hooks'; import React, { useCallback, useEffect, useState } from 'react'; import { CommonStackTokens } from '../styles'; import { withDisplayName } from '../utils'; import { RouteProps } from './type'; export default withDisplayName('TcpIp', ({ device }: RouteProps): JSX.Element | null => { const [tcpPort, setTcpAddresses] = useState(); useEffect(() => { if (!device) { setTcpAddresses(undefined); } }, [device]); const queryTcpAddress = useCallback(async () => { if (!device) { return; } const result = await device.tcpip.getAddresses(); setTcpAddresses(result); }, [device]); const [tcpPortValue, setTcpPortValue] = useState('5555'); const tcpPortInputId = useId('tcpPort'); const enableTcp = useCallback(async () => { if (!device) { return; } await device.tcpip.setPort(Number.parseInt(tcpPortValue, 10)); }, [device, tcpPortValue]); const disableTcp = useCallback(async () => { if (!device) { return; } await device.tcpip.disable(); }, [device]); return ( <> Although WebADB can enable ADB over WiFi for you, it can't connect to your device wirelessly. Your device will disconnect after changing ADB over WiFi config. {tcpPort !== undefined && (tcpPort.length !== 0 ? `Enabled at ${tcpPort.join(', ')}` : 'Disabled')} setTcpPortValue(value!)} /> ); });