|
|
@ -103,7 +103,11 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
throw new Exception(ex.Message); |
|
|
|
throw new Exception(ex.Message); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 进入房间 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="enterInfo"></param> |
|
|
|
|
|
|
|
/// <returns></returns> |
|
|
|
public async Task<RoomEnterResult> CallServer_EnterRoom(RoomEnterData enterInfo) |
|
|
|
public async Task<RoomEnterResult> CallServer_EnterRoom(RoomEnterData enterInfo) |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
@ -146,7 +150,11 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 离开房间 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="leaveInfo"></param> |
|
|
|
|
|
|
|
/// <returns></returns> |
|
|
|
public async Task<RoomEnterResult> CallServer_LeaveRoom(RoomLeaveData leaveInfo) |
|
|
|
public async Task<RoomEnterResult> CallServer_LeaveRoom(RoomLeaveData leaveInfo) |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
@ -192,32 +200,44 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
//TODO:保存数据 |
|
|
|
//TODO:保存数据 |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 上线处理 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <returns></returns> |
|
|
|
public override async Task OnConnectedAsync() |
|
|
|
public override async Task OnConnectedAsync() |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
var userId = Context.UserIdentifier; |
|
|
|
var userId = Context.UserIdentifier; |
|
|
|
var userName = Context.GetNameOfCurrentUser(); |
|
|
|
var userName = Context.GetNameOfCurrentUser(); |
|
|
|
FireDeductionUser? user = roomManager.GetUser(userId!); |
|
|
|
var user = roomManager.GetUser(userId!); |
|
|
|
|
|
|
|
|
|
|
|
if (user != null) |
|
|
|
if (user != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
user.Online = true; |
|
|
|
user.Online = true; |
|
|
|
if (user.ConnectionId != Context.ConnectionId) |
|
|
|
if (user.ConnectionId != Context.ConnectionId) |
|
|
|
user.ConnectionId = Context.ConnectionId; |
|
|
|
user.ConnectionId = Context.ConnectionId; |
|
|
|
var room = roomManager.GetRoomByUserId(user.UserId); |
|
|
|
var room = roomManager.GetRoom(user.UserId); |
|
|
|
if (room != null) |
|
|
|
if (room != null && !string.IsNullOrEmpty(user.RoomId)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//断线重连 |
|
|
|
//断线重连 |
|
|
|
|
|
|
|
RoommateChangeData data = new() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ChangeType = RoommateChangeType.OnLine, |
|
|
|
|
|
|
|
FireDeductionUser = user, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
//通知web端刷新房间用户状态 |
|
|
|
|
|
|
|
await Clients.Group(room.RoomId).SendAsync("callWeb_changeRoomate", data); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
user = new FireDeductionUser(); |
|
|
|
user = new FireDeductionUser |
|
|
|
user.ConnectionId = Context.ConnectionId; |
|
|
|
{ |
|
|
|
user.UserId = userId!; |
|
|
|
ConnectionId = Context.ConnectionId, |
|
|
|
user.UserName = userName!; |
|
|
|
UserId = userId!, |
|
|
|
|
|
|
|
UserName = userName! |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
roomManager.AddUser(user); |
|
|
|
roomManager.AddUser(user); |
|
|
|
} |
|
|
|
} |
|
|
@ -230,7 +250,11 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
throw; |
|
|
|
throw; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 离线处理 |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
/// <param name="exception"></param> |
|
|
|
|
|
|
|
/// <returns></returns> |
|
|
|
public override async Task OnDisconnectedAsync(Exception? exception) |
|
|
|
public override async Task OnDisconnectedAsync(Exception? exception) |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
@ -242,13 +266,20 @@ namespace AX.WebDrillServer.Hubs |
|
|
|
if (userId != null) |
|
|
|
if (userId != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var user = roomManager.GetUser(userId!); |
|
|
|
var user = roomManager.GetUser(userId!); |
|
|
|
if (user != null) |
|
|
|
if (user != null && !string.IsNullOrEmpty(user.RoomId)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
user.Online = false; |
|
|
|
user.Online = false; |
|
|
|
var room = roomManager.GetRoomByUserId(user.UserId); |
|
|
|
var room = roomManager.GetRoom(user.RoomId); |
|
|
|
if (room != null) |
|
|
|
if (room != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//断线 |
|
|
|
//断线 |
|
|
|
|
|
|
|
RoommateChangeData data = new() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ChangeType = RoommateChangeType.OffLine, |
|
|
|
|
|
|
|
FireDeductionUser = user, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
//通知web端刷新房间用户状态 |
|
|
|
|
|
|
|
await Clients.Group(room.RoomId).SendAsync("callWeb_changeRoomate", data); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|