mirror of
https://github.com/deavmi/nostril
synced 2024-09-20 07:22:59 +02:00
Tristan B. Velloza Kildaire
f66227da11
Connection - Added `handler(string)` method to the object - Added a stub worker function for the thread - Made `Connection` a `Thread` - Added logging to module
59 lines
1.1 KiB
D
59 lines
1.1 KiB
D
module nostril.connection;
|
|
|
|
import gogga;
|
|
|
|
// TODO: Investigate if we need the belowe (I copied it from Birchwood)
|
|
__gshared GoggaLogger logger;
|
|
__gshared static this()
|
|
{
|
|
logger = new GoggaLogger();
|
|
}
|
|
|
|
|
|
import vibe.vibe : WebSocket;
|
|
import core.thread : Thread;
|
|
import std.json;
|
|
|
|
public class Connection : Thread
|
|
{
|
|
/* Client socket */
|
|
private WebSocket ws;
|
|
|
|
this(WebSocket ws)
|
|
{
|
|
super(&worker);
|
|
this.ws = ws;
|
|
}
|
|
|
|
private void worker()
|
|
{
|
|
// TODO: Add this
|
|
}
|
|
|
|
/**
|
|
* Handles received data
|
|
*
|
|
* Params:
|
|
* text = received data
|
|
*/
|
|
private void handler(string text)
|
|
{
|
|
string receivedText = text;
|
|
logger.print(receivedText~"\n", DebugType.INFO);
|
|
|
|
|
|
JSONValue jsonReceived;
|
|
try
|
|
{
|
|
jsonReceived = parseJSON(receivedText);
|
|
logger.print(jsonReceived.toPrettyString()~"\n", DebugType.INFO);
|
|
|
|
// TODO: Add handling here
|
|
|
|
}
|
|
catch(JSONException e)
|
|
{
|
|
logger.print("There was an error parsing the client's JSON\n", DebugType.ERROR);
|
|
}
|
|
}
|
|
} |