From df74f3d02140d3373659918e736391671de09001 Mon Sep 17 00:00:00 2001 From: sta Date: Sun, 31 Jul 2016 17:02:25 +0900 Subject: [PATCH] [Modify] Polish it --- Example1/AudioStreamer.cs | 15 +++++++-------- Example1/Program.cs | 4 ++-- Example1/TextMessage.cs | 29 +++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Example1/AudioStreamer.cs b/Example1/AudioStreamer.cs index 8ad5b51c..c397dc41 100644 --- a/Example1/AudioStreamer.cs +++ b/Example1/AudioStreamer.cs @@ -119,14 +119,13 @@ namespace Example1 private string createTextMessage (string type, string message) { - return JsonConvert.SerializeObject ( - new TextMessage { - user_id = _id, - name = _name, - type = type, - message = message - } - ); + return new TextMessage { + UserID = _id, + Name = _name, + Type = type, + Message = message + } + .ToString (); } private void processBinaryMessage (byte[] data) diff --git a/Example1/Program.cs b/Example1/Program.cs index 7b936da9..14613efd 100644 --- a/Example1/Program.cs +++ b/Example1/Program.cs @@ -7,8 +7,8 @@ namespace Example1 { public static void Main (string[] args) { - using (var streamer = new AudioStreamer ("ws://agektmr.node-ninja.com:3000/socket")) - //using (var streamer = new AudioStreamer ("ws://localhost:3000/socket")) + //using (var streamer = new AudioStreamer ("ws://agektmr.node-ninja.com:3000/socket")) + using (var streamer = new AudioStreamer ("ws://localhost:3000/socket")) { string name; do { diff --git a/Example1/TextMessage.cs b/Example1/TextMessage.cs index 5eab648f..2b177d84 100644 --- a/Example1/TextMessage.cs +++ b/Example1/TextMessage.cs @@ -1,12 +1,33 @@ +using Newtonsoft.Json; using System; namespace Example1 { internal class TextMessage { - public uint? user_id; - public string name; - public string type; - public string message; + [JsonProperty ("user_id")] + public uint? UserID { + get; set; + } + + [JsonProperty ("name")] + public string Name { + get; set; + } + + [JsonProperty ("type")] + public string Type { + get; set; + } + + [JsonProperty ("message")] + public string Message { + get; set; + } + + public override string ToString () + { + return JsonConvert.SerializeObject (this); + } } }