Код: Выделить всё
------------- FLUX approach ------------
@GetMapping(value = "/video-flux", produces = "video/mp2t")
public Flux videoFlux(@PathVariable Long deviceId, HttpServletResponse response) {
// return Flux of byte[] from camera
}
------------ StreamingResponseBody approach ---------
@GetMapping(value = "/video-flux/streaming", produces = "video/mp2t")
public ResponseEntity videoFluxWithStreaming(@PathVariable Long deviceId) {
StreamingResponseBody responseBody = outputStream -> {
sameFluxFromPreviousAPI
.toIterable()
.forEach(bytes -> {
try {
outputStream.write(bytes);
outputStream.flush();
} catch (IOException e) {
throw new RuntimeException("Client disconnected");
}
});
};
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_TYPE, "video/mp2t")
.header(HttpHeaders.CONNECTION, "keep-alive")
.header(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, must-revalidate")
.header("X-Accel-Buffering", "no")
.body(responseBody);
}
Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/798 ... sponsebody
Мобильная версия