@@ -14,16 +14,16 @@ import type { GrpcWebTransportAdditionalOptions } from '../../types'
1414 * It uses the GrpcWebRpcTransport with GrpcWebFetchTransport from @protobuf-ts/grpcweb-transport.
1515 */
1616export default class BaseGrpcConsumer {
17- protected transport : GrpcWebRpcTransport
17+ private _client : unknown
18+ protected endpoint : string
1819 protected module : string = ''
20+ protected transport : GrpcWebRpcTransport
1921 protected metadata ?: Record < string , string >
20- protected endpoint : string
2122 protected options ?: GrpcWebTransportAdditionalOptions
22- private _client : unknown
2323
2424 constructor ( endpoint : string , options ?: GrpcWebTransportAdditionalOptions ) {
25- this . endpoint = endpoint
2625 this . options = options
26+ this . endpoint = endpoint
2727 this . transport = new GrpcWebRpcTransport ( endpoint , options )
2828 }
2929
@@ -37,6 +37,10 @@ export default class BaseGrpcConsumer {
3737 ...this . options ,
3838 meta : this . metadata ,
3939 } )
40+
41+ // Invalidate cached client so initClient creates a new client with updated transport
42+ this . _client = undefined
43+
4044 return this
4145 }
4246
@@ -45,6 +49,10 @@ export default class BaseGrpcConsumer {
4549 */
4650 public clearMetadata ( ) {
4751 this . metadata = undefined
52+ // Recreate transport without metadata, preserving existing options
53+ this . transport = new GrpcWebRpcTransport ( this . endpoint , this . options )
54+ // Invalidate cached client so initClient creates a new client with updated transport
55+ this . _client = undefined
4856 }
4957
5058 public getTransport ( ) : GrpcWebRpcTransport {
@@ -66,6 +74,7 @@ export default class BaseGrpcConsumer {
6674 if ( ! this . _client ) {
6775 this . _client = new ClientClass ( this . transport )
6876 }
77+
6978 return this . _client as TClient
7079 }
7180
0 commit comments