package com.sjyt.icom.asst.controller;

import com.sjyt.icom.asst.common.model.srs.*;
import com.sjyt.icom.asst.service.impl.SrsCallBackService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 操作SRS流媒体服务回调函数 该类所有方法返回值均为int类型,根据SRS回调返回值要求
 * 含义：0成功，非0失败
 *
 * @author: Tab
 * @date: 2022-06-11 22:53
 * @since 1.0.0
 */
@AllArgsConstructor
@Controller
@Slf4j
public class SrsCallBackController {
    private final SrsCallBackService callBackService;

    @ResponseBody
    @PostMapping("/connect")
    public int onConnect(@RequestBody SrsCallBackOnConnect data) {
        System.out.println("连接了"+data);
        return callBackService.connect(data);
    }

    @ResponseBody
    @PostMapping("/close")
    public int onClose(@RequestBody SrsCallBackOnClose data) {
        log.info("客户端断开连接" + data);
        return callBackService.close(data);
    }

    @ResponseBody
    @PostMapping("/publish")
    public int onPublish(@RequestBody SrsCallBackOnPublish data) {
        System.out.println("推拉流"+data);
        return callBackService.publish(data);
    }

    @ResponseBody
    @RequestMapping("/unpublished")
    public int onUnpublished(@RequestBody SrsCallBackOnUnPublish data) {
        log.info("客户端停止推流" + data);
        return callBackService.unpublished(data);
    }

    @ResponseBody
    @RequestMapping("/play")
    public int onPlay(@RequestBody SrsCallBackOnPlay data) {
        System.out.println("拉流了"+data);
        return callBackService.play(data);
    }
    @ResponseBody
    @PostMapping("/stop")
    public int onStop(@RequestBody SrsCallBackOnStop data) {
        log.info("客户端停止播放" + data);
        return callBackService.stop(data);
    }
}
