public void publish()

in src/main/java/com/amazonaws/kvstranscribestreaming/publisher/WebSocketTranscriptionPublisher.java [70:95]


    public void publish(TranscriptEvent event) {
        List<Result> results = event.transcript().results();
        if (results.size() > 0) {
            Result result = results.get(0);
            if (!result.isPartial()) {
                try {
                    logger.info("{} transcription event is {}", WEB_SOCKET_PUBLISHER_PREFIX, event.toString());

                    if(getConnectionId() == null) {
                        logger.info("{} connection id is null. Waiting for updating connection Id", WEB_SOCKET_PUBLISHER_PREFIX);
                        return;
                    }
                    PostToConnectionRequest request = new PostToConnectionRequest().withConnectionId(this.connectionId).withData(StandardCharsets.UTF_8.encode(buildTranscription(result)));
                    PostToConnectionResult postResult = apigatewayClient.postToConnection(request);
                    logger.info("{} connection id is {}, post to connection result is {}", WEB_SOCKET_PUBLISHER_PREFIX, this.connectionId, postResult.toString());

                    // No need to handle http response.
                } catch(GoneException e) {
                    logger.error("{} the connection with the provided id no longer exists. Refreshing connection id, message: {}", WEB_SOCKET_PUBLISHER_PREFIX, e.getMessage(), e);
                    this.connectionId = null;
                } catch (Exception e) {
                    logger.error("{} publish encountered exception, error message: {}", WEB_SOCKET_PUBLISHER_PREFIX, e.getMessage(), e);
                }
            }
        }
    }