1+ import * as net from 'net' ;
12import { BaseProtocol } from './protocol/base-protocol' ;
23import BaseConnection from './connection/base-connection' ;
34import { JsonProtocol } from './protocol/json-protocol' ;
89 TriggerHookRequest ,
910 JunoMessage
1011} from './models/messages' ;
11- import SocketConnection from './connection/unix-socket-connection' ;
12+ import UnixSocketConnection from './connection/unix-socket-connection' ;
13+ import InetSocketConnection from './connection/inet-socket-connection' ;
1214
1315export default class JunoModule {
1416
@@ -27,8 +29,25 @@ export default class JunoModule {
2729 // this.connection.setOnDataListener(this.onDataHandler);
2830 }
2931
30- public static default ( socketPath : string ) : JunoModule {
31- return new JunoModule ( new SocketConnection ( socketPath ) , new JsonProtocol ( ) ) ;
32+ public static async default ( socketPath : string ) {
33+ if ( net . isIP ( socketPath . split ( ':' ) [ 0 ] ) ) {
34+ const [ host , port ] = socketPath . split ( ':' ) ;
35+ return this . fromInetSocket ( host , Number ( port ) ) ;
36+ } else {
37+ return this . fromUnixSocket ( socketPath ) ;
38+ }
39+ }
40+
41+ public static fromUnixSocket ( path : string ) {
42+ // Return Error if invoked from windows
43+ if ( process . platform == 'win32' ) {
44+ throw new Error ( 'Unix sockets are not supported on windows' ) ;
45+ }
46+ return new JunoModule ( new UnixSocketConnection ( path ) , new JsonProtocol ( ) ) ;
47+ }
48+
49+ public static fromInetSocket ( host : string , port : number ) {
50+ return new JunoModule ( new InetSocketConnection ( host , port ) , new JsonProtocol ( ) ) ;
3251 }
3352
3453 public async initialize (
0 commit comments