1+ const DebugRouterConnector = require ( "@lynx-js/debug-router-connector" ) . DebugRouterConnector ;
2+
3+ const util = require ( './util.js' ) ;
4+
5+ function sleep ( ms ) {
6+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
7+ }
8+
9+ let successCount = 0 ;
10+
11+ async function TryConnect ( driver , serial , num ) {
12+ console . log ( 'TryConnect start: ' , num ) ;
13+ const clients = await driver . connectUsbClients ( serial , 5000 ) ;
14+ if ( clients && clients . length > 0 ) {
15+ console . log ( clients [ 0 ] . info . query . raw_info ) ;
16+ successCount ++ ;
17+
18+ console . log ( 'checkConnect' ) ;
19+ console . log ( 'TryConnect check connect start: ' , num ) ;
20+ const message = 'a' . repeat ( 20 ) ;
21+ const result = await clients [ 0 ] . sendCustomizedMessage ( "App.GetCloseCoverageUploadSwitch" , { message : message } , - 1 , "App" ) ;
22+ console . log ( result ) ;
23+ if ( ! result ) {
24+ console . error ( 'sendCustomizedMessage failed' ) ;
25+ process . exit ( - 1 ) ;
26+ } else {
27+ console . log ( 'sendCustomizedMessage success' ) ;
28+ process . exit ( 0 ) ;
29+ }
30+
31+ } else {
32+ console . error ( 'no clients connected' ) ;
33+ }
34+ console . log ( 'TryConnect end: ' , num ) ;
35+ }
36+
37+ async function main ( ) {
38+ const startActivity = 'adb shell am start -n com.lynx.debugrouter.testapp/com.lynx.debugrouter.testapp.MainActivity'
39+ util . exec ( startActivity , 10000 ) . then ( ( data ) => {
40+ console . log ( "startActivity:" + data ) ;
41+ } ) . catch ( ( reason ) => {
42+ console . log ( "startActivity FAILED:" + reason ) ;
43+ process . exit ( - 1 ) ;
44+ } ) ;
45+
46+ const driver = new DebugRouterConnector ( {
47+ manualConnect : true ,
48+ enableWebSocket : false ,
49+ enableAndroid : true ,
50+ enableIOS : true ,
51+ enableDesktop : false ,
52+ websocketOption : { }
53+ } ) ;
54+
55+ try {
56+ const devicesArray = await driver . connectDevices ( 5000 ) ;
57+ if ( devicesArray . length === 0 ) {
58+ console . error ( 'no devices connected' ) ;
59+ return ;
60+ }
61+ var serial = devicesArray [ 0 ] . serial ;
62+ const Connect0 = TryConnect ( driver , serial , 1 ) ;
63+ await sleep ( 3000 ) ;
64+ const Connect1 = TryConnect ( driver , serial , 2 ) ;
65+ await sleep ( 3000 ) ;
66+ const Connect2 = TryConnect ( driver , serial , 3 ) ;
67+ await sleep ( 3000 ) ;
68+ const Connect3 = TryConnect ( driver , serial , 4 ) ;
69+ await sleep ( 3000 ) ;
70+ const Connect4 = TryConnect ( driver , serial , 5 ) ;
71+ await sleep ( 3000 ) ;
72+ const Connect5 = TryConnect ( driver , serial , 6 ) ;
73+ await sleep ( 3000 ) ;
74+ const Connect6 = TryConnect ( driver , serial , 7 ) ;
75+ await sleep ( 3000 ) ;
76+ const Connect7 = TryConnect ( driver , serial , 8 ) ;
77+ await sleep ( 3000 ) ;
78+ const Connect8 = TryConnect ( driver , serial , 9 ) ;
79+ await sleep ( 3000 ) ;
80+ const Connect9 = TryConnect ( driver , serial , 10 ) ;
81+ await sleep ( 3000 ) ;
82+ await Promise . all ( [ Connect0 , Connect1 , Connect2 , Connect3 , Connect4 , Connect5 , Connect6 , Connect7 , Connect8 , Connect9 ] ) ;
83+ console . log ( 'successCount: ' , successCount ) ;
84+ } catch ( error ) {
85+ console . error ( 'Call tryConnect error: ' , error ) ;
86+ }
87+ process . exit ( 0 ) ;
88+ }
89+
90+ main ( ) ;
0 commit comments