1
This commit is contained in:
@@ -49,6 +49,14 @@ namespace Assets.MyGame.Scripts.Net
|
||||
/// 创建或返回已存在的 WebSocket
|
||||
/// </summary>
|
||||
public WebSocket Connect(SocketType type,Action action=null)
|
||||
{
|
||||
return Connect(type, null, action);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建或返回已存在的 WebSocket(可指定动态 URL,用于 /api/Room/Assign 返回的房间专属地址)
|
||||
/// </summary>
|
||||
public WebSocket Connect(SocketType type, string url, Action action = null)
|
||||
{
|
||||
// 已存在则直接返回
|
||||
if (sockets.TryGetValue(type, out var exist))
|
||||
@@ -83,7 +91,9 @@ namespace Assets.MyGame.Scripts.Net
|
||||
}
|
||||
}
|
||||
|
||||
string url = baseUrl + socketPaths[type];
|
||||
// 未指定 url 时用默认 baseUrl + socketPaths
|
||||
if (string.IsNullOrEmpty(url))
|
||||
url = baseUrl + socketPaths[type];
|
||||
var ws = new WebSocket(new Uri(url));
|
||||
sockets[type] = ws;
|
||||
// 事件绑定
|
||||
|
||||
Reference in New Issue
Block a user