[+] Mediasoup
This commit is contained in:
26
taoyao-signal/taoyao-meeting/pom.xml
Normal file
26
taoyao-signal/taoyao-meeting/pom.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.acgist</groupId>
|
||||
<artifactId>taoyao</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>taoyao-meeting</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>taoyao-meeting</name>
|
||||
<description>会议:会议模式、广播模式、单人对讲</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.acgist</groupId>
|
||||
<artifactId>taoyao-media</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.acgist.taoyao.meeting;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 会议
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Schema(title = "会议", description = "会议")
|
||||
public class Meeting {
|
||||
|
||||
/**
|
||||
* 会议标识
|
||||
*/
|
||||
@Schema(title = "会议标识", description = "会议标识")
|
||||
private String id;
|
||||
/**
|
||||
* 会议名称
|
||||
*/
|
||||
@Schema(title = "会议名称", description = "会议名称")
|
||||
private String name;
|
||||
/**
|
||||
* 会议密码
|
||||
*/
|
||||
@Schema(title = "会议密码", description = "会议密码")
|
||||
private String password;
|
||||
/**
|
||||
* 终端会话标识列表
|
||||
*/
|
||||
@Schema(title = "终端会话标识列表", description = "终端会话标识列表")
|
||||
private List<String> sns;
|
||||
/**
|
||||
* 创建终端标识
|
||||
*/
|
||||
@Schema(title = "创建终端标识", description = "创建终端标识")
|
||||
private String creator;
|
||||
|
||||
/**
|
||||
* 新增终端会话标识
|
||||
*
|
||||
* @param sn 终端会话标识
|
||||
*/
|
||||
public void addSn(String sn) {
|
||||
synchronized (this.sns) {
|
||||
if(this.sns.contains(sn)) {
|
||||
return;
|
||||
}
|
||||
this.sns.add(sn);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.acgist.taoyao.meeting;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.acgist.taoyao.signal.event.ApplicationEventAdapter;
|
||||
import com.acgist.taoyao.signal.listener.ApplicationListenerAdapter;
|
||||
|
||||
/**
|
||||
* 会议事件监听适配器
|
||||
*
|
||||
* @param <E> 事件泛型
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
public abstract class MeetingListenerAdapter<E extends ApplicationEventAdapter> extends ApplicationListenerAdapter<E> {
|
||||
|
||||
@Autowired
|
||||
protected MeetingManager meetingManager;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.acgist.taoyao.meeting;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.acgist.taoyao.boot.annotation.Manager;
|
||||
import com.acgist.taoyao.boot.service.IdService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 会议管理
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Slf4j
|
||||
@Manager
|
||||
public class MeetingManager {
|
||||
|
||||
@Autowired
|
||||
private IdService idService;
|
||||
|
||||
/**
|
||||
* 会议列表
|
||||
*/
|
||||
private List<Meeting> meetings = new CopyOnWriteArrayList<>();
|
||||
|
||||
/**
|
||||
* @return 所有会议列表
|
||||
*/
|
||||
public List<Meeting> meetings() {
|
||||
return this.meetings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id 会议标识
|
||||
*
|
||||
* @return 会议信息
|
||||
*/
|
||||
public Meeting meeting(String id) {
|
||||
return this.meetings.stream()
|
||||
.filter(v -> v.getId().equals(id))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id 会议标识
|
||||
*
|
||||
* @return 会议所有终端标识
|
||||
*/
|
||||
public List<String> sns(String id) {
|
||||
final Meeting meeting = this.meeting(id);
|
||||
return meeting == null ? List.of() : meeting.getSns();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建会议
|
||||
*
|
||||
* @param sn 创建会议终端标识
|
||||
*
|
||||
* @return 会议信息
|
||||
*/
|
||||
public Meeting create(String sn) {
|
||||
final Meeting meeting = new Meeting();
|
||||
meeting.setId(this.idService.buildIdToString());
|
||||
meeting.setSns(new CopyOnWriteArrayList<>());
|
||||
meeting.setCreator(sn);
|
||||
meeting.addSn(sn);
|
||||
this.meetings.add(meeting);
|
||||
log.info("创建会议:{}", meeting.getId());
|
||||
return meeting;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.acgist.taoyao.meeting.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.meeting.Meeting;
|
||||
import com.acgist.taoyao.meeting.MeetingManager;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Content;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
/**
|
||||
* 会议
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@Tag(name = "会议", description = "会议管理")
|
||||
@RestController
|
||||
@RequestMapping("/meeting")
|
||||
public class MeetingController {
|
||||
|
||||
@Autowired
|
||||
private MeetingManager meetingManager;
|
||||
|
||||
@Operation(summary = "会议列表", description = "会议列表")
|
||||
@GetMapping("/list")
|
||||
@ApiResponse(content = @Content(schema = @Schema(implementation = Meeting.class)))
|
||||
public Message list() {
|
||||
return Message.success(this.meetingManager.meetings());
|
||||
}
|
||||
|
||||
@Operation(summary = "会议状态", description = "会议状态")
|
||||
@GetMapping("/status/{id}")
|
||||
public Message status(@PathVariable String id) {
|
||||
return Message.success(this.meetingManager.meeting(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "会议终端列表", description = "会议终端列表")
|
||||
@GetMapping("/list/client/{id}")
|
||||
public Message listClient(@PathVariable String id) {
|
||||
return Message.success(this.meetingManager.sns(id));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.acgist.taoyao.meeting.listener;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.acgist.taoyao.boot.annotation.EventListener;
|
||||
import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.meeting.Meeting;
|
||||
import com.acgist.taoyao.meeting.MeetingListenerAdapter;
|
||||
import com.acgist.taoyao.signal.event.meeting.MeetingCreateEvent;
|
||||
|
||||
/**
|
||||
* 创建会议监听
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@EventListener
|
||||
public class MeetingCreateListener extends MeetingListenerAdapter<MeetingCreateEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(MeetingCreateEvent event) {
|
||||
final Meeting meeting = this.meetingManager.create(event.getSn());
|
||||
final Message message = event.getMessage();
|
||||
message.setBody(Map.of("id", meeting.getId()));
|
||||
this.clientSessionManager.broadcast(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.acgist.taoyao.meeting.listener;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.acgist.taoyao.boot.annotation.EventListener;
|
||||
import com.acgist.taoyao.boot.model.Message;
|
||||
import com.acgist.taoyao.boot.model.MessageCode;
|
||||
import com.acgist.taoyao.boot.model.MessageCodeException;
|
||||
import com.acgist.taoyao.meeting.Meeting;
|
||||
import com.acgist.taoyao.meeting.MeetingListenerAdapter;
|
||||
import com.acgist.taoyao.signal.event.meeting.MeetingEnterEvent;
|
||||
|
||||
/**
|
||||
* 进入会议监听
|
||||
*
|
||||
* @author acgist
|
||||
*/
|
||||
@EventListener
|
||||
public class MeetingEnterListener extends MeetingListenerAdapter<MeetingEnterEvent> {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(MeetingEnterEvent event) {
|
||||
final String sn = event.getSn();
|
||||
final String id = event.get("id");
|
||||
final Meeting meeting = this.meetingManager.meeting(id);
|
||||
if(meeting == null) {
|
||||
throw MessageCodeException.of(MessageCode.CODE_3400, "无效会议");
|
||||
}
|
||||
meeting.addSn(sn);
|
||||
final Message message = event.getMessage();
|
||||
message.setBody(Map.of(
|
||||
"id", meeting.getId(),
|
||||
"sn", sn
|
||||
));
|
||||
// TODO:返回房间列表
|
||||
meeting.getSns().stream()
|
||||
.filter(v -> !sn.equals(v))
|
||||
.forEach(v -> this.clientSessionManager.unicast(v, message));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user