Правильная обработка DisconnectReason при сборсах и обрывах соединения
This commit is contained in:
@@ -13,6 +13,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import io.g365sfu.exception.SFUException;
|
||||
import io.g365sfu.exception.SFUHandshakeException;
|
||||
import io.g365sfu.net.DisconnectReason;
|
||||
import io.g365sfu.net.DisconnectedPeer;
|
||||
import io.g365sfu.net.Incoming;
|
||||
import io.g365sfu.net.Outgoing;
|
||||
@@ -215,13 +216,14 @@ public class SFU {
|
||||
message.get(peerIdBytes);
|
||||
String peerId = new String(peerIdBytes).trim();
|
||||
Room room = this.rooms.get(roomId);
|
||||
DisconnectedPeer disconnectedPeer = new DisconnectedPeer(peerId, roomId, room);
|
||||
DisconnectReason reason = io.g365sfu.net.DisconnectReason.fromCode(message.getInt());
|
||||
if(room != null) {
|
||||
/**
|
||||
* Если такая комната существует то удаляем оттуда участника
|
||||
*/
|
||||
room.removeParticipant(peerId);
|
||||
}
|
||||
DisconnectedPeer disconnectedPeer = new DisconnectedPeer(peerId, roomId, room, reason);
|
||||
if(this.onPeerDisconnected != null) {
|
||||
this.onPeerDisconnected.accept(disconnectedPeer);
|
||||
}
|
||||
@@ -396,6 +398,14 @@ public class SFU {
|
||||
this.onDeleteRoom = onDeleteRoom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Устанавливает потребителя для обработки сообщений от сервера SFU о том, что участник отключился от комнаты.
|
||||
* @param onPeerDisconnected потребитель, который будет вызываться при получении сообщения от сервера SFU с кодом 0x11,
|
||||
*/
|
||||
public void setPeerDisconnectedConsumer(Consumer<DisconnectedPeer> onPeerDisconnected) {
|
||||
this.onPeerDisconnected = onPeerDisconnected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает TURN сервер на этом SFU
|
||||
*/
|
||||
|
||||
25
src/main/java/io/g365sfu/net/DisconnectReason.java
Normal file
25
src/main/java/io/g365sfu/net/DisconnectReason.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package io.g365sfu.net;
|
||||
|
||||
public enum DisconnectReason {
|
||||
FAILED(0),
|
||||
CLOSED(1);
|
||||
|
||||
private final int code;
|
||||
|
||||
DisconnectReason(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public static DisconnectReason fromCode(int code) {
|
||||
for (DisconnectReason reason : DisconnectReason.values()) {
|
||||
if (reason.code == code) {
|
||||
return reason;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown DisconnectReason code: " + code);
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,13 @@ public class DisconnectedPeer {
|
||||
private String peerId;
|
||||
private Room room;
|
||||
private String roomId;
|
||||
private DisconnectReason reason;
|
||||
|
||||
public DisconnectedPeer(String peerId, String roomId, Room room) {
|
||||
public DisconnectedPeer(String peerId, String roomId, Room room, DisconnectReason reason) {
|
||||
this.peerId = peerId;
|
||||
this.room = room;
|
||||
this.roomId = roomId;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public String getPeerId() {
|
||||
@@ -25,4 +27,8 @@ public class DisconnectedPeer {
|
||||
public String getRoomId() {
|
||||
return roomId;
|
||||
}
|
||||
|
||||
public DisconnectReason getReason() {
|
||||
return reason;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user