@@ -32,17 +32,32 @@ class Client {
3232
3333 Connect ( ) {
3434 return new Promise ( ( resolve , reject ) => {
35- this . socket = ( this . tls ? tls : net ) . createConnection ( { host : this . host , port : this . port } , ( ) => {
36- this . socket . write ( "Authentication: " + Buffer . from ( this . username + "\\0" + this . password ) . toString ( 'base64' ) + "\r\n" ) ;
37-
38- this . socket . on ( 'data' , function ( data ) {
39- if ( data . toString ( ) . startsWith ( "0" ) ) {
40- resolve ( "Connected to CursusDB cluster successfully." )
41- } else {
42- reject ( data . toString ( ) )
43- }
35+ if ( this . tls ) {
36+ this . socket = tls . connect ( { host : this . host , port : this . port } , ( ) => {
37+ this . socket . write ( "Authentication: " + Buffer . from ( this . username + "\\0" + this . password ) . toString ( 'base64' ) + "\r\n" ) ;
38+
39+ this . socket . on ( 'data' , function ( data ) {
40+ if ( data . toString ( ) . startsWith ( "0" ) ) {
41+ resolve ( "Connected to CursusDB cluster successfully." )
42+ } else {
43+ reject ( data . toString ( ) )
44+ }
45+ } ) ;
46+ } ) ;
47+ } else {
48+ this . socket = net . createConnection ( { host : this . host , port : this . port } , ( ) => {
49+ this . socket . write ( "Authentication: " + Buffer . from ( this . username + "\\0" + this . password ) . toString ( 'base64' ) + "\r\n" ) ;
50+
51+ this . socket . on ( 'data' , function ( data ) {
52+ if ( data . toString ( ) . startsWith ( "0" ) ) {
53+ resolve ( "Connected to CursusDB cluster successfully." )
54+ } else {
55+ reject ( data . toString ( ) )
56+ }
57+ } ) ;
4458 } ) ;
45- } ) ;
59+ }
60+
4661 } )
4762 }
4863
0 commit comments