Add convenience Call ctor for Message

This commit is contained in:
Frank A. Krueger 2017-06-15 21:27:15 -07:00
parent a8b227ec1c
commit 8e1da8c190
3 changed files with 10 additions and 12 deletions

View File

@ -108,12 +108,7 @@ namespace Ooui
protected void SendCall (string methodName, params object[] args) protected void SendCall (string methodName, params object[] args)
{ {
Send (new Message { Send (Message.Call (Id, methodName, args));
MessageType = MessageType.Call,
TargetId = Id,
Key = methodName,
Value = args,
});
} }
protected void SendSet (string attributeName, object value) protected void SendSet (string attributeName, object value)

View File

@ -22,6 +22,13 @@ namespace Ooui
[JsonProperty("v")] [JsonProperty("v")]
public object Value = null; public object Value = null;
public static Message Call (string targetId, string method, params object[] args) => new Message {
MessageType = MessageType.Call,
TargetId = targetId,
Key = method,
Value = args,
};
public static Message Event (string targetId, string eventType) => new Message { public static Message Event (string targetId, string eventType) => new Message {
MessageType = MessageType.Event, MessageType = MessageType.Event,
TargetId = targetId, TargetId = targetId,

View File

@ -353,12 +353,8 @@ namespace Ooui
// //
// Add it to the document body // Add it to the document body
// //
await SendMessageAsync (webSocket, new Message { await SendMessageAsync (webSocket, Message.Call ("document.body", "appendChild", element),
TargetId = "document.body", element, createdIds, token).ConfigureAwait (false);
MessageType = MessageType.Call,
Key = "appendChild",
Value = new[] { element },
}, element, createdIds, token).ConfigureAwait (false);
// //
// Listen for events // Listen for events