@@ -39,6 +39,16 @@ export interface ConnectionOptions {
39
39
* GRPC Channel arguments
40
40
*
41
41
* @see option descriptions {@link https://grpc.github.io/grpc/core/group__grpc__arg__keys.html | here}
42
+ *
43
+ * By default the SDK sets the following keepalive arguments:
44
+ *
45
+ * ```
46
+ * grpc.keepalive_permit_without_calls: 1
47
+ * grpc.keepalive_time_ms: 30_000
48
+ * grpc.keepalive_timeout_ms: 15_000
49
+ * ```
50
+ *
51
+ * To opt-out of keepalive, override these keys with `undefined`.
42
52
*/
43
53
channelArgs ?: grpc . ChannelOptions ;
44
54
@@ -75,18 +85,21 @@ export type ConnectionOptionsWithDefaults = Required<Omit<ConnectionOptions, 'tl
75
85
76
86
export const LOCAL_TARGET = '127.0.0.1:7233' ;
77
87
78
- export function defaultConnectionOpts ( ) : ConnectionOptionsWithDefaults {
88
+ function addDefaults ( options : ConnectionOptions ) : ConnectionOptionsWithDefaults {
89
+ const { channelArgs, interceptors, ...rest } = options ;
79
90
return {
80
91
address : LOCAL_TARGET ,
81
92
credentials : grpc . credentials . createInsecure ( ) ,
82
93
channelArgs : {
83
94
'grpc.keepalive_permit_without_calls' : 1 ,
84
95
'grpc.keepalive_time_ms' : 30_000 ,
85
96
'grpc.keepalive_timeout_ms' : 15_000 ,
97
+ ...channelArgs ,
86
98
} ,
87
- interceptors : [ makeGrpcRetryInterceptor ( defaultGrpcRetryOptions ( ) ) ] ,
99
+ interceptors : interceptors ?? [ makeGrpcRetryInterceptor ( defaultGrpcRetryOptions ( ) ) ] ,
88
100
metadata : { } ,
89
101
connectTimeoutMs : 10_000 ,
102
+ ...filterNullAndUndefined ( rest ) ,
90
103
} ;
91
104
}
92
105
@@ -192,10 +205,7 @@ export class Connection {
192
205
readonly callContextStorage : AsyncLocalStorage < CallContext > ;
193
206
194
207
protected static createCtorOptions ( options ?: ConnectionOptions ) : ConnectionCtorOptions {
195
- const optionsWithDefaults = {
196
- ...defaultConnectionOpts ( ) ,
197
- ...filterNullAndUndefined ( normalizeGRPCConfig ( options ) ) ,
198
- } ;
208
+ const optionsWithDefaults = addDefaults ( normalizeGRPCConfig ( options ) ) ;
199
209
// Allow overriding this
200
210
optionsWithDefaults . metadata [ 'client-name' ] ??= 'temporal-typescript' ;
201
211
optionsWithDefaults . metadata [ 'client-version' ] ??= pkg . version ;
0 commit comments