@@ -22,6 +22,9 @@ class RNGrpc: RCTEventEmitter {
2222 var grpcCompression : Bool ?
2323 var grpcCompressorName : String ?
2424 var grpcCompressionLimit : Int ?
25+ var grpcKeepaliveEnabled : Bool ?
26+ var grpcKeepaliveTime : Int64 ?
27+ var grpcKeepaliveTimeout : Int64 ?
2528 var calls = [ Int: GrpcCall] ( )
2629
2730 deinit {
@@ -44,6 +47,12 @@ class RNGrpc: RCTEventEmitter {
4447 self . grpcCompression = enabled. boolValue
4548 self . grpcCompressorName = compressorName
4649 self . grpcCompressionLimit = Int ( limit ?? " " )
50+
51+ @objc
52+ public func setKeepalive( _ enabled: NSNumber , time: NSNumber , timeout: NSNumber ) {
53+ self . grpcKeepaliveEnabled = enabled. boolValue
54+ self . grpcKeepaliveTime = time. int64Value
55+ self . grpcKeepaliveTimeout = timeout. int64Value
4756 }
4857
4958 @objc
@@ -361,6 +370,20 @@ class RNGrpc: RCTEventEmitter {
361370 config. maximumReceiveMessageLength = maxReceiveSize
362371 }
363372
373+ if let enabled = grpcKeepaliveEnabled, enabled {
374+ let interval = self . grpcKeepaliveTime != nil ? TimeAmount . seconds ( self . grpcKeepaliveTime!) : TimeAmount . nanoseconds ( . max)
375+
376+ let timeout = TimeAmount . seconds ( grpcKeepaliveTimeout ?? 20 )
377+
378+ let keepalive = ClientConnectionKeepalive (
379+ interval: interval,
380+ timeout: timeout,
381+ permitWithoutCalls: true
382+ )
383+
384+ config. keepalive = keepalive
385+ }
386+
364387 return try ? GRPCChannelPool . with ( configuration: config)
365388 }
366389
0 commit comments