|
|
|
@ -40,7 +40,7 @@ namespace Example1
|
|
|
|
|
|
|
|
|
|
|
|
_websocket.OnMessage += (sender, e) => {
|
|
|
|
_websocket.OnMessage += (sender, e) => {
|
|
|
|
if (e.IsText) {
|
|
|
|
if (e.IsText) {
|
|
|
|
_notifier.Notify (convertToNotificationMessage (e.Data));
|
|
|
|
_notifier.Notify (processTextMessage (e.Data));
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -108,9 +108,43 @@ namespace Example1
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private NotificationMessage convertToNotificationMessage (string textMessage)
|
|
|
|
private byte[] createBinaryMessage (float[,] bufferArray)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var json = JObject.Parse (textMessage);
|
|
|
|
var msg = new List<byte> ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var id = (uint) _id;
|
|
|
|
|
|
|
|
var chNum = bufferArray.GetLength (0);
|
|
|
|
|
|
|
|
var buffLen = bufferArray.GetLength (1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
msg.AddRange (id.ToByteArray (ByteOrder.Big));
|
|
|
|
|
|
|
|
msg.Add ((byte) chNum);
|
|
|
|
|
|
|
|
msg.AddRange (((uint) buffLen).ToByteArray (ByteOrder.Big));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chNum.Times (
|
|
|
|
|
|
|
|
i =>
|
|
|
|
|
|
|
|
buffLen.Times (
|
|
|
|
|
|
|
|
j => msg.AddRange (bufferArray[i, j].ToByteArray (ByteOrder.Big))
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return msg.ToArray ();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string createTextMessage (string type, string message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return JsonConvert.SerializeObject (
|
|
|
|
|
|
|
|
new TextMessage {
|
|
|
|
|
|
|
|
user_id = _id,
|
|
|
|
|
|
|
|
name = _name,
|
|
|
|
|
|
|
|
type = type,
|
|
|
|
|
|
|
|
message = message
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private NotificationMessage processTextMessage (string data)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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"];
|
|
|
|
@ -136,6 +170,7 @@ namespace Example1
|
|
|
|
else if (type == "connected") {
|
|
|
|
else if (type == "connected") {
|
|
|
|
_id = id;
|
|
|
|
_id = id;
|
|
|
|
_timer.Change (30000, 30000);
|
|
|
|
_timer.Change (30000, 30000);
|
|
|
|
|
|
|
|
|
|
|
|
body = String.Format ("user_id: {0} name: {1}", id, name);
|
|
|
|
body = String.Format ("user_id: {0} name: {1}", id, name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
@ -149,40 +184,6 @@ namespace Example1
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private byte[] createBinaryMessage (float[,] bufferArray)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var msg = new List<byte> ();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var id = (uint) _id;
|
|
|
|
|
|
|
|
var chNum = bufferArray.GetLength (0);
|
|
|
|
|
|
|
|
var buffLen = bufferArray.GetLength (1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
msg.AddRange (id.ToByteArray (ByteOrder.Big));
|
|
|
|
|
|
|
|
msg.Add ((byte) chNum);
|
|
|
|
|
|
|
|
msg.AddRange (((uint) buffLen).ToByteArray (ByteOrder.Big));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
chNum.Times (
|
|
|
|
|
|
|
|
i =>
|
|
|
|
|
|
|
|
buffLen.Times (
|
|
|
|
|
|
|
|
j => msg.AddRange (bufferArray[i, j].ToByteArray (ByteOrder.Big))
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return msg.ToArray ();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string createTextMessage (string type, string message)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return JsonConvert.SerializeObject (
|
|
|
|
|
|
|
|
new TextMessage {
|
|
|
|
|
|
|
|
user_id = _id,
|
|
|
|
|
|
|
|
name = _name,
|
|
|
|
|
|
|
|
type = type,
|
|
|
|
|
|
|
|
message = message
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void sendHeartbeat (object state)
|
|
|
|
private void sendHeartbeat (object state)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_websocket.Send (createTextMessage ("heartbeat", String.Empty));
|
|
|
|
_websocket.Send (createTextMessage ("heartbeat", String.Empty));
|
|
|
|
|