@@ -23,27 +23,37 @@ function getServerIpAddress(host, port) {
23
23
}
24
24
}
25
25
26
- // ios or android device use ` localhost`
27
- return `localhost :${ port } `
26
+ // ios simulator uses localhost
27
+ return `127.0.0.1 :${ port } `
28
28
}
29
29
30
30
module . exports = function install ( Vue , { debug = false , host = null , port = 8098 } = { } ) {
31
31
const startApp = Vue . prototype . $start
32
32
33
33
Vue . prototype . $start = function ( ) {
34
- devtools . connect ( 'ws://localhost' , port , {
35
- app : this ,
36
- showToast : ( message ) => require ( 'nativescript-toast' ) . makeText ( message ) . show ( ) ,
37
- io ( ) {
38
- const address = `http://${ getServerIpAddress ( host , port ) } `
39
- const SocketIO = require ( 'nativescript-socket.io' )
40
- debug && SocketIO . enableDebug ( )
41
-
42
- return SocketIO . connect ( address )
43
- }
44
- } )
45
-
46
- devtools . init ( Vue ) ;
34
+ const setupDevtools = ( ) => {
35
+ devtools . connect ( 'ws://localhost' , port , {
36
+ app : this ,
37
+ showToast : ( message ) => require ( 'nativescript-toast' ) . makeText ( message ) . show ( ) ,
38
+ io ( ) {
39
+ const address = `http://${ getServerIpAddress ( host , port ) } `
40
+ const SocketIO = require ( 'nativescript-socket.io' )
41
+ debug && SocketIO . enableDebug ( )
42
+ return SocketIO . connect ( address )
43
+ }
44
+ } )
45
+
46
+ devtools . init ( Vue ) ;
47
+ }
48
+
49
+ if ( isAndroid ) {
50
+ setupDevtools ( )
51
+ } else {
52
+ // on ios we need to delay the call because the socket connection is not established
53
+ // if called too early in the application startup process
54
+ // we might need to add a delay to the setTimeout in the future
55
+ setTimeout ( setupDevtools )
56
+ }
47
57
48
58
return startApp . call ( this )
49
59
}
0 commit comments