* LCIMClient.cs:
* LCIMSessionController.cs: * LCIMConversationController.cs: * ILCIMSignatureFactory.cs: chore: 支持 LCUser 登录
parent
0ea13ab725
commit
acee284f67
|
@ -57,7 +57,7 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
};
|
||||
}
|
||||
if (Client.SignatureFactory != null) {
|
||||
LCIMSignature signature = Client.SignatureFactory.CreateStartConversationSignature(Client.Id, members);
|
||||
LCIMSignature signature = await Client.SignatureFactory.CreateStartConversationSignature(Client.Id, members);
|
||||
conv.S = signature.Signature;
|
||||
conv.T = signature.Timestamp;
|
||||
conv.N = signature.Nonce;
|
||||
|
@ -145,7 +145,7 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
conv.M.AddRange(clientIds);
|
||||
// 签名参数
|
||||
if (Client.SignatureFactory != null) {
|
||||
LCIMSignature signature = Client.SignatureFactory.CreateConversationSignature(convId,
|
||||
LCIMSignature signature = await Client.SignatureFactory.CreateConversationSignature(convId,
|
||||
Client.Id,
|
||||
clientIds,
|
||||
LCIMSignatureAction.Invite);
|
||||
|
@ -175,7 +175,7 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
conv.M.AddRange(removeIds);
|
||||
// 签名参数
|
||||
if (Client.SignatureFactory != null) {
|
||||
LCIMSignature signature = Client.SignatureFactory.CreateConversationSignature(convId,
|
||||
LCIMSignature signature = await Client.SignatureFactory.CreateConversationSignature(convId,
|
||||
Client.Id,
|
||||
removeIds,
|
||||
LCIMSignatureAction.Kick);
|
||||
|
@ -271,7 +271,7 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
};
|
||||
blacklist.ToPids.AddRange(clientIds);
|
||||
if (Client.SignatureFactory != null) {
|
||||
LCIMSignature signature = Client.SignatureFactory.CreateBlacklistSignature(convId,
|
||||
LCIMSignature signature = await Client.SignatureFactory.CreateBlacklistSignature(convId,
|
||||
Client.Id,
|
||||
clientIds,
|
||||
LCIMSignatureAction.ConversationBlockClients);
|
||||
|
@ -298,7 +298,7 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
};
|
||||
blacklist.ToPids.AddRange(clientIds);
|
||||
if (Client.SignatureFactory != null) {
|
||||
LCIMSignature signature = Client.SignatureFactory.CreateBlacklistSignature(convId,
|
||||
LCIMSignature signature = await Client.SignatureFactory.CreateBlacklistSignature(convId,
|
||||
Client.Id,
|
||||
clientIds,
|
||||
LCIMSignatureAction.ConversationUnblockClients);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using LeanCloud.Storage;
|
||||
using LeanCloud.Realtime.Protocol;
|
||||
|
||||
namespace LeanCloud.Realtime.Internal.Controller {
|
||||
|
@ -19,7 +21,7 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal async Task Open(bool force) {
|
||||
SessionCommand session = NewSessionCommand();
|
||||
SessionCommand session = await NewSessionCommand();
|
||||
session.R = !force;
|
||||
GenericCommand request = NewCommand(CommandType.Session, OpType.Open);
|
||||
request.SessionMessage = session;
|
||||
|
@ -32,7 +34,7 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
/// </summary>
|
||||
/// <returns></returns>
|
||||
internal async Task Reopen() {
|
||||
SessionCommand session = NewSessionCommand();
|
||||
SessionCommand session = await NewSessionCommand();
|
||||
session.R = true;
|
||||
GenericCommand request = NewCommand(CommandType.Session, OpType.Open);
|
||||
request.SessionMessage = session;
|
||||
|
@ -67,14 +69,14 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
#endregion
|
||||
|
||||
private async Task Refresh() {
|
||||
SessionCommand session = NewSessionCommand();
|
||||
SessionCommand session = await NewSessionCommand();
|
||||
GenericCommand request = NewCommand(CommandType.Session, OpType.Refresh);
|
||||
request.SessionMessage = session;
|
||||
GenericCommand response = await Client.Connection.SendRequest(request);
|
||||
UpdateSession(response.SessionMessage);
|
||||
}
|
||||
|
||||
private SessionCommand NewSessionCommand() {
|
||||
private async Task<SessionCommand> NewSessionCommand() {
|
||||
SessionCommand session = new SessionCommand();
|
||||
if (Client.Tag != null) {
|
||||
session.Tag = Client.Tag;
|
||||
|
@ -82,8 +84,21 @@ namespace LeanCloud.Realtime.Internal.Controller {
|
|||
if (Client.DeviceId != null) {
|
||||
session.DeviceId = Client.DeviceId;
|
||||
}
|
||||
LCIMSignature signature = null;
|
||||
if (Client.SignatureFactory != null) {
|
||||
LCIMSignature signature = Client.SignatureFactory.CreateConnectSignature(Client.Id);
|
||||
signature = await Client.SignatureFactory.CreateConnectSignature(Client.Id);
|
||||
}
|
||||
if (signature == null && !string.IsNullOrEmpty(Client.SessionToken)) {
|
||||
Dictionary<string, object> ret = await LCApplication.HttpClient.Post<Dictionary<string, object>>("rtm/sign", data: new Dictionary<string, object> {
|
||||
{ "session_token", Client.SessionToken }
|
||||
});
|
||||
signature = new LCIMSignature {
|
||||
Signature = ret["signature"] as string,
|
||||
Timestamp = (long)ret["timestamp"],
|
||||
Nonce = ret["nonce"] as string
|
||||
};
|
||||
}
|
||||
if (signature != null) {
|
||||
session.S = signature.Signature;
|
||||
session.T = signature.Timestamp;
|
||||
session.N = signature.Nonce;
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
|||
using System.Linq;
|
||||
using System.Collections.ObjectModel;
|
||||
using LeanCloud.Common;
|
||||
using LeanCloud.Storage;
|
||||
using LeanCloud.Realtime.Protocol;
|
||||
using LeanCloud.Realtime.Internal.Controller;
|
||||
using LeanCloud.Realtime.Internal.Connection;
|
||||
|
@ -27,6 +28,10 @@ namespace LeanCloud.Realtime {
|
|||
get; private set;
|
||||
}
|
||||
|
||||
internal string SessionToken {
|
||||
get; private set;
|
||||
}
|
||||
|
||||
#region 事件
|
||||
|
||||
#region 连接状态事件
|
||||
|
@ -248,6 +253,31 @@ namespace LeanCloud.Realtime {
|
|||
string tag = null,
|
||||
string deviceId = null,
|
||||
ILCIMSignatureFactory signatureFactory = null) {
|
||||
if (string.IsNullOrEmpty(clientId)) {
|
||||
throw new ArgumentNullException(nameof(clientId));
|
||||
}
|
||||
SetUpClient(clientId, tag, deviceId, signatureFactory);
|
||||
}
|
||||
|
||||
public LCIMClient(LCUser user,
|
||||
string tag = null,
|
||||
string deviceId = null,
|
||||
ILCIMSignatureFactory signatureFactory = null) {
|
||||
if (user == null) {
|
||||
throw new ArgumentNullException(nameof(user));
|
||||
}
|
||||
if (string.IsNullOrEmpty(user.ObjectId) ||
|
||||
string.IsNullOrEmpty(user.SessionToken)) {
|
||||
throw new ArgumentException("User must be authenticacted.");
|
||||
}
|
||||
SetUpClient(user.ObjectId, tag, deviceId, signatureFactory);
|
||||
SessionToken = user.SessionToken;
|
||||
}
|
||||
|
||||
private void SetUpClient(string clientId,
|
||||
string tag,
|
||||
string deviceId,
|
||||
ILCIMSignatureFactory signatureFactory) {
|
||||
Id = clientId;
|
||||
Tag = tag;
|
||||
DeviceId = deviceId;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LeanCloud.Realtime {
|
||||
public interface ILCIMSignatureFactory {
|
||||
|
@ -7,13 +8,13 @@ namespace LeanCloud.Realtime {
|
|||
/// </summary>
|
||||
/// <param name="clientId"></param>
|
||||
/// <returns></returns>
|
||||
LCIMSignature CreateConnectSignature(string clientId);
|
||||
Task<LCIMSignature> CreateConnectSignature(string clientId);
|
||||
|
||||
/// <summary>
|
||||
/// 创建开启对话签名
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
LCIMSignature CreateStartConversationSignature(string clientId, IEnumerable<string> memberIds);
|
||||
Task<LCIMSignature> CreateStartConversationSignature(string clientId, IEnumerable<string> memberIds);
|
||||
|
||||
/// <summary>
|
||||
/// 创建会话相关签名
|
||||
|
@ -23,7 +24,7 @@ namespace LeanCloud.Realtime {
|
|||
/// <param name="memberIds"></param>
|
||||
/// <param name="action"></param>
|
||||
/// <returns></returns>
|
||||
LCIMSignature CreateConversationSignature(string conversationId, string clientId, IEnumerable<string> memberIds, string action);
|
||||
Task<LCIMSignature> CreateConversationSignature(string conversationId, string clientId, IEnumerable<string> memberIds, string action);
|
||||
|
||||
/// <summary>
|
||||
/// 创建黑名单相关签名
|
||||
|
@ -33,6 +34,6 @@ namespace LeanCloud.Realtime {
|
|||
/// <param name="memberIds"></param>
|
||||
/// <param name="action"></param>
|
||||
/// <returns></returns>
|
||||
LCIMSignature CreateBlacklistSignature(string conversationId, string clientId, IEnumerable<string> memberIds, string action);
|
||||
Task<LCIMSignature> CreateBlacklistSignature(string conversationId, string clientId, IEnumerable<string> memberIds, string action);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
using System;
|
||||
namespace Realtime.Test {
|
||||
public class Client {
|
||||
public Client() {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
using System;
|
||||
namespace Realtime.Test {
|
||||
public class ConversationQuery {
|
||||
public ConversationQuery() {
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue