Commit 9789c55ef944ffdbfd7b2bdaf9d2a210f6572a32
1 parent
5d031b3d
增加SSE前端推送支持
Showing
1 changed file
with
32 additions
and
0 deletions
src/main/java/com/genersoft/iot/vmp/vmanager/SEEController/SEEController.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.vmanager.SEEController; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEventListener; | |
| 4 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 5 | +import org.springframework.stereotype.Controller; | |
| 6 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 7 | +import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * @description: SSE推送 | |
| 11 | + * @author: lawrencehj | |
| 12 | + * @data: 2021-01-20 | |
| 13 | + */ | |
| 14 | + | |
| 15 | +@Controller | |
| 16 | +@RequestMapping("/api") | |
| 17 | +public class SEEController { | |
| 18 | + @Autowired | |
| 19 | + AlarmEventListener alarmEventListener; | |
| 20 | + | |
| 21 | + //设置响应 | |
| 22 | + @RequestMapping("/emit") | |
| 23 | + public SseEmitter emit() { | |
| 24 | + SseEmitter sseEmitter = new SseEmitter(0L); | |
| 25 | + try { | |
| 26 | + alarmEventListener.addSseEmitters(sseEmitter); | |
| 27 | + }catch (Exception e){ | |
| 28 | + sseEmitter.completeWithError(e); | |
| 29 | + } | |
| 30 | + return sseEmitter; | |
| 31 | + } | |
| 32 | +} | ... | ... |