package com.sjyt.icom.asst.context.handle.srs;

import cn.hutool.core.util.ObjectUtil;
import com.sjyt.icom.asst.common.event.SrsCallBackEvent;
import com.sjyt.icom.asst.conf.properties.RtspAppProperties;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * <p>流媒体app检查</p>
 *
 * @author renyanru
 * @version V1.0.0
 * @date 2022/6/14 13:26
 */
@Slf4j
@Component
@AllArgsConstructor
public class RtspAppHandle extends RtspHandle {
    private final RtspAppProperties config;

    /**
     * app名称判断
     *
     * @param event e
     * @return r
     */
    @Override
    public Integer doChain(SrsCallBackEvent event) {
        log.info("appHandle执行");
        return Optional.ofNullable(event)
                .filter(it -> ObjectUtil.equal(config.getApp(), it.getAppName()))
                .map(it -> handle.doChain(it))
                .orElseGet(() -> {
                    log.error("app名称校验失败");
                    return FAIL;
                });
    }
}
