建筑在美貌上的爱情,一旦美貌消失,它也会随之消失。——堂恩
昨天说到 srs信令java版
今天按照官方文档实现http
回调:
https://ossrs.net/lts/zh-cn/docs/v5/doc/http-callback
完整配置文件:
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
| # WebRTC streaming config for SRS. # @see full.conf for detail config.
listen 1935; max_connections 1000; daemon off; srs_log_tank console;
http_server { enabled on; listen 8080; dir ./objs/nginx/html; }
http_api { enabled on; listen 1985; } stats { network 0; } rtc_server { enabled on; listen 8000; # UDP port # @see https: candidate $CANDIDATE; }
vhost __defaultVhost__ { http_hooks { enabled on; on_publish http: on_unpublish http: on_play http: on_stop http: on_dvr http: on_hls http: on_hls_notify http: } rtc { enabled on; # @see https: rtmp_to_rtc off; # @see https: rtc_to_rtmp off; } http_remux { enabled on; mount [vhost]/[app]/[stream].flv; } }
|
对应的docker
命令:
1
| docker run --rm --env CANDIDATE=$CANDIDATE -p 1935:1935 -p 8080:8080 -p 1985:1985 -p 8000:8000/udp -v /Users/achao/IdeaProjects/srs/trunk/conf/rtc.conf:/usr/local/srs/conf/rtc.conf registry.cn-hangzhou.aliyuncs.com/ossrs/srs:5 objs/srs -c /usr/local/srs/conf/rtc.conf
|
然后我们的回调实现
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
| package com.example.simplesrssignaling;
import lombok.Data; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*;
@RestController @CrossOrigin @RequestMapping("/api/v1") public class SRSController {
@PostMapping("/streams") public ResponseEntity<Response> handlePublishAndUnpublish(@RequestBody HookData data) { return ResponseEntity.ok(new Response(0)); }
@PostMapping("/sessions") public ResponseEntity<Response> handlePlayAndStop(@RequestBody HookData data) { return ResponseEntity.ok(new Response(0)); }
@PostMapping("/dvrs") public ResponseEntity<Response> handleDVR(@RequestBody HookData data) { return ResponseEntity.ok(new Response(0)); }
@PostMapping("/hls") public ResponseEntity<Response> handleHLS(@RequestBody HookData data) { return ResponseEntity.ok(new Response(0)); }
@Data public static class HookData { private String action; private String client_id; private String ip; private String vhost; private String app; private String stream; private String param; }
@Data public static class Response { private Integer code; private String msg;
public Response(int code) { this.code = code; this.msg = "ok"; } } }
|