|
@@ -9,6 +9,7 @@ import com.yonge.cooleshow.biz.dal.entity.LiveRoomVideo;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.RecordNotify;
|
|
|
import com.yonge.cooleshow.biz.dal.service.LiveRoomService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.LiveRoomVideoService;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -50,45 +51,71 @@ public class LiveRoomVideoServiceImpl extends ServiceImpl<LiveRoomVideoDao, Live
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 云端录制回调
|
|
|
+ */
|
|
|
@Override
|
|
|
public void recordSync(RecordNotify recordNotify) {
|
|
|
if (recordNotify.getCode().equals(200)) {
|
|
|
- //云端录制文件地址
|
|
|
- String fileUrl = recordNotify.getOutput().getFileUrl();
|
|
|
- //房间uid
|
|
|
- String roomUid = recordNotify.getRoomId();
|
|
|
- //融云唯一id标识
|
|
|
- String recordId = recordNotify.getRecordId();
|
|
|
- //回调事件类型
|
|
|
- Integer notifyType = recordNotify.getType();
|
|
|
- if (Objects.nonNull(notifyType)) {
|
|
|
- Date now = new Date();
|
|
|
- //notifyType 1: 录制开始;4: 文件上传-融云回调完成
|
|
|
+ if (Objects.nonNull(recordNotify.getType())) {
|
|
|
+ //云端录制文件地址
|
|
|
+ String fileUrl = recordNotify.getOutput().getFileUrl();
|
|
|
+ //房间uid
|
|
|
+ String roomUId = recordNotify.getRoomId();
|
|
|
+ //融云唯一id标识
|
|
|
+ String recordId = recordNotify.getRecordId();
|
|
|
+ //回调事件类型
|
|
|
+ Integer notifyType = recordNotify.getType();
|
|
|
+ //查询直播间
|
|
|
+ LiveRoom room = liveRoomService.getOne(new QueryWrapper<LiveRoom>().lambda()
|
|
|
+ .eq(LiveRoom::getRoomUid, roomUId));
|
|
|
+ //开始录制
|
|
|
if (notifyType == 1) {
|
|
|
- LiveRoomVideo video = new LiveRoomVideo();
|
|
|
- LiveRoom room = liveRoomService.getOne(new QueryWrapper<LiveRoom>().lambda()
|
|
|
- .eq(LiveRoom::getRoomUid, roomUid));
|
|
|
- video.setCourseGroupId(room.getCourseGroupId());
|
|
|
- video.setCourseId(room.getCourseId());
|
|
|
- video.setRoomUid(roomUid);
|
|
|
- video.setRecordId(recordId);
|
|
|
- video.setUrl(fileUrl);
|
|
|
- video.setStartTime(now);
|
|
|
- video.setType(notifyType);
|
|
|
- video.setCreatedTime(now);
|
|
|
- this.save(video);
|
|
|
+ insertVideo(fileUrl, recordId, notifyType, room);
|
|
|
+ return;
|
|
|
}
|
|
|
+ //录制完成
|
|
|
if (notifyType == 4) {
|
|
|
- LiveRoomVideo video = this.getOne(Wrappers.<LiveRoomVideo>lambdaQuery()
|
|
|
- .eq(LiveRoomVideo::getRoomUid, roomUid)
|
|
|
- .eq(LiveRoomVideo::getRecordId, recordId));
|
|
|
- video.setEndTime(now);
|
|
|
- video.setType(notifyType);
|
|
|
- this.updateById(video);
|
|
|
+ //写入数据库
|
|
|
+ try {
|
|
|
+ //获取最后一次录制视频
|
|
|
+ LiveRoomVideo video = baseMapper.getLastRecord(roomUId, recordId);
|
|
|
+ if (Objects.isNull(video)) {
|
|
|
+ log.error("recordSync error :roomUId : {} ,recordId:{}", roomUId, recordId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(video.getUrl())) {
|
|
|
+ //保存切片
|
|
|
+ insertVideo(fileUrl, recordId, notifyType, room);
|
|
|
+ } else {
|
|
|
+ Date now = new Date();
|
|
|
+ video.setEndTime(now);
|
|
|
+ video.setType(notifyType);
|
|
|
+ video.setUrl(fileUrl);
|
|
|
+ video.setCreatedTime(now);
|
|
|
+ this.updateById(video);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("recordSync error : {}", e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void insertVideo(String fileUrl, String recordId, Integer notifyType, LiveRoom room) {
|
|
|
+ Date now = new Date();
|
|
|
+ LiveRoomVideo roomVideo = new LiveRoomVideo();
|
|
|
+ roomVideo.setCourseGroupId(room.getCourseGroupId());
|
|
|
+ roomVideo.setCourseId(room.getCourseId());
|
|
|
+ roomVideo.setRoomUid(room.getRoomUid());
|
|
|
+ roomVideo.setRecordId(recordId);
|
|
|
+ roomVideo.setUrl(fileUrl);
|
|
|
+ roomVideo.setStartTime(now);
|
|
|
+ roomVideo.setType(notifyType);
|
|
|
+ roomVideo.setCreatedTime(now);
|
|
|
+ this.save(roomVideo);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|