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)
{
Send (new Message {
MessageType = MessageType.Call,
TargetId = Id,
Key = methodName,
Value = args,
});
Send (Message.Call (Id, methodName, args));
}
protected void SendSet (string attributeName, object value)

View File

@ -22,6 +22,13 @@ namespace Ooui
[JsonProperty("v")]
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 {
MessageType = MessageType.Event,
TargetId = targetId,

View File

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