@@ -48,6 +48,7 @@ class Daemon {
48
48
this . started = false
49
49
this . clean = true
50
50
this . apiAddr = null
51
+ this . grpcAddr = null
51
52
this . gatewayAddr = null
52
53
this . api = null
53
54
}
@@ -58,9 +59,14 @@ class Daemon {
58
59
*/
59
60
_setApi ( addr ) {
60
61
this . apiAddr = multiaddr ( addr )
61
- this . api = this . opts . ipfsHttpModule ( addr )
62
- this . api . apiHost = this . apiAddr . nodeAddress ( ) . address
63
- this . api . apiPort = this . apiAddr . nodeAddress ( ) . port
62
+ }
63
+
64
+ /**
65
+ * @private
66
+ * @param {string } addr
67
+ */
68
+ _setGrpc ( addr ) {
69
+ this . grpcAddr = multiaddr ( addr )
64
70
}
65
71
66
72
/**
@@ -69,8 +75,36 @@ class Daemon {
69
75
*/
70
76
_setGateway ( addr ) {
71
77
this . gatewayAddr = multiaddr ( addr )
72
- this . api . gatewayHost = this . gatewayAddr . nodeAddress ( ) . address
73
- this . api . gatewayPort = this . gatewayAddr . nodeAddress ( ) . port
78
+ }
79
+
80
+ _createApi ( ) {
81
+ if ( this . opts . ipfsClientModule && this . grpcAddr ) {
82
+ this . api = this . opts . ipfsClientModule ( {
83
+ grpc : this . grpcAddr ,
84
+ http : this . apiAddr
85
+ } )
86
+ } else if ( this . apiAddr ) {
87
+ this . api = this . opts . ipfsHttpModule ( this . apiAddr )
88
+ }
89
+
90
+ if ( ! this . api ) {
91
+ throw new Error ( `Could not create API from http '${ this . apiAddr } ' and/or gRPC '${ this . grpcAddr } '` )
92
+ }
93
+
94
+ if ( this . apiAddr ) {
95
+ this . api . apiHost = this . apiAddr . nodeAddress ( ) . address
96
+ this . api . apiPort = this . apiAddr . nodeAddress ( ) . port
97
+ }
98
+
99
+ if ( this . gatewayAddr ) {
100
+ this . api . gatewayHost = this . gatewayAddr . nodeAddress ( ) . address
101
+ this . api . gatewayPort = this . gatewayAddr . nodeAddress ( ) . port
102
+ }
103
+
104
+ if ( this . grpcAddr ) {
105
+ this . api . grpcHost = this . grpcAddr . nodeAddress ( ) . address
106
+ this . api . grpcPort = this . grpcAddr . nodeAddress ( ) . port
107
+ }
74
108
}
75
109
76
110
/**
@@ -150,6 +184,7 @@ class Daemon {
150
184
151
185
if ( api ) {
152
186
this . _setApi ( api )
187
+ this . _createApi ( )
153
188
} else if ( ! this . exec ) {
154
189
throw new Error ( 'No executable specified' )
155
190
} else {
@@ -168,6 +203,7 @@ class Daemon {
168
203
output += data . toString ( )
169
204
const apiMatch = output . trim ( ) . match ( / A P I .* l i s t e n i n g o n : ? ( .* ) / )
170
205
const gwMatch = output . trim ( ) . match ( / G a t e w a y .* l i s t e n i n g o n : ? ( .* ) / )
206
+ const grpcMatch = output . trim ( ) . match ( / g R P C .* l i s t e n i n g o n : ? ( .* ) / )
171
207
172
208
if ( apiMatch && apiMatch . length > 0 ) {
173
209
this . _setApi ( apiMatch [ 1 ] )
@@ -177,8 +213,13 @@ class Daemon {
177
213
this . _setGateway ( gwMatch [ 1 ] )
178
214
}
179
215
216
+ if ( grpcMatch && grpcMatch . length > 0 ) {
217
+ this . _setGrpc ( grpcMatch [ 1 ] )
218
+ }
219
+
180
220
if ( output . match ( / (?: d a e m o n i s r u n n i n g | D a e m o n i s r e a d y ) / ) ) {
181
221
// we're good
222
+ this . _createApi ( )
182
223
this . started = true
183
224
this . subprocess . stdout . off ( 'data' , readyHandler )
184
225
resolve ( this . api )
0 commit comments