@@ -17,6 +17,11 @@ public final class FaceLivenessSession: LivenessService {
17
17
let baseURL : URL
18
18
var serverEventListeners : [ LivenessEventKind . Server : ( FaceLivenessSession . SessionConfiguration ) -> Void ] = [ : ]
19
19
var onComplete : ( ServerDisconnection ) -> Void = { _ in }
20
+
21
+ private let livenessServiceDispatchQueue = DispatchQueue (
22
+ label: " com.amazon.aws.amplify.liveness.service " ,
23
+ target: . global( )
24
+ )
20
25
21
26
init (
22
27
websocket: WebSocketSession ,
@@ -77,36 +82,38 @@ public final class FaceLivenessSession: LivenessService {
77
82
78
83
public func send< T> (
79
84
_ event: LivenessEvent < T > ,
80
- eventDate: ( ) -> Date = Date . init
85
+ eventDate: @escaping ( ) -> Date = Date . init
81
86
) {
82
- let encodedPayload = eventStreamEncoder. encode (
83
- payload: event. payload,
84
- headers: [
85
- " :content-type " : . string( " application/json " ) ,
86
- " :event-type " : . string( event. eventTypeHeader) ,
87
- " :message-type " : . string( " event " )
88
- ]
89
- )
90
-
91
- let eventDate = eventDate ( )
92
-
93
- let signedPayload = signer. signWithPreviousSignature (
94
- payload: encodedPayload,
95
- dateHeader: ( key: " :date " , value: eventDate)
96
- )
97
-
98
- let encodedEvent = eventStreamEncoder. encode (
99
- payload: encodedPayload,
100
- headers: [
101
- " :date " : . timestamp( eventDate) ,
102
- " :chunk-signature " : . data( signedPayload)
103
- ]
104
- )
105
-
106
- websocket. send (
107
- message: . data( encodedEvent) ,
108
- onError: { _ in }
109
- )
87
+ livenessServiceDispatchQueue. async {
88
+ let encodedPayload = self . eventStreamEncoder. encode (
89
+ payload: event. payload,
90
+ headers: [
91
+ " :content-type " : . string( " application/json " ) ,
92
+ " :event-type " : . string( event. eventTypeHeader) ,
93
+ " :message-type " : . string( " event " )
94
+ ]
95
+ )
96
+
97
+ let eventDate = eventDate ( )
98
+
99
+ let signedPayload = self . signer. signWithPreviousSignature (
100
+ payload: encodedPayload,
101
+ dateHeader: ( key: " :date " , value: eventDate)
102
+ )
103
+
104
+ let encodedEvent = self . eventStreamEncoder. encode (
105
+ payload: encodedPayload,
106
+ headers: [
107
+ " :date " : . timestamp( eventDate) ,
108
+ " :chunk-signature " : . data( signedPayload)
109
+ ]
110
+ )
111
+
112
+ self . websocket. send (
113
+ message: . data( encodedEvent) ,
114
+ onError: { _ in }
115
+ )
116
+ }
110
117
}
111
118
112
119
private func fallbackDecoding( _ message: EventStream . Message ) -> Bool {
0 commit comments