package com.gc.easy.flv.controller;

import com.gc.easy.flv.service.IFLVService;
import com.gc.easy.flv.service.IOpenFLVService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.annotation.Log;
import me.zhengjie.annotation.rest.AnonymousGetMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

/**
 * FLV流转换
 *
 * @author gc.x
 */
@Slf4j
@RequestMapping("api/front/flv")
@Api(tags = "微信：拉流播放")
public class FLVController {

    @Autowired
    private IFLVService service;

    @Autowired(required = false)
    private IOpenFLVService openFLVService;

    @Log("拉流播放")
    @ApiOperation(value = "打开视频流")
    @AnonymousGetMapping(value = "/get/stream")
    public void open(String url, HttpServletResponse response, HttpServletRequest request) throws UnsupportedEncodingException {
        if (!StringUtils.isEmpty(url)) {
            String decodedUrl = java.net.URLDecoder.decode(url, "UTF-8");
            service.open(decodedUrl, response, request, openFLVService);
        }
    }
}
