* LCIMAudioMessage.cs: chore: 完善消息类型

* Program.cs:
* LCIMFileMessage.cs:
* LCIMImageMessage.cs:
* LCIMVideoMessage.cs:
* LCIMLocationMessage.cs:
oneRain 2020-03-18 11:41:13 +08:00
parent 6b4d28b000
commit 29a84b8afb
6 changed files with 140 additions and 18 deletions

View File

@ -1,7 +1,17 @@
using System;
namespace LeanCloud.Realtime.Message {
public class LCIMAudioMessage {
public LCIMAudioMessage() {
using LeanCloud.Storage;
namespace LeanCloud.Realtime {
public class LCIMAudioMessage : LCIMFileMessage {
public double Duration {
get {
if (double.TryParse("duration", out double duration)) {
return duration;
}
return 0;
}
}
public LCIMAudioMessage(LCFile file) : base(file) {
}
}
}

View File

@ -1,7 +1,53 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using LeanCloud.Storage;
namespace LeanCloud.Realtime {
public class LCIMFileMessage {
public LCIMFileMessage() {
public class LCIMFileMessage : LCIMTextMessage {
public LCFile File {
get; set;
}
public int Size {
get {
if (int.TryParse(File.MetaData["size"] as string, out int size)) {
return size;
}
return 0;
}
}
public string Format {
get {
return File.MimeType;
}
}
public string Url {
get {
return File.Url;
}
}
public LCIMFileMessage(LCFile file) : base(null) {
File = file;
}
internal override string Serialize() {
if (File == null) {
throw new Exception("File MUST NOT be null before sent.");
}
File.MetaData["name"] = File.Name;
File.MetaData["format"] = File.MimeType;
Dictionary<string, object> data = new Dictionary<string, object> {
{ "objId", File.ObjectId },
{ "url", File.Url },
{ "metaData", File.MetaData }
};
return JsonConvert.SerializeObject(new Dictionary<string, object> {
{ "_lcfile", data }
});
}
}
}

View File

@ -1,7 +1,27 @@
using System;
namespace LeanCloud.Realtime.Message {
public class LCIMImageMessage {
public LCIMImageMessage() {
using LeanCloud.Storage;
namespace LeanCloud.Realtime {
public class LCIMImageMessage : LCIMFileMessage {
public int Width {
get {
if (int.TryParse(File.MetaData["width"] as string, out int width)) {
return width;
}
return 0;
}
}
public int Height {
get {
if (int.TryParse(File.MetaData["height"] as string, out int height)) {
return height;
}
return 0;
}
}
public LCIMImageMessage(LCFile file) : base(file) {
}
}
}

View File

@ -1,7 +1,25 @@
using System;
namespace LeanCloud.Realtime.Message {
public class LCIMLocationMessage {
public LCIMLocationMessage() {
using System.Collections.Generic;
using Newtonsoft.Json;
using LeanCloud.Storage;
namespace LeanCloud.Realtime {
public class LCIMLocationMessage : LCIMTextMessage {
public LCGeoPoint Location {
get; set;
}
public LCIMLocationMessage(LCGeoPoint locaction) : base(null) {
Location = locaction;
}
internal override string Serialize() {
Dictionary<string, object> data = new Dictionary<string, object> {
{ "longitude", Location.Longitude },
{ "latitude", Location.Latitude }
};
return JsonConvert.SerializeObject(new Dictionary<string, object> {
{ "_lcloc", data }
});
}
}
}

View File

@ -0,0 +1,18 @@
using LeanCloud.Storage;
namespace LeanCloud.Realtime {
public class LCIMVideoMessage : LCIMFileMessage {
public double Duration {
get {
if (double.TryParse(File.MetaData["duration"] as string, out double duration)) {
return duration;
}
return 0;
}
}
public LCIMVideoMessage(LCFile file) : base(file) {
}
}
}

View File

@ -4,6 +4,7 @@ using System.Threading;
using System.Threading.Tasks;
using LeanCloud;
using LeanCloud.Common;
using LeanCloud.Storage;
using LeanCloud.Realtime;
namespace RealtimeConsole {
@ -56,13 +57,13 @@ namespace RealtimeConsole {
string name = Guid.NewGuid().ToString();
LCIMConversation conversation = await client.CreateConversation(memberIdList, name: name, unique: true);
LCIMTextMessage textMessage = new LCIMTextMessage("hello, world");
await conversation.Send(textMessage);
//LCIMTextMessage textMessage = new LCIMTextMessage("hello, world");
//await conversation.Send(textMessage);
await Task.Delay(3000);
//await Task.Delay(3000);
LCIMTextMessage newMessage = new LCIMTextMessage("hello, code");
await conversation.Update(textMessage, newMessage);
//LCIMTextMessage newMessage = new LCIMTextMessage("hello, code");
//await conversation.Update(textMessage, newMessage);
//// 设置成员的角色
//await conversation.UpdateMemberRole("world", LCIMConversationMemberInfo.Manager);
@ -75,6 +76,15 @@ namespace RealtimeConsole {
//LCIMTextMessage textMessage = new LCIMTextMessage("hello, world");
//await conversation.Send(textMessage);
LCFile file = new LCFile("avatar", "../../../Storage.Test/assets/hello.png");
await file.Save();
LCIMImageMessage imageMessage = new LCIMImageMessage(file);
await conversation.Send(imageMessage);
LCGeoPoint location = new LCGeoPoint(11, 12);
LCIMLocationMessage locationMessage = new LCIMLocationMessage(location);
await conversation.Send(locationMessage);
}
}
}