Fix a few
This commit is contained in:
parent
f068425b10
commit
20e2ac2521
@ -9,7 +9,7 @@ using System.Runtime.CompilerServices;
|
|||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("")]
|
[assembly: AssemblyProduct("")]
|
||||||
[assembly: AssemblyCopyright("sta")]
|
[assembly: AssemblyCopyright("sta.blockhead")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
@ -24,4 +24,3 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
//[assembly: AssemblyDelaySign(false)]
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
//[assembly: AssemblyKeyFile("")]
|
//[assembly: AssemblyKeyFile("")]
|
||||||
|
|
||||||
|
@ -4,10 +4,6 @@ namespace Example
|
|||||||
{
|
{
|
||||||
internal class NotificationMessage
|
internal class NotificationMessage
|
||||||
{
|
{
|
||||||
public NotificationMessage ()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public string Body {
|
public string Body {
|
||||||
get; set;
|
get; set;
|
||||||
}
|
}
|
||||||
@ -22,7 +18,7 @@ namespace Example
|
|||||||
|
|
||||||
public override string ToString ()
|
public override string ToString ()
|
||||||
{
|
{
|
||||||
return String.Format ("[{0}: {1}]", Summary, Body);
|
return String.Format ("{0}: {1}", Summary, Body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ namespace Example
|
|||||||
|
|
||||||
ws.OnMessage += (sender, e) =>
|
ws.OnMessage += (sender, e) =>
|
||||||
nf.Notify (
|
nf.Notify (
|
||||||
new NotificationMessage () {
|
new NotificationMessage {
|
||||||
Summary = "WebSocket Message",
|
Summary = "WebSocket Message",
|
||||||
Body = e.Data,
|
Body = e.Data,
|
||||||
Icon = "notification-message-im"
|
Icon = "notification-message-im"
|
||||||
@ -34,7 +34,7 @@ namespace Example
|
|||||||
|
|
||||||
ws.OnError += (sender, e) =>
|
ws.OnError += (sender, e) =>
|
||||||
nf.Notify (
|
nf.Notify (
|
||||||
new NotificationMessage () {
|
new NotificationMessage {
|
||||||
Summary = "WebSocket Error",
|
Summary = "WebSocket Error",
|
||||||
Body = e.Message,
|
Body = e.Message,
|
||||||
Icon = "notification-message-im"
|
Icon = "notification-message-im"
|
||||||
@ -42,7 +42,7 @@ namespace Example
|
|||||||
|
|
||||||
ws.OnClose += (sender, e) =>
|
ws.OnClose += (sender, e) =>
|
||||||
nf.Notify (
|
nf.Notify (
|
||||||
new NotificationMessage () {
|
new NotificationMessage {
|
||||||
Summary = String.Format ("WebSocket Close ({0})", e.Code),
|
Summary = String.Format ("WebSocket Close ({0})", e.Code),
|
||||||
Body = e.Reason,
|
Body = e.Reason,
|
||||||
Icon = "notification-message-im"
|
Icon = "notification-message-im"
|
||||||
@ -51,7 +51,6 @@ namespace Example
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
ws.Log.Level = LogLevel.Trace;
|
ws.Log.Level = LogLevel.Trace;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Per-message Compression
|
// Per-message Compression
|
||||||
//ws.Compression = CompressionMethod.Deflate;
|
//ws.Compression = CompressionMethod.Deflate;
|
||||||
|
|
||||||
@ -80,9 +79,8 @@ namespace Example
|
|||||||
Thread.Sleep (500);
|
Thread.Sleep (500);
|
||||||
Console.Write ("> ");
|
Console.Write ("> ");
|
||||||
var msg = Console.ReadLine ();
|
var msg = Console.ReadLine ();
|
||||||
if (msg == "exit") {
|
if (msg == "exit")
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
ws.Send (msg);
|
ws.Send (msg);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ using System.Runtime.CompilerServices;
|
|||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("")]
|
[assembly: AssemblyProduct("")]
|
||||||
[assembly: AssemblyCopyright("sta")]
|
[assembly: AssemblyCopyright("sta.blockhead")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
@ -24,4 +24,3 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
//[assembly: AssemblyDelaySign(false)]
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
//[assembly: AssemblyKeyFile("")]
|
//[assembly: AssemblyKeyFile("")]
|
||||||
|
|
||||||
|
@ -31,18 +31,18 @@ namespace Example1
|
|||||||
configure ();
|
configure ();
|
||||||
}
|
}
|
||||||
|
|
||||||
private AudioMessage acceptBinaryMessage (byte [] value)
|
private AudioMessage acceptBinaryMessage (byte [] data)
|
||||||
{
|
{
|
||||||
var id = value.SubArray (0, 4).To<uint> (ByteOrder.Big);
|
var id = data.SubArray (0, 4).To<uint> (ByteOrder.Big);
|
||||||
var chNum = value.SubArray (4, 1) [0];
|
var chNum = data.SubArray (4, 1) [0];
|
||||||
var bufferLength = value.SubArray (5, 4).To<uint> (ByteOrder.Big);
|
var bufferLength = data.SubArray (5, 4).To<uint> (ByteOrder.Big);
|
||||||
var bufferArray = new float [chNum, bufferLength];
|
var bufferArray = new float [chNum, bufferLength];
|
||||||
|
|
||||||
var offset = 9;
|
var offset = 9;
|
||||||
((int) chNum).Times (
|
((int) chNum).Times (
|
||||||
i => bufferLength.Times (
|
i => bufferLength.Times (
|
||||||
j => {
|
j => {
|
||||||
bufferArray [i, j] = value.SubArray (offset, 4).To<float> (ByteOrder.Big);
|
bufferArray [i, j] = data.SubArray (offset, 4).To<float> (ByteOrder.Big);
|
||||||
offset += 4;
|
offset += 4;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -54,17 +54,21 @@ namespace Example1
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private NotificationMessage acceptTextMessage (string value)
|
private NotificationMessage acceptTextMessage (string data)
|
||||||
{
|
{
|
||||||
var json = JObject.Parse (value);
|
var json = JObject.Parse (data);
|
||||||
var id = (uint) json ["user_id"];
|
var id = (uint) json ["user_id"];
|
||||||
var name = (string) json ["name"];
|
var name = (string) json ["name"];
|
||||||
var type = (string) json ["type"];
|
var type = (string) json ["type"];
|
||||||
|
|
||||||
string message;
|
string message;
|
||||||
if (type == "connection") {
|
if (type == "message")
|
||||||
|
message = String.Format ("{0}: {1}", name, (string) json ["message"]);
|
||||||
|
else if (type == "start_music")
|
||||||
|
message = String.Format ("{0}: Started playing music!", name);
|
||||||
|
else if (type == "connection") {
|
||||||
var users = (JArray) json ["message"];
|
var users = (JArray) json ["message"];
|
||||||
var msg = new StringBuilder ("Now keeping connection:");
|
var msg = new StringBuilder ("Now keeping connections:");
|
||||||
foreach (JToken user in users)
|
foreach (JToken user in users)
|
||||||
msg.AppendFormat (
|
msg.AppendFormat (
|
||||||
"\n- user_id: {0} name: {1}", (uint) user ["user_id"], (string) user ["name"]);
|
"\n- user_id: {0} name: {1}", (uint) user ["user_id"], (string) user ["name"]);
|
||||||
@ -72,19 +76,15 @@ namespace Example1
|
|||||||
message = msg.ToString ();
|
message = msg.ToString ();
|
||||||
}
|
}
|
||||||
else if (type == "connected") {
|
else if (type == "connected") {
|
||||||
_heartbeatTimer.Change (30000, 30000);
|
|
||||||
_id = id;
|
_id = id;
|
||||||
|
_heartbeatTimer.Change (30000, 30000);
|
||||||
message = String.Format ("user_id: {0} name: {1}", id, name);
|
message = String.Format ("user_id: {0} name: {1}", id, name);
|
||||||
}
|
}
|
||||||
else if (type == "message")
|
|
||||||
message = String.Format ("{0}: {1}", name, (string) json ["message"]);
|
|
||||||
else if (type == "start_music")
|
|
||||||
message = String.Format ("{0}: Started playing music!", name);
|
|
||||||
else
|
else
|
||||||
message = "Received unknown type message.";
|
message = "Received unknown type message.";
|
||||||
|
|
||||||
return new NotificationMessage {
|
return new NotificationMessage {
|
||||||
Summary = String.Format ("AudioStreamer Message ({0})", type),
|
Summary = String.Format ("AudioStreamer ({0})", type),
|
||||||
Body = message,
|
Body = message,
|
||||||
Icon = "notification-message-im"
|
Icon = "notification-message-im"
|
||||||
};
|
};
|
||||||
@ -120,7 +120,7 @@ namespace Example1
|
|||||||
_websocket.OnError += (sender, e) =>
|
_websocket.OnError += (sender, e) =>
|
||||||
_notifier.Notify (
|
_notifier.Notify (
|
||||||
new NotificationMessage {
|
new NotificationMessage {
|
||||||
Summary = "AudioStreamer Error",
|
Summary = "AudioStreamer (error)",
|
||||||
Body = e.Message,
|
Body = e.Message,
|
||||||
Icon = "notification-message-im"
|
Icon = "notification-message-im"
|
||||||
});
|
});
|
||||||
@ -128,8 +128,8 @@ namespace Example1
|
|||||||
_websocket.OnClose += (sender, e) =>
|
_websocket.OnClose += (sender, e) =>
|
||||||
_notifier.Notify (
|
_notifier.Notify (
|
||||||
new NotificationMessage {
|
new NotificationMessage {
|
||||||
Summary = String.Format ("AudioStreamer Disconnect ({0})", e.Code),
|
Summary = "AudioStreamer (disconnect)",
|
||||||
Body = e.Reason,
|
Body = String.Format ("code: {0} reason: {1}", e.Code, e.Reason),
|
||||||
Icon = "notification-message-im"
|
Icon = "notification-message-im"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -169,25 +169,19 @@ namespace Example1
|
|||||||
_websocket.Send (createTextMessage ("heartbeat", String.Empty));
|
_websocket.Send (createTextMessage ("heartbeat", String.Empty));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Connect ()
|
public void Connect (string username)
|
||||||
{
|
{
|
||||||
do {
|
_name = username;
|
||||||
Console.Write ("Input your name> ");
|
|
||||||
_name = Console.ReadLine ();
|
|
||||||
}
|
|
||||||
while (_name.Length == 0);
|
|
||||||
|
|
||||||
_websocket.Connect ();
|
_websocket.Connect ();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Disconnect ()
|
public void Disconnect ()
|
||||||
{
|
{
|
||||||
var wait = new ManualResetEvent (false);
|
_heartbeatTimer.Change (-1, -1);
|
||||||
_heartbeatTimer.Dispose (wait);
|
_websocket.Close (CloseStatusCode.Away);
|
||||||
wait.WaitOne ();
|
_audioBox.Clear ();
|
||||||
|
_id = null;
|
||||||
_websocket.Close ();
|
_name = null;
|
||||||
_notifier.Close ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write (string message)
|
public void Write (string message)
|
||||||
@ -198,6 +192,9 @@ namespace Example1
|
|||||||
void IDisposable.Dispose ()
|
void IDisposable.Dispose ()
|
||||||
{
|
{
|
||||||
Disconnect ();
|
Disconnect ();
|
||||||
|
|
||||||
|
_heartbeatTimer.Dispose ();
|
||||||
|
_notifier.Close ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,14 @@ namespace Example1
|
|||||||
using (var streamer = new AudioStreamer ("ws://agektmr.node-ninja.com:3000/socket"))
|
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://localhost:3000/socket"))
|
||||||
{
|
{
|
||||||
streamer.Connect ();
|
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");
|
Console.WriteLine ("\nType \"exit\" to exit.\n");
|
||||||
while (true) {
|
while (true) {
|
||||||
|
Loading…
Reference in New Issue
Block a user