-
Notifications
You must be signed in to change notification settings - Fork 461
/
MediaEndpoint.java
649 lines (582 loc) · 21.4 KB
/
MediaEndpoint.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
/*
* (C) Copyright 2017-2020 OpenVidu (https://openvidu.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package io.openvidu.server.kurento.endpoint;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.kurento.client.BaseRtpEndpoint;
import org.kurento.client.Continuation;
import org.kurento.client.Endpoint;
import org.kurento.client.ErrorEvent;
import org.kurento.client.EventListener;
import org.kurento.client.IceCandidate;
import org.kurento.client.ListenerSubscription;
import org.kurento.client.MediaElement;
import org.kurento.client.MediaPipeline;
import org.kurento.client.PlayerEndpoint;
import org.kurento.client.RtpEndpoint;
import org.kurento.client.SdpEndpoint;
import org.kurento.client.WebRtcEndpoint;
import org.kurento.client.internal.server.KurentoServerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import io.openvidu.client.OpenViduException;
import io.openvidu.client.OpenViduException.Code;
import io.openvidu.java.client.KurentoOptions;
import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.core.Participant;
import io.openvidu.server.kurento.core.KurentoMediaOptions;
import io.openvidu.server.kurento.core.KurentoParticipant;
/**
* {@link Endpoint} wrapper. Can be based on WebRtcEndpoint (that supports
* buffering of {@link IceCandidate}s until the {@link WebRtcEndpoint} is
* created), PlayerEndpoint (to play RTSP or file streams) and RtpEndpoint.
* Connections to other peers are opened using the corresponding method of the
* internal endpoint.
*
* @author Pablo Fuente (pablofuenteperez@gmail.com)
*/
public abstract class MediaEndpoint {
private static Logger log;
private OpenviduConfig openviduConfig;
private EndpointType endpointType;
private WebRtcEndpoint webEndpoint = null;
private RtpEndpoint endpoint = null;
private PlayerEndpoint playerEndpoint = null;
private final int maxRecvKbps;
private final int minRecvKbps;
private final int maxSendKbps;
private final int minSendKbps;
private KurentoParticipant owner;
protected String endpointName; // KMS media object identifier. Unique for every MediaEndpoint
protected String streamId; // OpenVidu Stream identifier. Common property for a
// PublisherEndpoint->SubscriberEndpoint flow. Equal to endpointName for
// PublisherEndpoints, different for SubscriberEndpoints
protected Long createdAt; // Timestamp when this [publisher / subscriber] started [publishing / receiving]
private MediaPipeline pipeline = null;
private ListenerSubscription endpointSubscription = null;
private final List<IceCandidate> receivedCandidateList = Collections.synchronizedList(new ArrayList<>());
private final List<IceCandidate> gatheredCandidateList = Collections.synchronizedList(new ArrayList<>());
private LinkedList<IceCandidate> candidates = new LinkedList<IceCandidate>();
public String selectedLocalIceCandidate;
public String selectedRemoteIceCandidate;
public Queue<KmsEvent> kmsEvents = new ConcurrentLinkedQueue<>();
public Runnable kmsWebrtcStatsRunnable;
public AtomicInteger statsNotFoundErrors = new AtomicInteger(0);
public AtomicBoolean cancelStatsLoop = new AtomicBoolean(false);
/**
* Constructor to set the owner, the endpoint's name and the media pipeline.
*
* @param web
* @param owner
* @param endpointName
* @param pipeline
* @param log
*/
public MediaEndpoint(EndpointType endpointType, KurentoParticipant owner, String endpointName,
MediaPipeline pipeline, OpenviduConfig openviduConfig, Logger log) {
if (log == null) {
MediaEndpoint.log = LoggerFactory.getLogger(MediaEndpoint.class);
} else {
MediaEndpoint.log = log;
}
this.endpointType = endpointType;
this.owner = owner;
this.setEndpointName(endpointName);
this.setMediaPipeline(pipeline);
this.openviduConfig = openviduConfig;
KurentoOptions kurentoTokenOptions = this.owner.getToken().getKurentoOptions();
if (kurentoTokenOptions != null) {
this.maxRecvKbps = kurentoTokenOptions.getVideoMaxRecvBandwidth() != null
? kurentoTokenOptions.getVideoMaxRecvBandwidth()
: this.openviduConfig.getVideoMaxRecvBandwidth();
this.minRecvKbps = kurentoTokenOptions.getVideoMinRecvBandwidth() != null
? kurentoTokenOptions.getVideoMinRecvBandwidth()
: this.openviduConfig.getVideoMinRecvBandwidth();
this.maxSendKbps = kurentoTokenOptions.getVideoMaxSendBandwidth() != null
? kurentoTokenOptions.getVideoMaxSendBandwidth()
: this.openviduConfig.getVideoMaxSendBandwidth();
this.minSendKbps = kurentoTokenOptions.getVideoMinSendBandwidth() != null
? kurentoTokenOptions.getVideoMinSendBandwidth()
: this.openviduConfig.getVideoMinSendBandwidth();
} else {
this.maxRecvKbps = this.openviduConfig.getVideoMaxRecvBandwidth();
this.minRecvKbps = this.openviduConfig.getVideoMinRecvBandwidth();
this.maxSendKbps = this.openviduConfig.getVideoMaxSendBandwidth();
this.minSendKbps = this.openviduConfig.getVideoMinSendBandwidth();
}
}
public boolean isWeb() {
return EndpointType.WEBRTC_ENDPOINT.equals(this.endpointType);
}
public boolean isPlayerEndpoint() {
return EndpointType.PLAYER_ENDPOINT.equals(this.endpointType);
}
/**
* @return the user session that created this endpoint
*/
public Participant getOwner() {
return owner;
}
/**
* @return the internal endpoint ({@link RtpEndpoint} or {@link WebRtcEndpoint}
* or {@link PlayerEndpoint})
*/
public Endpoint getEndpoint() {
if (this.isWeb()) {
return this.webEndpoint;
} else if (this.isPlayerEndpoint()) {
return this.playerEndpoint;
} else {
return this.endpoint;
}
}
public BaseRtpEndpoint getBaseRtpEndpoint() {
if (this.isWeb()) {
return this.webEndpoint;
}
return this.endpoint;
}
public long createdAt() {
return this.createdAt;
}
public WebRtcEndpoint getWebEndpoint() {
return webEndpoint;
}
public RtpEndpoint getRtpEndpoint() {
return endpoint;
}
public PlayerEndpoint getPlayerEndpoint() {
return playerEndpoint;
}
/**
* If this object doesn't have a {@link WebRtcEndpoint}, it is created in a
* thread-safe way using the internal {@link MediaPipeline}. Otherwise no
* actions are taken. It also registers an error listener for the endpoint and
* for any additional media elements.
*
* @param endpointLatch latch whose countdown is performed when the asynchronous
* call to build the {@link WebRtcEndpoint} returns
*
* @return the existing endpoint, if any
*/
public synchronized Endpoint createEndpoint(CountDownLatch endpointLatch) {
Endpoint old = this.getEndpoint();
if (old == null) {
internalEndpointInitialization(endpointLatch);
} else {
endpointLatch.countDown();
if (this.isWeb()) {
while (!candidates.isEmpty()) {
internalAddIceCandidate(candidates.removeFirst());
}
}
}
return old;
}
/**
* @return the pipeline
*/
public MediaPipeline getPipeline() {
return this.pipeline;
}
/**
* Sets the {@link MediaPipeline} used to create the internal
* {@link WebRtcEndpoint}.
*
* @param pipeline the {@link MediaPipeline}
*/
public void setMediaPipeline(MediaPipeline pipeline) {
this.pipeline = pipeline;
}
public String getEndpointName() {
if (endpointName == null) {
endpointName = this.getEndpoint().getName();
}
return endpointName;
}
public void setEndpointName(String endpointName) {
this.endpointName = endpointName;
}
public String getStreamId() {
return streamId;
}
public void setStreamId(String streamId) {
this.streamId = streamId;
}
/**
* Unregisters all error listeners created for media elements owned by this
* instance.
*/
public synchronized void unregisterErrorListeners() {
unregisterElementErrListener(endpoint, endpointSubscription);
}
/**
* Creates the endpoint (RTP or WebRTC) and any other additional elements (if
* needed).
*
* @param endpointLatch
*/
protected void internalEndpointInitialization(final CountDownLatch endpointLatch) {
if (this.isWeb()) {
WebRtcEndpoint.Builder builder = new WebRtcEndpoint.Builder(pipeline);
/*
* if (this.dataChannels) { builder.useDataChannels(); }
*/
builder.buildAsync(new Continuation<WebRtcEndpoint>() {
@Override
public void onSuccess(WebRtcEndpoint result) throws Exception {
webEndpoint = result;
if (openviduConfig.getCoturnIp() != null && !openviduConfig.getCoturnIp().isEmpty()
&& openviduConfig.isTurnadminAvailable()) {
webEndpoint.setStunServerAddress(openviduConfig.getCoturnIp());
webEndpoint.setStunServerPort(3478);
}
endpointLatch.countDown();
while (!candidates.isEmpty()) {
internalAddIceCandidate(candidates.removeFirst());
}
log.trace("EP {}: Created a new WebRtcEndpoint", endpointName);
endpointSubscription = registerElemErrListener(webEndpoint);
// This can be done after unlocking latch. Not necessary to wait
webEndpoint.setMaxVideoRecvBandwidth(maxRecvKbps, new Continuation<Void>() {
@Override
public void onSuccess(Void result) throws Exception {
}
@Override
public void onError(Throwable cause) throws Exception {
log.error("Error setting max video receive bandwidth for endpoint {}: {}", endpointName,
cause.getMessage());
}
});
webEndpoint.setMinVideoRecvBandwidth(minRecvKbps, new Continuation<Void>() {
@Override
public void onSuccess(Void result) throws Exception {
}
@Override
public void onError(Throwable cause) throws Exception {
log.error("Error setting min video receive bandwidth for endpoint {}: {}", endpointName,
cause.getMessage());
}
});
webEndpoint.setMaxVideoSendBandwidth(maxSendKbps, new Continuation<Void>() {
@Override
public void onSuccess(Void result) throws Exception {
}
@Override
public void onError(Throwable cause) throws Exception {
log.error("Error setting max video send bandwidth for endpoint {}: {}", endpointName,
cause.getMessage());
}
});
webEndpoint.setMinVideoSendBandwidth(minSendKbps, new Continuation<Void>() {
@Override
public void onSuccess(Void result) throws Exception {
}
@Override
public void onError(Throwable cause) throws Exception {
log.error("Error setting min video send bandwidth for endpoint {}: {}", endpointName,
cause.getMessage());
}
});
}
@Override
public void onError(Throwable cause) throws Exception {
endpointLatch.countDown();
log.error("EP {}: Failed to create a new WebRtcEndpoint", endpointName, cause);
}
});
} else if (this.isPlayerEndpoint()) {
final KurentoMediaOptions mediaOptions = (KurentoMediaOptions) this.owner.getPublisherMediaOptions();
PlayerEndpoint.Builder playerBuilder = new PlayerEndpoint.Builder(pipeline, mediaOptions.rtspUri);
if (!mediaOptions.adaptativeBitrate) {
playerBuilder = playerBuilder.useEncodedMedia();
}
if (mediaOptions.networkCache != null) {
playerBuilder = playerBuilder.withNetworkCache(mediaOptions.networkCache);
}
playerBuilder.buildAsync(new Continuation<PlayerEndpoint>() {
@Override
public void onSuccess(PlayerEndpoint result) throws Exception {
playerEndpoint = result;
if (!mediaOptions.onlyPlayWithSubscribers) {
playerEndpoint.play(new Continuation<Void>() {
@Override
public void onSuccess(Void result) throws Exception {
log.info("IP Camera stream {} feed is now enabled", streamId);
}
@Override
public void onError(Throwable cause) throws Exception {
log.info("Error while enabling feed for IP camera {}: {}", streamId,
cause.getMessage());
}
});
}
log.trace("EP {}: Created a new PlayerEndpoint", endpointName);
endpointSubscription = registerElemErrListener(playerEndpoint);
endpointLatch.countDown();
}
@Override
public void onError(Throwable cause) throws Exception {
endpointLatch.countDown();
log.error("EP {}: Failed to create a new PlayerEndpoint", endpointName, cause);
}
});
} else {
new RtpEndpoint.Builder(pipeline).buildAsync(new Continuation<RtpEndpoint>() {
@Override
public void onSuccess(RtpEndpoint result) throws Exception {
endpoint = result;
endpointLatch.countDown();
log.trace("EP {}: Created a new RtpEndpoint", endpointName);
endpointSubscription = registerElemErrListener(endpoint);
}
@Override
public void onError(Throwable cause) throws Exception {
endpointLatch.countDown();
log.error("EP {}: Failed to create a new RtpEndpoint", endpointName, cause);
}
});
}
}
/**
* Add a new {@link IceCandidate} received gathered by the remote peer of this
* {@link WebRtcEndpoint}.
*
* @param candidate the remote candidate
*/
public synchronized void addIceCandidate(IceCandidate candidate) throws OpenViduException {
if (!this.isWeb()) {
throw new OpenViduException(Code.MEDIA_NOT_A_WEB_ENDPOINT_ERROR_CODE, "Operation not supported");
}
if (webEndpoint == null) {
candidates.addLast(candidate);
} else {
internalAddIceCandidate(candidate);
}
}
/**
* Registers a listener for when the {@link MediaElement} triggers an
* {@link ErrorEvent}. Notifies the owner with the error.
*
* @param element the {@link MediaElement}
* @return {@link ListenerSubscription} that can be used to deregister the
* listener
*/
protected ListenerSubscription registerElemErrListener(MediaElement element) {
return element.addErrorListener(new EventListener<ErrorEvent>() {
@Override
public void onEvent(ErrorEvent event) {
owner.sendMediaError(event);
}
});
}
/**
* Unregisters the error listener from the media element using the provided
* subscription.
*
* @param element the {@link MediaElement}
* @param subscription the associated {@link ListenerSubscription}
*/
protected void unregisterElementErrListener(MediaElement element, final ListenerSubscription subscription) {
if (element == null || subscription == null) {
return;
}
element.removeErrorListener(subscription);
}
/**
* Orders the internal endpoint ({@link RtpEndpoint} or {@link WebRtcEndpoint})
* to process the offer String.
*
* @see SdpEndpoint#processOffer(String)
* @param offer String with the Sdp offer
* @return the Sdp answer
*/
protected String processOffer(String offer) throws OpenViduException {
if (this.isWeb()) {
if (webEndpoint == null) {
throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
"Can't process offer when WebRtcEndpoint is null (ep: " + endpointName + ")");
}
return webEndpoint.processOffer(offer);
} else if (this.isPlayerEndpoint()) {
return "";
} else {
if (endpoint == null) {
throw new OpenViduException(Code.MEDIA_RTP_ENDPOINT_ERROR_CODE,
"Can't process offer when RtpEndpoint is null (ep: " + endpointName + ")");
}
return endpoint.processOffer(offer);
}
}
/**
* Orders the internal endpoint ({@link RtpEndpoint} or {@link WebRtcEndpoint})
* to process the answer String.
*
* @see SdpEndpoint#processAnswer(String)
* @param answer String with the Sdp answer from remote
* @return the updated Sdp offer, based on the received answer
*/
protected String processAnswer(String answer) throws OpenViduException {
if (this.isWeb()) {
if (webEndpoint == null) {
throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
"Can't process answer when WebRtcEndpoint is null (ep: " + endpointName + ")");
}
return webEndpoint.processAnswer(answer);
} else if (this.isPlayerEndpoint()) {
return "";
} else {
if (endpoint == null) {
throw new OpenViduException(Code.MEDIA_RTP_ENDPOINT_ERROR_CODE,
"Can't process answer when RtpEndpoint is null (ep: " + endpointName + ")");
}
return endpoint.processAnswer(answer);
}
}
/**
* If supported, it registers a listener for when a new {@link IceCandidate} is
* gathered by the internal endpoint ({@link WebRtcEndpoint}) and sends it to
* the remote User Agent as a notification using the messaging capabilities of
* the {@link Participant}.
*
* @see WebRtcEndpoint#addOnIceCandidateListener(org.kurento.client.EventListener)
* @see Participant#sendIceCandidate(String, IceCandidate)
* @throws OpenViduException if thrown, unable to register the listener
*/
protected void registerOnIceCandidateEventListener(String senderPublicId) throws OpenViduException {
if (!this.isWeb()) {
return;
}
if (webEndpoint == null) {
throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
"Can't register event listener for null WebRtcEndpoint (ep: " + endpointName + ")");
}
webEndpoint.addIceCandidateFoundListener(event -> {
final IceCandidate candidate = event.getCandidate();
gatheredCandidateList.add(candidate);
owner.sendIceCandidate(senderPublicId, endpointName, candidate);
});
}
/**
* If supported, it instructs the internal endpoint to start gathering
* {@link IceCandidate}s.
*/
protected void gatherCandidates() throws OpenViduException {
if (!this.isWeb()) {
return;
}
if (webEndpoint == null) {
throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
"Can't start gathering ICE candidates on null WebRtcEndpoint (ep: " + endpointName + ")");
}
webEndpoint.gatherCandidates(new Continuation<Void>() {
@Override
public void onSuccess(Void result) throws Exception {
log.trace("EP {}: Internal endpoint started to gather candidates", endpointName);
}
@Override
public void onError(Throwable cause) throws Exception {
log.warn("EP {}: Internal endpoint failed to start gathering candidates", endpointName, cause);
}
});
}
private void internalAddIceCandidate(IceCandidate candidate) throws OpenViduException {
if (webEndpoint == null) {
throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
"Can't add existing ICE candidates to null WebRtcEndpoint (ep: " + endpointName + ")");
}
this.receivedCandidateList.add(candidate);
this.webEndpoint.addIceCandidate(candidate, new Continuation<Void>() {
@Override
public void onSuccess(Void result) throws Exception {
log.trace("Ice candidate \"{}\" added to the internal endpoint", candidate.getCandidate());
}
@Override
public void onError(Throwable cause) throws Exception {
log.warn("EP {}: Failed to add ice candidate \"{}\" to the internal endpoint: {}", endpointName,
candidate.getCandidate(), cause.getMessage());
}
});
}
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.addProperty("createdAt", this.createdAt);
return json;
}
public JsonObject withStatsToJson() {
JsonObject json = new JsonObject();
json.addProperty("createdAt", this.createdAt);
json.addProperty("webrtcEndpointName", this.getEndpointName());
if (!this.isPlayerEndpoint()) {
try {
json.addProperty("remoteSdp", ((SdpEndpoint) this.getEndpoint()).getRemoteSessionDescriptor());
} catch (KurentoServerException e) {
log.error("Error retrieving remote SDP for endpoint {} of stream {}: {}", this.endpointName,
this.streamId, e.getMessage());
json.add("remoteSdp", JsonNull.INSTANCE);
}
try {
json.addProperty("localSdp", ((SdpEndpoint) this.getEndpoint()).getLocalSessionDescriptor());
} catch (KurentoServerException e) {
log.error("Error retrieving local SDP for endpoint {} of stream {}: {}", this.endpointName,
this.streamId, e.getMessage());
json.add("localSdp", JsonNull.INSTANCE);
}
}
Gson gson = new GsonBuilder().create();
JsonArray receivedCandidates = new JsonArray();
Iterator<IceCandidate> it1 = this.receivedCandidateList.iterator();
while (it1 != null && it1.hasNext()) {
receivedCandidates.add(gson.toJsonTree(it1.next()));
}
json.add("receivedCandidates", receivedCandidates);
JsonArray gatheredCandidates = new JsonArray();
Iterator<IceCandidate> it2 = this.gatheredCandidateList.iterator();
while (it2 != null && it2.hasNext()) {
gatheredCandidates.add(gson.toJsonTree(it2.next()));
}
json.add("gatheredCandidates", gatheredCandidates);
json.addProperty("localCandidate", this.selectedLocalIceCandidate);
json.addProperty("remoteCandidate", this.selectedRemoteIceCandidate);
JsonArray jsonArray = new JsonArray();
this.kmsEvents.forEach(ev -> {
// Remove unwanted properties
JsonObject j = ev.toJson();
j.remove("sessionId");
j.remove("user");
j.remove("connection");
j.remove("endpoint");
j.remove("timestampMillis");
jsonArray.add(j);
});
json.add("events", jsonArray);
return json;
}
}