[*] 日常优化
This commit is contained in:
@@ -480,7 +480,7 @@ class RemoteClient {
|
|||||||
/**
|
/**
|
||||||
* 关闭媒体
|
* 关闭媒体
|
||||||
*/
|
*/
|
||||||
close() {
|
async close() {
|
||||||
const me = this;
|
const me = this;
|
||||||
if(me.closed) {
|
if(me.closed) {
|
||||||
return;
|
return;
|
||||||
@@ -488,23 +488,23 @@ class RemoteClient {
|
|||||||
console.debug("关闭终端", me.clientId);
|
console.debug("关闭终端", me.clientId);
|
||||||
me.closed = true;
|
me.closed = true;
|
||||||
if(me.audioTrack) {
|
if(me.audioTrack) {
|
||||||
me.audioTrack.stop();
|
await me.audioTrack.stop();
|
||||||
me.audioTrack = null;
|
me.audioTrack = null;
|
||||||
}
|
}
|
||||||
if(me.videoTrack) {
|
if(me.videoTrack) {
|
||||||
me.videoTrack.stop();
|
await me.videoTrack.stop();
|
||||||
me.videoTrack = null;
|
me.videoTrack = null;
|
||||||
}
|
}
|
||||||
if(me.dataConsumer) {
|
if(me.dataConsumer) {
|
||||||
me.dataConsumer.close();
|
await me.dataConsumer.close();
|
||||||
me.dataConsumer = null;
|
me.dataConsumer = null;
|
||||||
}
|
}
|
||||||
if(me.audioConsumer) {
|
if(me.audioConsumer) {
|
||||||
me.audioConsumer.close();
|
await me.audioConsumer.close();
|
||||||
me.audioConsumer = null;
|
me.audioConsumer = null;
|
||||||
}
|
}
|
||||||
if(me.videoConsumer) {
|
if(me.videoConsumer) {
|
||||||
me.videoConsumer.close();
|
await me.videoConsumer.close();
|
||||||
me.videoConsumer = null;
|
me.videoConsumer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -882,6 +882,9 @@ class Taoyao extends RemoteClient {
|
|||||||
case "room::close":
|
case "room::close":
|
||||||
me.defaultRoomClose(message);
|
me.defaultRoomClose(message);
|
||||||
break;
|
break;
|
||||||
|
case "room::create":
|
||||||
|
this.defaultRoomCreate(message);
|
||||||
|
break;
|
||||||
case "room::enter":
|
case "room::enter":
|
||||||
me.defaultRoomEnter(message);
|
me.defaultRoomEnter(message);
|
||||||
break;
|
break;
|
||||||
@@ -2328,20 +2331,6 @@ class Taoyao extends RemoteClient {
|
|||||||
me.closeRoomMedia();
|
me.closeRoomMedia();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建房间信令
|
|
||||||
*
|
|
||||||
* @param {*} room 房间
|
|
||||||
*
|
|
||||||
* @returns 房间
|
|
||||||
*/
|
|
||||||
async roomCreate(room) {
|
|
||||||
const me = this;
|
|
||||||
console.debug("创建房间", room);
|
|
||||||
const response = await me.request(protocol.buildMessage("room::create", room));
|
|
||||||
return response.body;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 媒体回调
|
* 媒体回调
|
||||||
*
|
*
|
||||||
@@ -2885,6 +2874,47 @@ class Taoyao extends RemoteClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建房间信令
|
||||||
|
*
|
||||||
|
* @param {*} room 房间信息
|
||||||
|
*
|
||||||
|
* @returns 响应消息
|
||||||
|
*/
|
||||||
|
async roomCreate(room) {
|
||||||
|
if(this.roomId) {
|
||||||
|
this.callbackError("终端已经进入房间");
|
||||||
|
return {
|
||||||
|
code : 9999,
|
||||||
|
message: "终端已经进入房间"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
console.debug("创建房间", room);
|
||||||
|
const response = await this.request(protocol.buildMessage("room::create", {
|
||||||
|
...room
|
||||||
|
}));
|
||||||
|
return response.body;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建房间信令
|
||||||
|
* 用于房间重建
|
||||||
|
*
|
||||||
|
* @param {*} message 信令消息
|
||||||
|
*/
|
||||||
|
async defaultRoomCreate(message) {
|
||||||
|
console.debug("创建房间", message);
|
||||||
|
const {
|
||||||
|
roomId,
|
||||||
|
password
|
||||||
|
} = message.body;
|
||||||
|
if(this.roomId && roomId === this.roomId) {
|
||||||
|
await this.roomLeave();
|
||||||
|
await this.roomEnter(roomId, password);
|
||||||
|
await this.mediaProduce();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 进入房间信令
|
* 进入房间信令
|
||||||
*
|
*
|
||||||
@@ -2927,6 +2957,7 @@ class Taoyao extends RemoteClient {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 进入房间信令
|
* 进入房间信令
|
||||||
|
* 其他终端进入房间
|
||||||
*
|
*
|
||||||
* @param {*} message 信令消息
|
* @param {*} message 信令消息
|
||||||
*/
|
*/
|
||||||
@@ -2965,7 +2996,7 @@ class Taoyao extends RemoteClient {
|
|||||||
*/
|
*/
|
||||||
async defaultRoomExpel(message) {
|
async defaultRoomExpel(message) {
|
||||||
console.debug("收到提出房间信令", message);
|
console.debug("收到提出房间信令", message);
|
||||||
this.roomLeave();
|
await this.roomLeave();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3004,11 +3035,11 @@ class Taoyao extends RemoteClient {
|
|||||||
/**
|
/**
|
||||||
* 离开房间信令
|
* 离开房间信令
|
||||||
*/
|
*/
|
||||||
roomLeave() {
|
async roomLeave() {
|
||||||
this.push(protocol.buildMessage("room::leave", {
|
this.push(protocol.buildMessage("room::leave", {
|
||||||
roomId: this.roomId
|
roomId: this.roomId
|
||||||
}));
|
}));
|
||||||
this.closeRoomMedia();
|
await this.closeRoomMedia();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3563,41 +3594,41 @@ class Taoyao extends RemoteClient {
|
|||||||
/**
|
/**
|
||||||
* 关闭视频房间媒体
|
* 关闭视频房间媒体
|
||||||
*/
|
*/
|
||||||
closeRoomMedia() {
|
async closeRoomMedia() {
|
||||||
console.debug("关闭视频房间媒体");
|
console.debug("关闭视频房间媒体");
|
||||||
const me = this;
|
const me = this;
|
||||||
me.roomId = null;
|
me.roomId = null;
|
||||||
me.close();
|
await me.close();
|
||||||
if (me.sendTransport) {
|
if (me.sendTransport) {
|
||||||
me.sendTransport.close();
|
await me.sendTransport.close();
|
||||||
me.sendTransport = null;
|
me.sendTransport = null;
|
||||||
}
|
}
|
||||||
if (me.recvTransport) {
|
if (me.recvTransport) {
|
||||||
me.recvTransport.close();
|
await me.recvTransport.close();
|
||||||
me.recvTransport = null;
|
me.recvTransport = null;
|
||||||
}
|
}
|
||||||
if(me.dataProducer) {
|
if(me.dataProducer) {
|
||||||
me.dataProducer.close();
|
await me.dataProducer.close();
|
||||||
me.dataProducer = null;
|
me.dataProducer = null;
|
||||||
}
|
}
|
||||||
if(me.audioProducer) {
|
if(me.audioProducer) {
|
||||||
me.audioProducer.close();
|
await me.audioProducer.close();
|
||||||
me.audioProducer = null;
|
me.audioProducer = null;
|
||||||
}
|
}
|
||||||
if(me.videoProducer) {
|
if(me.videoProducer) {
|
||||||
me.videoProducer.close();
|
await me.videoProducer.close();
|
||||||
me.videoProducer = null;
|
me.videoProducer = null;
|
||||||
}
|
}
|
||||||
me.consumers.forEach((consumer, consumerId) => {
|
me.consumers.forEach(async (consumer, consumerId) => {
|
||||||
consumer.close();
|
await consumer.close();
|
||||||
});
|
});
|
||||||
me.consumers.clear();
|
me.consumers.clear();
|
||||||
me.dataConsumers.forEach((dataConsumer, consumerId) => {
|
me.dataConsumers.forEach(async (dataConsumer, consumerId) => {
|
||||||
dataConsumer.close();
|
await dataConsumer.close();
|
||||||
});
|
});
|
||||||
me.dataConsumers.clear();
|
me.dataConsumers.clear();
|
||||||
me.remoteClients.forEach((client, clientId) => {
|
me.remoteClients.forEach(async (client, clientId) => {
|
||||||
client.close();
|
await client.close();
|
||||||
});
|
});
|
||||||
me.remoteClients.clear();
|
me.remoteClients.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,15 @@ public class RoomManager {
|
|||||||
// mediaClient.request(clone);
|
// mediaClient.request(clone);
|
||||||
// 更新媒体服务
|
// 更新媒体服务
|
||||||
room.setMediaClient(mediaClient);
|
room.setMediaClient(mediaClient);
|
||||||
// TODO:通知重建房间
|
if(room.getPassword() != null) {
|
||||||
|
clone.setBody(Map.of(
|
||||||
|
Constant.ROOM_ID, room.getRoomId(),
|
||||||
|
Constant.PASSWORD, room.getPassword()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
room.getClients().forEach((client, wrapper) -> {
|
||||||
|
client.push(clone);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import com.acgist.taoyao.signal.protocol.ProtocolClientAdapter;
|
|||||||
""",
|
""",
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
|
"roomId" : "房间ID",
|
||||||
"name" : "房间名称",
|
"name" : "房间名称",
|
||||||
"clientSize" : "终端数量",
|
"clientSize" : "终端数量",
|
||||||
"mediaClientId": "媒体服务ID"
|
"mediaClientId": "媒体服务ID"
|
||||||
@@ -56,13 +57,12 @@ public class RoomCreateProtocol extends ProtocolClientAdapter implements Applica
|
|||||||
@Override
|
@Override
|
||||||
public void onApplicationEvent(MediaServerRegisterEvent event) {
|
public void onApplicationEvent(MediaServerRegisterEvent event) {
|
||||||
this.roomManager.recreate(event.getClient(), this.build());
|
this.roomManager.recreate(event.getClient(), this.build());
|
||||||
// TODO:通知
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@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) {
|
||||||
if(clientType.isClient()) {
|
if(clientType.isClient()) {
|
||||||
// WEB同步创建房间
|
|
||||||
final Room room = this.roomManager.create(
|
final Room room = this.roomManager.create(
|
||||||
MapUtils.get(body, Constant.NAME),
|
MapUtils.get(body, Constant.NAME),
|
||||||
MapUtils.get(body, Constant.PASSWORD),
|
MapUtils.get(body, Constant.PASSWORD),
|
||||||
@@ -70,8 +70,7 @@ public class RoomCreateProtocol extends ProtocolClientAdapter implements Applica
|
|||||||
message.cloneWithoutBody()
|
message.cloneWithoutBody()
|
||||||
);
|
);
|
||||||
message.setBody(room.getRoomStatus());
|
message.setBody(room.getRoomStatus());
|
||||||
// 通知媒体终端
|
client.push(message);
|
||||||
this.clientManager.broadcast(message, ClientType.MEDIA_CLIENT_TYPE);
|
|
||||||
} else {
|
} else {
|
||||||
this.logNoAdapter(clientType);
|
this.logNoAdapter(clientType);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user