From a845aa1230a50d6d41fbdc4dff7cb84b1cb022c1 Mon Sep 17 00:00:00 2001 From: sta Date: Wed, 2 Feb 2022 22:06:03 +0900 Subject: [PATCH] [Delete] Example1 --- Example1/AssemblyInfo.cs | 26 ----- Example1/AudioStreamer.cs | 192 -------------------------------- Example1/BinaryMessage.cs | 74 ------------ Example1/Example1.csproj | 77 ------------- Example1/NotificationMessage.cs | 24 ---- Example1/Notifier.cs | 81 -------------- Example1/Program.cs | 37 ------ Example1/TextMessage.cs | 33 ------ websocket-sharp.sln | 10 -- 9 files changed, 554 deletions(-) delete mode 100644 Example1/AssemblyInfo.cs delete mode 100644 Example1/AudioStreamer.cs delete mode 100644 Example1/BinaryMessage.cs delete mode 100644 Example1/Example1.csproj delete mode 100644 Example1/NotificationMessage.cs delete mode 100644 Example1/Notifier.cs delete mode 100644 Example1/Program.cs delete mode 100644 Example1/TextMessage.cs diff --git a/Example1/AssemblyInfo.cs b/Example1/AssemblyInfo.cs deleted file mode 100644 index a78e6c6d..00000000 --- a/Example1/AssemblyInfo.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("Example1")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("sta.blockhead")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.*")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] diff --git a/Example1/AudioStreamer.cs b/Example1/AudioStreamer.cs deleted file mode 100644 index 711694e9..00000000 --- a/Example1/AudioStreamer.cs +++ /dev/null @@ -1,192 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using WebSocketSharp; - -namespace Example1 -{ - internal class AudioStreamer : IDisposable - { - private Dictionary _audioBox; - private uint? _id; - private string _name; - private Notifier _notifier; - private Timer _timer; - private WebSocket _websocket; - - public AudioStreamer (string url) - { - _websocket = new WebSocket (url); - - _audioBox = new Dictionary (); - _id = null; - _notifier = new Notifier (); - _timer = new Timer (sendHeartbeat, null, -1, -1); - - configure (); - } - - private void configure () - { -#if DEBUG - _websocket.Log.Level = LogLevel.Trace; -#endif - _websocket.OnOpen += (sender, e) => - _websocket.Send (createTextMessage ("connection", String.Empty)); - - _websocket.OnMessage += (sender, e) => { - if (e.IsText) { - _notifier.Notify (processTextMessage (e.Data)); - return; - } - - if (e.IsBinary) { - processBinaryMessage (e.RawData); - return; - } - }; - - _websocket.OnError += (sender, e) => - _notifier.Notify ( - new NotificationMessage { - Summary = "AudioStreamer (error)", - Body = e.Message, - Icon = "notification-message-im" - } - ); - - _websocket.OnClose += (sender, e) => - _notifier.Notify ( - new NotificationMessage { - Summary = "AudioStreamer (disconnect)", - Body = String.Format ("code: {0} reason: {1}", e.Code, e.Reason), - Icon = "notification-message-im" - } - ); - } - - private byte[] createBinaryMessage (float[,] bufferArray) - { - return new BinaryMessage { - UserID = (uint) _id, - ChannelNumber = (byte) bufferArray.GetLength (0), - BufferLength = (uint) bufferArray.GetLength (1), - BufferArray = bufferArray - } - .ToArray (); - } - - private string createTextMessage (string type, string message) - { - return new TextMessage { - UserID = _id, - Name = _name, - Type = type, - Message = message - } - .ToString (); - } - - private void processBinaryMessage (byte[] data) - { - var msg = BinaryMessage.Parse (data); - - var id = msg.UserID; - if (id == _id) - return; - - Queue queue; - if (_audioBox.TryGetValue (id, out queue)) { - queue.Enqueue (msg.BufferArray); - return; - } - - queue = Queue.Synchronized (new Queue ()); - queue.Enqueue (msg.BufferArray); - _audioBox.Add (id, queue); - } - - private NotificationMessage processTextMessage (string data) - { - var json = JObject.Parse (data); - var id = (uint) json["user_id"]; - var name = (string) json["name"]; - var type = (string) json["type"]; - - string body; - if (type == "message") { - body = String.Format ("{0}: {1}", name, (string) json["message"]); - } - else if (type == "start_music") { - body = String.Format ("{0}: Started playing music!", name); - } - else if (type == "connection") { - var users = (JArray) json["message"]; - var buff = new StringBuilder ("Now keeping connections:"); - foreach (JToken user in users) { - buff.AppendFormat ( - "\n- user_id: {0} name: {1}", (uint) user["user_id"], (string) user["name"] - ); - } - - body = buff.ToString (); - } - else if (type == "connected") { - _id = id; - _timer.Change (30000, 30000); - - body = String.Format ("user_id: {0} name: {1}", id, name); - } - else { - body = "Received unknown type message."; - } - - return new NotificationMessage { - Summary = String.Format ("AudioStreamer ({0})", type), - Body = body, - Icon = "notification-message-im" - }; - } - - private void sendHeartbeat (object state) - { - _websocket.Send (createTextMessage ("heartbeat", String.Empty)); - } - - public void Close () - { - Disconnect (); - _timer.Dispose (); - _notifier.Close (); - } - - public void Connect (string username) - { - _name = username; - _websocket.Connect (); - } - - public void Disconnect () - { - _timer.Change (-1, -1); - _websocket.Close (CloseStatusCode.Away); - _audioBox.Clear (); - _id = null; - _name = null; - } - - public void Write (string message) - { - _websocket.Send (createTextMessage ("message", message)); - } - - void IDisposable.Dispose () - { - Close (); - } - } -} diff --git a/Example1/BinaryMessage.cs b/Example1/BinaryMessage.cs deleted file mode 100644 index eafa7aa9..00000000 --- a/Example1/BinaryMessage.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.Collections.Generic; -using WebSocketSharp; - -namespace Example1 -{ - internal class BinaryMessage - { - public uint UserID { - get; set; - } - - public byte ChannelNumber { - get; set; - } - - public uint BufferLength { - get; set; - } - - public float[,] BufferArray { - get; set; - } - - public static BinaryMessage Parse (byte[] data) - { - var id = data.SubArray (0, 4).To (ByteOrder.Big); - var num = data.SubArray (4, 1)[0]; - var len = data.SubArray (5, 4).To (ByteOrder.Big); - var arr = new float[num, len]; - - var offset = 9; - ((uint) num).Times ( - i => - len.Times ( - j => { - arr[i, j] = data.SubArray (offset, 4).To (ByteOrder.Big); - offset += 4; - } - ) - ); - - return new BinaryMessage { - UserID = id, - ChannelNumber = num, - BufferLength = len, - BufferArray = arr - }; - } - - public byte[] ToArray () - { - var buff = new List (); - - var id = UserID; - var num = ChannelNumber; - var len = BufferLength; - var arr = BufferArray; - - buff.AddRange (id.ToByteArray (ByteOrder.Big)); - buff.Add (num); - buff.AddRange (len.ToByteArray (ByteOrder.Big)); - - ((uint) num).Times ( - i => - len.Times ( - j => buff.AddRange (arr[i, j].ToByteArray (ByteOrder.Big)) - ) - ); - - return buff.ToArray (); - } - } -} diff --git a/Example1/Example1.csproj b/Example1/Example1.csproj deleted file mode 100644 index 81c52eff..00000000 --- a/Example1/Example1.csproj +++ /dev/null @@ -1,77 +0,0 @@ - - - - Debug - AnyCPU - 9.0.21022 - 2.0 - {390E2568-57B7-4D17-91E5-C29336368CCF} - Exe - Example - example1 - v3.5 - - - true - full - false - bin\Debug - DEBUG; - prompt - 4 - true - - - none - false - bin\Release - prompt - 4 - true - - - true - full - false - bin\Debug_Ubuntu - DEBUG;UBUNTU - prompt - 4 - true - - - none - false - bin\Release_Ubuntu - prompt - 4 - true - UBUNTU - - - - - False - notify-sharp - - - False - - - - - - - - - - - - - - - {B357BAC7-529E-4D81-A0D2-71041B19C8DE} - websocket-sharp - - - \ No newline at end of file diff --git a/Example1/NotificationMessage.cs b/Example1/NotificationMessage.cs deleted file mode 100644 index 01f1692a..00000000 --- a/Example1/NotificationMessage.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -namespace Example1 -{ - internal class NotificationMessage - { - public string Body { - get; set; - } - - public string Icon { - get; set; - } - - public string Summary { - get; set; - } - - public override string ToString () - { - return String.Format ("{0}: {1}", Summary, Body); - } - } -} diff --git a/Example1/Notifier.cs b/Example1/Notifier.cs deleted file mode 100644 index adf53ec9..00000000 --- a/Example1/Notifier.cs +++ /dev/null @@ -1,81 +0,0 @@ -#if UBUNTU -using Notifications; -#endif -using System; -using System.Collections; -using System.Collections.Generic; -using System.Threading; - -namespace Example1 -{ - internal class Notifier : IDisposable - { - private volatile bool _enabled; - private ManualResetEvent _exited; - private Queue _queue; - private object _sync; - - public Notifier () - { - _enabled = true; - _exited = new ManualResetEvent (false); - _queue = new Queue (); - _sync = ((ICollection) _queue).SyncRoot; - - ThreadPool.QueueUserWorkItem ( - state => { - while (_enabled || Count > 0) { - var msg = dequeue (); - if (msg != null) { -#if UBUNTU - var nf = new Notification (msg.Summary, msg.Body, msg.Icon); - nf.AddHint ("append", "allowed"); - nf.Show (); -#else - Console.WriteLine (msg); -#endif - } - else { - Thread.Sleep (500); - } - } - - _exited.Set (); - } - ); - } - - public int Count { - get { - lock (_sync) - return _queue.Count; - } - } - - private NotificationMessage dequeue () - { - lock (_sync) - return _queue.Count > 0 ? _queue.Dequeue () : null; - } - - public void Close () - { - _enabled = false; - _exited.WaitOne (); - _exited.Close (); - } - - public void Notify (NotificationMessage message) - { - lock (_sync) { - if (_enabled) - _queue.Enqueue (message); - } - } - - void IDisposable.Dispose () - { - Close (); - } - } -} diff --git a/Example1/Program.cs b/Example1/Program.cs deleted file mode 100644 index 88c0bedf..00000000 --- a/Example1/Program.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Threading; - -namespace Example1 -{ - public class Program - { - public static void Main (string[] args) - { - // The AudioStreamer class provides a client (chat) for AudioStreamer - // (https://github.com/agektmr/AudioStreamer). - - using (var streamer = new AudioStreamer ("ws://localhost:3000/socket")) - { - string name; - do { - Console.Write ("Input your name> "); - name = Console.ReadLine (); - } - while (name.Length == 0); - - streamer.Connect (name); - - Console.WriteLine ("\nType 'exit' to exit.\n"); - while (true) { - Thread.Sleep (1000); - Console.Write ("> "); - var msg = Console.ReadLine (); - if (msg == "exit") - break; - - streamer.Write (msg); - } - } - } - } -} diff --git a/Example1/TextMessage.cs b/Example1/TextMessage.cs deleted file mode 100644 index 2b177d84..00000000 --- a/Example1/TextMessage.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Newtonsoft.Json; -using System; - -namespace Example1 -{ - internal class TextMessage - { - [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); - } - } -} diff --git a/websocket-sharp.sln b/websocket-sharp.sln index 3c20e06a..6ff1c036 100644 --- a/websocket-sharp.sln +++ b/websocket-sharp.sln @@ -5,8 +5,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "websocket-sharp", "websocke EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example", "Example\Example.csproj", "{52805AEC-EFB1-4F42-BB8E-3ED4E692C568}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example1", "Example1\Example1.csproj", "{390E2568-57B7-4D17-91E5-C29336368CCF}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example2", "Example2\Example2.csproj", "{B81A24C8-25BB-42B2-AF99-1E1EACCE74C7}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example3", "Example3\Example3.csproj", "{C648BA25-77E5-4A40-A97F-D0AA37B9FB26}" @@ -19,14 +17,6 @@ Global Release_Ubuntu|Any CPU = Release_Ubuntu|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {390E2568-57B7-4D17-91E5-C29336368CCF}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU - {390E2568-57B7-4D17-91E5-C29336368CCF}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU - {390E2568-57B7-4D17-91E5-C29336368CCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {390E2568-57B7-4D17-91E5-C29336368CCF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {390E2568-57B7-4D17-91E5-C29336368CCF}.Release_Ubuntu|Any CPU.ActiveCfg = Release_Ubuntu|Any CPU - {390E2568-57B7-4D17-91E5-C29336368CCF}.Release_Ubuntu|Any CPU.Build.0 = Release_Ubuntu|Any CPU - {390E2568-57B7-4D17-91E5-C29336368CCF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {390E2568-57B7-4D17-91E5-C29336368CCF}.Release|Any CPU.Build.0 = Release|Any CPU {52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug_Ubuntu|Any CPU.ActiveCfg = Debug_Ubuntu|Any CPU {52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug_Ubuntu|Any CPU.Build.0 = Debug_Ubuntu|Any CPU {52805AEC-EFB1-4F42-BB8E-3ED4E692C568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU