[*] 日常优化
This commit is contained in:
@@ -9,33 +9,43 @@ import com.acgist.taoyao.boot.model.Message;
|
|||||||
*/
|
*/
|
||||||
public interface Client extends AutoCloseable {
|
public interface Client extends AutoCloseable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return IP
|
* @return IP
|
||||||
*/
|
*/
|
||||||
String ip();
|
String getIP();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 终端标识
|
* @return 终端名称
|
||||||
*/
|
*/
|
||||||
String clientId();
|
String getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 终端类型
|
* @return 终端ID
|
||||||
*/
|
*/
|
||||||
ClientType clientType();
|
String getClientId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 终端状态
|
* @return 终端类型
|
||||||
*/
|
*/
|
||||||
ClientStatus status();
|
ClientType getClientType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 推送消息
|
* @return 终端状态
|
||||||
*
|
*/
|
||||||
* @param message 消息
|
ClientStatus getStatus();
|
||||||
*/
|
|
||||||
void push(Message message);
|
/**
|
||||||
|
* @return 终端实例
|
||||||
|
*/
|
||||||
|
AutoCloseable getInstance();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 推送消息
|
||||||
|
*
|
||||||
|
* @param message 消息
|
||||||
|
*/
|
||||||
|
void push(Message message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求消息
|
* 请求消息
|
||||||
*
|
*
|
||||||
@@ -48,35 +58,35 @@ public interface Client extends AutoCloseable {
|
|||||||
/**
|
/**
|
||||||
* 响应消息
|
* 响应消息
|
||||||
*
|
*
|
||||||
* @param id 消息标识
|
* @param id 消息ID
|
||||||
* @param message 消息
|
* @param message 消息
|
||||||
*
|
*
|
||||||
* @return 是否响应消息
|
* @return 是否响应消息
|
||||||
*/
|
*/
|
||||||
boolean response(Long id, Message message);
|
boolean response(Long id, Message message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param timeout 超时时间
|
* @return 授权是否超时
|
||||||
*
|
*/
|
||||||
* @return 授权是否超时
|
boolean timeout();
|
||||||
*/
|
|
||||||
boolean timeout(long timeout);
|
/**
|
||||||
|
* 设置授权
|
||||||
/**
|
*
|
||||||
* @return 终端实例
|
* @param clientId 终端ID
|
||||||
*/
|
*/
|
||||||
AutoCloseable instance();
|
void authorize(String clientId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置授权
|
* @return 是否授权
|
||||||
*
|
*/
|
||||||
* @param clientId 终端标识
|
boolean authorized();
|
||||||
*/
|
|
||||||
void authorize(String clientId);
|
/**
|
||||||
|
* @return 是否没有授权
|
||||||
/**
|
*/
|
||||||
* @return 是否授权
|
default boolean unauthorized() {
|
||||||
*/
|
return !this.authorized();
|
||||||
boolean authorized();
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,72 +20,86 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public abstract class ClientAdapter<T extends AutoCloseable> implements Client {
|
public abstract class ClientAdapter<T extends AutoCloseable> implements Client {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IP
|
* IP
|
||||||
*/
|
*/
|
||||||
protected String ip;
|
protected String ip;
|
||||||
/**
|
/**
|
||||||
* 进入时间
|
* 终端ID
|
||||||
*/
|
*/
|
||||||
protected final long time;
|
protected String clientId;
|
||||||
/**
|
/**
|
||||||
|
* 进入时间
|
||||||
|
*/
|
||||||
|
protected final long time;
|
||||||
|
/**
|
||||||
* 超时时间
|
* 超时时间
|
||||||
*/
|
*/
|
||||||
protected final long timeout;
|
protected final long timeout;
|
||||||
/**
|
/**
|
||||||
* 终端标识
|
* 终端实例
|
||||||
*/
|
*/
|
||||||
protected String clientId;
|
protected final T instance;
|
||||||
/**
|
/**
|
||||||
* 终端实例
|
* 是否授权
|
||||||
*/
|
*/
|
||||||
protected final T instance;
|
protected boolean authorized;
|
||||||
/**
|
/**
|
||||||
* 是否授权
|
* 终端状态
|
||||||
*/
|
*/
|
||||||
protected boolean authorized;
|
protected final ClientStatus status;
|
||||||
/**
|
/**
|
||||||
* 终端状态
|
|
||||||
*/
|
|
||||||
protected final ClientStatus status;
|
|
||||||
/**
|
|
||||||
* 同步消息
|
* 同步消息
|
||||||
*/
|
*/
|
||||||
protected final Map<Long, Message> requestMessage;
|
protected final Map<Long, Message> requestMessage;
|
||||||
|
|
||||||
protected ClientAdapter(long timeout, T instance) {
|
/**
|
||||||
this.time = System.currentTimeMillis();
|
* @param timeout 超时时间
|
||||||
this.timeout = timeout;
|
* @param instance 终端实例
|
||||||
this.instance = instance;
|
*/
|
||||||
this.authorized = false;
|
protected ClientAdapter(long timeout, T instance) {
|
||||||
this.status = new ClientStatus();
|
this.time = System.currentTimeMillis();
|
||||||
this.requestMessage = new ConcurrentHashMap<>();
|
this.timeout = timeout;
|
||||||
}
|
this.instance = instance;
|
||||||
|
this.authorized = false;
|
||||||
@Override
|
this.status = new ClientStatus();
|
||||||
public String ip() {
|
this.requestMessage = new ConcurrentHashMap<>();
|
||||||
return this.ip;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public String getIP() {
|
||||||
public String clientId() {
|
return this.ip;
|
||||||
return this.clientId;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public String getName() {
|
||||||
public ClientType clientType() {
|
return this.status.getName();
|
||||||
return this.status.getClientType();
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public String getClientId() {
|
||||||
public ClientStatus status() {
|
return this.clientId;
|
||||||
return this.status;
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
@Override
|
public ClientType getClientType() {
|
||||||
|
return this.status.getClientType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClientStatus getStatus() {
|
||||||
|
return this.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T getInstance() {
|
||||||
|
return this.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Message request(Message request) {
|
public Message request(Message request) {
|
||||||
final Header header = request.getHeader();
|
final Header header = request.getHeader();
|
||||||
final Long id = header.getId();
|
final Long id = header.getId();
|
||||||
this.requestMessage.put(id, request);
|
this.requestMessage.put(id, request);
|
||||||
synchronized (request) {
|
synchronized (request) {
|
||||||
this.push(request);
|
this.push(request);
|
||||||
@@ -102,9 +116,9 @@ public abstract class ClientAdapter<T extends AutoCloseable> implements Client {
|
|||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean response(Long id, Message message) {
|
public boolean response(Long id, Message message) {
|
||||||
final Message request = this.requestMessage.get(id);
|
final Message request = this.requestMessage.get(id);
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
// 同步处理:重新设置响应消息
|
// 同步处理:重新设置响应消息
|
||||||
@@ -117,37 +131,32 @@ public abstract class ClientAdapter<T extends AutoCloseable> implements Client {
|
|||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean timeout(long timeout) {
|
public boolean timeout() {
|
||||||
return System.currentTimeMillis() - this.time > timeout;
|
return System.currentTimeMillis() - this.time > this.timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public T instance() {
|
public void authorize(String clientId) {
|
||||||
return this.instance;
|
this.clientId = clientId;
|
||||||
}
|
this.authorized = true;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public void authorize(String clientId) {
|
@Override
|
||||||
this.clientId = clientId;
|
public boolean authorized() {
|
||||||
this.authorized = true;
|
return this.authorized;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean authorized() {
|
public void close() throws Exception {
|
||||||
return this.authorized;
|
this.instance.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws Exception {
|
public String toString() {
|
||||||
this.instance.close();
|
return this.getClass().getSimpleName() + " - " + this.ip + " - " + this.clientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return this.getClass().getSimpleName() + " - " + this.ip + " - " + this.clientId;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import org.springframework.context.ApplicationContext;
|
|||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
|
||||||
import com.acgist.taoyao.boot.annotation.Manager;
|
import com.acgist.taoyao.boot.annotation.Manager;
|
||||||
import com.acgist.taoyao.boot.config.TaoyaoProperties;
|
|
||||||
import com.acgist.taoyao.boot.model.Message;
|
import com.acgist.taoyao.boot.model.Message;
|
||||||
import com.acgist.taoyao.signal.event.client.ClientCloseEvent;
|
import com.acgist.taoyao.signal.event.client.ClientCloseEvent;
|
||||||
|
|
||||||
@@ -24,7 +23,6 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Manager
|
@Manager
|
||||||
public class ClientManager {
|
public class ClientManager {
|
||||||
|
|
||||||
private final TaoyaoProperties taoyaoProperties;
|
|
||||||
private final ApplicationContext applicationContext;
|
private final ApplicationContext applicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,8 +30,7 @@ public class ClientManager {
|
|||||||
*/
|
*/
|
||||||
private final List<Client> clients;
|
private final List<Client> clients;
|
||||||
|
|
||||||
public ClientManager(TaoyaoProperties taoyaoProperties, ApplicationContext applicationContext) {
|
public ClientManager(ApplicationContext applicationContext) {
|
||||||
this.taoyaoProperties = taoyaoProperties;
|
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
this.clients = new CopyOnWriteArrayList<>();
|
this.clients = new CopyOnWriteArrayList<>();
|
||||||
}
|
}
|
||||||
@@ -60,7 +57,7 @@ public class ClientManager {
|
|||||||
*/
|
*/
|
||||||
public void unicast(String to, Message message) {
|
public void unicast(String to, Message message) {
|
||||||
this.clients().stream()
|
this.clients().stream()
|
||||||
.filter(v -> Objects.equals(to, v.clientId()))
|
.filter(v -> Objects.equals(to, v.getClientId()))
|
||||||
.forEach(v -> v.push(message));
|
.forEach(v -> v.push(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +69,7 @@ public class ClientManager {
|
|||||||
*/
|
*/
|
||||||
public void unicast(Client to, Message message) {
|
public void unicast(Client to, Message message) {
|
||||||
this.clients().stream()
|
this.clients().stream()
|
||||||
.filter(v -> v.instance() == to)
|
.filter(v -> v.getInstance() == to)
|
||||||
.forEach(v -> v.push(message));
|
.forEach(v -> v.push(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +92,7 @@ public class ClientManager {
|
|||||||
*/
|
*/
|
||||||
public void broadcast(String from, Message message, ClientType ... clientTypes) {
|
public void broadcast(String from, Message message, ClientType ... clientTypes) {
|
||||||
this.clients(clientTypes).stream()
|
this.clients(clientTypes).stream()
|
||||||
.filter(v -> !Objects.equals(from, v.clientId()))
|
.filter(v -> !Objects.equals(from, v.getClientId()))
|
||||||
.forEach(v -> v.push(message));
|
.forEach(v -> v.push(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +105,7 @@ public class ClientManager {
|
|||||||
*/
|
*/
|
||||||
public void broadcast(Client from, Message message, ClientType ... clientTypes) {
|
public void broadcast(Client from, Message message, ClientType ... clientTypes) {
|
||||||
this.clients(clientTypes).stream()
|
this.clients(clientTypes).stream()
|
||||||
.filter(v -> v.instance() != from)
|
.filter(v -> v.getInstance() != from)
|
||||||
.forEach(v -> v.push(message));
|
.forEach(v -> v.push(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,7 +116,7 @@ public class ClientManager {
|
|||||||
*/
|
*/
|
||||||
public Client clients(AutoCloseable instance) {
|
public Client clients(AutoCloseable instance) {
|
||||||
return this.clients.stream()
|
return this.clients.stream()
|
||||||
.filter(v -> v.instance() == instance)
|
.filter(v -> v.getInstance() == instance)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
@@ -131,7 +128,7 @@ public class ClientManager {
|
|||||||
*/
|
*/
|
||||||
public Client clients(String clientId) {
|
public Client clients(String clientId) {
|
||||||
return this.clients().stream()
|
return this.clients().stream()
|
||||||
.filter(v -> Objects.equals(clientId, v.clientId()))
|
.filter(v -> Objects.equals(clientId, v.getClientId()))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
@@ -144,7 +141,7 @@ public class ClientManager {
|
|||||||
public List<Client> clients(ClientType ... clientTypes) {
|
public List<Client> clients(ClientType ... clientTypes) {
|
||||||
return this.clients.stream()
|
return this.clients.stream()
|
||||||
.filter(Client::authorized)
|
.filter(Client::authorized)
|
||||||
.filter(client -> ArrayUtils.isEmpty(clientTypes) || ArrayUtils.contains(clientTypes, client.clientType()))
|
.filter(client -> ArrayUtils.isEmpty(clientTypes) || ArrayUtils.contains(clientTypes, client.getClientType()))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +152,7 @@ public class ClientManager {
|
|||||||
*/
|
*/
|
||||||
public ClientStatus status(AutoCloseable instance) {
|
public ClientStatus status(AutoCloseable instance) {
|
||||||
final Client client = this.clients(instance);
|
final Client client = this.clients(instance);
|
||||||
return client == null ? null : client.status();
|
return client == null ? null : client.getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -165,7 +162,7 @@ public class ClientManager {
|
|||||||
*/
|
*/
|
||||||
public ClientStatus status(String clientId) {
|
public ClientStatus status(String clientId) {
|
||||||
final Client client = this.clients(clientId);
|
final Client client = this.clients(clientId);
|
||||||
return client == null ? null : client.status();
|
return client == null ? null : client.getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -175,7 +172,7 @@ public class ClientManager {
|
|||||||
*/
|
*/
|
||||||
public List<ClientStatus> status(ClientType ... clientTypes) {
|
public List<ClientStatus> status(ClientType ... clientTypes) {
|
||||||
return this.clients(clientTypes).stream()
|
return this.clients(clientTypes).stream()
|
||||||
.map(Client::status)
|
.map(Client::getStatus)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,8 +222,8 @@ public class ClientManager {
|
|||||||
private void closeTimeout() {
|
private void closeTimeout() {
|
||||||
final int oldSize = this.clients.size();
|
final int oldSize = this.clients.size();
|
||||||
this.clients.stream()
|
this.clients.stream()
|
||||||
.filter(v -> !v.authorized())
|
.filter(v -> v.unauthorized())
|
||||||
.filter(v -> v.timeout(this.taoyaoProperties.getTimeout()))
|
.filter(v -> v.timeout())
|
||||||
.forEach(v -> {
|
.forEach(v -> {
|
||||||
log.debug("关闭超时终端:{}", v);
|
log.debug("关闭超时终端:{}", v);
|
||||||
this.close(v);
|
this.close(v);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public abstract class ClientEventAdapter extends ApplicationEventAdapter {
|
|||||||
public ClientEventAdapter(Client client, Message message, Map<String, Object> body) {
|
public ClientEventAdapter(Client client, Message message, Map<String, Object> body) {
|
||||||
super(client, message, body);
|
super(client, message, body);
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.clientId = client.clientId();
|
this.clientId = client.getClientId();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class ClientWrapper implements AutoCloseable {
|
|||||||
this.room = room;
|
this.room = room;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.roomId = room.getRoomId();
|
this.roomId = room.getRoomId();
|
||||||
this.clientId = client.clientId();
|
this.clientId = client.getClientId();
|
||||||
this.producers = new ConcurrentHashMap<>();
|
this.producers = new ConcurrentHashMap<>();
|
||||||
this.consumers = new ConcurrentHashMap<>();
|
this.consumers = new ConcurrentHashMap<>();
|
||||||
this.dataProducers = new ConcurrentHashMap<>();
|
this.dataProducers = new ConcurrentHashMap<>();
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ public class Recorder {
|
|||||||
* @param status 状态
|
* @param status 状态
|
||||||
*/
|
*/
|
||||||
private void updateRecordStatus(boolean status) {
|
private void updateRecordStatus(boolean status) {
|
||||||
this.clientWrapper.getClient().status().setServerRecording(status);
|
this.clientWrapper.getClient().getStatus().setServerRecording(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class Room extends OperatorAdapter {
|
|||||||
*/
|
*/
|
||||||
public List<ClientStatus> clientStatus() {
|
public List<ClientStatus> clientStatus() {
|
||||||
return this.clients.keySet().stream()
|
return this.clients.keySet().stream()
|
||||||
.map(Client::status)
|
.map(Client::getStatus)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ public class Room extends OperatorAdapter {
|
|||||||
if(clientWrapper != null) {
|
if(clientWrapper != null) {
|
||||||
return clientWrapper;
|
return clientWrapper;
|
||||||
}
|
}
|
||||||
log.info("终端进入房间:{} - {}", this.roomId, client.clientId());
|
log.info("终端进入房间:{} - {}", this.roomId, client.getClientId());
|
||||||
clientWrapper = new ClientWrapper(this, client);
|
clientWrapper = new ClientWrapper(this, client);
|
||||||
this.clients.put(client, clientWrapper);
|
this.clients.put(client, clientWrapper);
|
||||||
this.roomStatus.setClientSize(this.roomStatus.getClientSize() + 1);
|
this.roomStatus.setClientSize(this.roomStatus.getClientSize() + 1);
|
||||||
@@ -139,7 +139,7 @@ public class Room extends OperatorAdapter {
|
|||||||
synchronized (this.clients) {
|
synchronized (this.clients) {
|
||||||
final ClientWrapper wrapper = this.clients.remove(client);
|
final ClientWrapper wrapper = this.clients.remove(client);
|
||||||
if(wrapper != null) {
|
if(wrapper != null) {
|
||||||
log.info("终端离开房间:{} - {}", this.roomId, client.clientId());
|
log.info("终端离开房间:{} - {}", this.roomId, client.getClientId());
|
||||||
try {
|
try {
|
||||||
wrapper.close();
|
wrapper.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -179,7 +179,7 @@ public class Room extends OperatorAdapter {
|
|||||||
*/
|
*/
|
||||||
public void unicast(String to, Message message) {
|
public void unicast(String to, Message message) {
|
||||||
this.clients.keySet().stream()
|
this.clients.keySet().stream()
|
||||||
.filter(v -> Objects.equals(to, v.clientId()))
|
.filter(v -> Objects.equals(to, v.getClientId()))
|
||||||
.forEach(v -> v.push(message));
|
.forEach(v -> v.push(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -200,7 +200,7 @@ public class Room extends OperatorAdapter {
|
|||||||
*/
|
*/
|
||||||
public void broadcast(String from, Message message) {
|
public void broadcast(String from, Message message) {
|
||||||
this.clients.keySet().stream()
|
this.clients.keySet().stream()
|
||||||
.filter(v -> !Objects.equals(from, v.clientId()))
|
.filter(v -> !Objects.equals(from, v.getClientId()))
|
||||||
.forEach(v -> v.push(message));
|
.forEach(v -> v.push(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class RoomManager {
|
|||||||
*/
|
*/
|
||||||
public void recreate(Client mediaClient, Message message) {
|
public void recreate(Client mediaClient, Message message) {
|
||||||
this.rooms.stream()
|
this.rooms.stream()
|
||||||
.filter(room -> mediaClient.clientId().equals(room.getMediaClient().clientId()))
|
.filter(room -> mediaClient.getClientId().equals(room.getMediaClient().getClientId()))
|
||||||
.forEach(room -> {
|
.forEach(room -> {
|
||||||
log.info("重建房间:{}", room.getRoomId());
|
log.info("重建房间:{}", room.getRoomId());
|
||||||
final Message clone = message.cloneWithoutBody();
|
final Message clone = message.cloneWithoutBody();
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class Transport extends OperatorAdapter {
|
|||||||
this.room = room;
|
this.room = room;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.roomId = room.getRoomId();
|
this.roomId = room.getRoomId();
|
||||||
this.clientId = client.clientId();
|
this.clientId = client.getClientId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class Session implements Closeable {
|
|||||||
* @param message 消息
|
* @param message 消息
|
||||||
*/
|
*/
|
||||||
public void pushOther(String clientId, Message message) {
|
public void pushOther(String clientId, Message message) {
|
||||||
if(this.source.clientId().equals(clientId)) {
|
if(this.source.getClientId().equals(clientId)) {
|
||||||
this.target.push(message);
|
this.target.push(message);
|
||||||
} else {
|
} else {
|
||||||
this.source.push(message);
|
this.source.push(message);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class SessionManager {
|
|||||||
public Session call(Client source, Client target) {
|
public Session call(Client source, Client target) {
|
||||||
final Session session = new Session(this.idService.buildUuid(), source, target);
|
final Session session = new Session(this.idService.buildUuid(), source, target);
|
||||||
this.sessions.put(session.getId(), session);
|
this.sessions.put(session.getId(), session);
|
||||||
log.info("创建视频会话:{} - {} - {}", session.getId(), session.getSource().clientId(), session.getTarget().clientId());
|
log.info("创建视频会话:{} - {} - {}", session.getId(), session.getSource().getClientId(), session.getTarget().getClientId());
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ public class SessionManager {
|
|||||||
public Session remove(String sessionId) {
|
public Session remove(String sessionId) {
|
||||||
final Session session = this.sessions.remove(sessionId);
|
final Session session = this.sessions.remove(sessionId);
|
||||||
if(session != null) {
|
if(session != null) {
|
||||||
log.info("视频会话关闭:{} - {} - {}", sessionId, session.getSource().clientId(), session.getTarget().clientId());
|
log.info("视频会话关闭:{} - {} - {}", sessionId, session.getSource().getClientId(), session.getTarget().getClientId());
|
||||||
}
|
}
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public abstract class ProtocolClientAdapter extends ProtocolAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Client client, Message message) {
|
public void execute(Client client, Message message) {
|
||||||
this.execute(client.clientId(), client.clientType(), client, message, message.body());
|
this.execute(client.getClientId(), client.getClientType(), client, message, message.body());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ public class ProtocolManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(log.isDebugEnabled()) {
|
if(log.isDebugEnabled()) {
|
||||||
log.debug("执行信令消息:{} - {}", client.clientId(), content);
|
log.debug("执行信令消息:{} - {}", client.getClientId(), content);
|
||||||
}
|
}
|
||||||
if(protocol instanceof ClientRegisterProtocol) {
|
if(protocol instanceof ClientRegisterProtocol) {
|
||||||
protocol.execute(client, message);
|
protocol.execute(client, message);
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class ClientAlarmProtocol extends ProtocolClientAdapter {
|
|||||||
alarmMessage,
|
alarmMessage,
|
||||||
alarmDatetime
|
alarmDatetime
|
||||||
);
|
);
|
||||||
final ClientStatus status = client.status();
|
final ClientStatus status = client.getStatus();
|
||||||
status.setAlarming(Boolean.TRUE);
|
status.setAlarming(Boolean.TRUE);
|
||||||
// 业务逻辑
|
// 业务逻辑
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,11 +61,11 @@ public class ClientCloseProtocol extends ProtocolClientAdapter implements Applic
|
|||||||
* @param client 终端
|
* @param client 终端
|
||||||
*/
|
*/
|
||||||
private void close(Client client) {
|
private void close(Client client) {
|
||||||
if(client == null || !client.authorized()) {
|
if(client == null || client.unauthorized()) {
|
||||||
// 没有授权终端
|
// 没有授权终端
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String clientId = client.clientId();
|
final String clientId = client.getClientId();
|
||||||
log.info("关闭终端:{}", clientId);
|
log.info("关闭终端:{}", clientId);
|
||||||
// 释放房间终端
|
// 释放房间终端
|
||||||
this.roomManager.leave(client);
|
this.roomManager.leave(client);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class ClientConfigProtocol extends ProtocolClientAdapter implements Appli
|
|||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(ClientConfigEvent event) {
|
public void onApplicationEvent(ClientConfigEvent event) {
|
||||||
final Client client = event.getClient();
|
final Client client = event.getClient();
|
||||||
final ClientType clientType = client.clientType();
|
final ClientType clientType = client.getClientType();
|
||||||
client.push(this.build(clientType));
|
client.push(this.build(clientType));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class ClientHeartbeatProtocol extends ProtocolClientAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||||
client.push(message.cloneWithoutBody());
|
client.push(message.cloneWithoutBody());
|
||||||
final ClientStatus status = client.status();
|
final ClientStatus status = client.getStatus();
|
||||||
status.copy(body);
|
status.copy(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class ClientOnlineProtocol extends ProtocolClientAdapter implements Appli
|
|||||||
final String clientId = event.getClientId();
|
final String clientId = event.getClientId();
|
||||||
this.clientManager.broadcast(
|
this.clientManager.broadcast(
|
||||||
clientId,
|
clientId,
|
||||||
this.build(client.status())
|
this.build(client.getStatus())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,8 +110,8 @@ public class ClientRegisterProtocol extends ProtocolClientAdapter {
|
|||||||
* @return 终端状态
|
* @return 终端状态
|
||||||
*/
|
*/
|
||||||
private ClientStatus buildStatus(String clientId, ClientType clientType, Client client, Map<String, Object> body) {
|
private ClientStatus buildStatus(String clientId, ClientType clientType, Client client, Map<String, Object> body) {
|
||||||
final ClientStatus status = client.status();
|
final ClientStatus status = client.getStatus();
|
||||||
status.setIp(client.ip());
|
status.setIp(client.getIP());
|
||||||
status.setName(MapUtils.get(body, Constant.NAME));
|
status.setName(MapUtils.get(body, Constant.NAME));
|
||||||
status.setClientId(clientId);
|
status.setClientId(clientId);
|
||||||
status.setClientType(clientType);
|
status.setClientType(clientType);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class ControlClientRecordProtocol extends ProtocolControlAdapter implemen
|
|||||||
* @param enabled 录像状态
|
* @param enabled 录像状态
|
||||||
*/
|
*/
|
||||||
private void updateRecordStatus(Client client, Boolean enabled) {
|
private void updateRecordStatus(Client client, Boolean enabled) {
|
||||||
client.status().setClientRecording(enabled);
|
client.getStatus().setClientRecording(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class MediaTransportPlainProtocol extends ProtocolRoomAdapter {
|
|||||||
final Map<String, Transport> transports = room.getTransports();
|
final Map<String, Transport> transports = room.getTransports();
|
||||||
final String transportId = MapUtils.get(responseBody, Constant.TRANSPORT_ID);
|
final String transportId = MapUtils.get(responseBody, Constant.TRANSPORT_ID);
|
||||||
// 重写地址
|
// 重写地址
|
||||||
this.rewriteIp(client.ip(), responseBody);
|
this.rewriteIp(client.getIP(), responseBody);
|
||||||
// 处理逻辑
|
// 处理逻辑
|
||||||
final ClientWrapper clientWrapper = room.clientWrapper(client);
|
final ClientWrapper clientWrapper = room.clientWrapper(client);
|
||||||
// 生产者
|
// 生产者
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class MediaTransportWebRtcCreateProtocol extends ProtocolRoomAdapter {
|
|||||||
final Map<String, Transport> transports = room.getTransports();
|
final Map<String, Transport> transports = room.getTransports();
|
||||||
final String transportId = MapUtils.get(responseBody, Constant.TRANSPORT_ID);
|
final String transportId = MapUtils.get(responseBody, Constant.TRANSPORT_ID);
|
||||||
// 重写地址
|
// 重写地址
|
||||||
this.rewriteIp(client.ip(), responseBody);
|
this.rewriteIp(client.getIP(), responseBody);
|
||||||
// 处理逻辑
|
// 处理逻辑
|
||||||
final ClientWrapper clientWrapper = room.clientWrapper(client);
|
final ClientWrapper clientWrapper = room.clientWrapper(client);
|
||||||
// 消费者
|
// 消费者
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public class RoomEnterProtocol extends ProtocolRoomAdapter {
|
|||||||
message.setBody(Map.of(
|
message.setBody(Map.of(
|
||||||
Constant.ROOM_ID, room.getRoomId(),
|
Constant.ROOM_ID, room.getRoomId(),
|
||||||
Constant.CLIENT_ID, clientId,
|
Constant.CLIENT_ID, clientId,
|
||||||
Constant.STATUS, client.status()
|
Constant.STATUS, client.getStatus()
|
||||||
));
|
));
|
||||||
room.broadcast(message);
|
room.broadcast(message);
|
||||||
// 进入房间事件
|
// 进入房间事件
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class RoomLeaveProtocol extends ProtocolRoomAdapter implements Applicatio
|
|||||||
final Client client = event.getClient();
|
final Client client = event.getClient();
|
||||||
final Map<String, String> body = Map.of(
|
final Map<String, String> body = Map.of(
|
||||||
Constant.ROOM_ID, room.getRoomId(),
|
Constant.ROOM_ID, room.getRoomId(),
|
||||||
Constant.CLIENT_ID, client.clientId()
|
Constant.CLIENT_ID, client.getClientId()
|
||||||
);
|
);
|
||||||
room.broadcast(client, this.build(body));
|
room.broadcast(client, this.build(body));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,15 +52,15 @@ public class SessionCallProtocol extends ProtocolSessionAdapter {
|
|||||||
}
|
}
|
||||||
final Session session = this.sessionManager.call(client, target);
|
final Session session = this.sessionManager.call(client, target);
|
||||||
message.setBody(Map.of(
|
message.setBody(Map.of(
|
||||||
Constant.NAME, target.status().getName(),
|
Constant.NAME, target.getName(),
|
||||||
Constant.CLIENT_ID, target.clientId(),
|
Constant.CLIENT_ID, target.getClientId(),
|
||||||
Constant.SESSION_ID, session.getId()
|
Constant.SESSION_ID, session.getId()
|
||||||
));
|
));
|
||||||
client.push(message);
|
client.push(message);
|
||||||
final Message callMessage = message.cloneWithoutBody();
|
final Message callMessage = message.cloneWithoutBody();
|
||||||
callMessage.setBody(Map.of(
|
callMessage.setBody(Map.of(
|
||||||
Constant.NAME, client.status().getName(),
|
Constant.NAME, client.getName(),
|
||||||
Constant.CLIENT_ID, client.clientId(),
|
Constant.CLIENT_ID, client.getClientId(),
|
||||||
Constant.SESSION_ID, session.getId(),
|
Constant.SESSION_ID, session.getId(),
|
||||||
Constant.AUDIO, MapUtils.get(body, Constant.AUDIO, true),
|
Constant.AUDIO, MapUtils.get(body, Constant.AUDIO, true),
|
||||||
Constant.VIDEO, MapUtils.get(body, Constant.VIDEO, true)
|
Constant.VIDEO, MapUtils.get(body, Constant.VIDEO, true)
|
||||||
|
|||||||
Reference in New Issue
Block a user