private Subscription Subscribe(string target, string type)
{
Subscription s;
if (!this.subscriptions.ContainsKey(target))
{
s = new Subscription() {id = Guid.NewGuid().ToString(), target = target, type = type};
this.socket.Emit("subscribe", s.JSON());
this.subscriptions[s.id] = s;
this.socket.On(s.id, (dynamic d) =>
{
switch ((string) d.action)
{
case "subscribed":
Console.WriteLine("subscription : " + s.id);
break;
case "layer":
//var l = new LayerCallback();
var l = JsonConvert.DeserializeObject<LayerCallback>(d.data.ToString());
s.TriggerLayerCallback(l);
break;
}
});
}
else
{
s = this.subscriptions[target];
}
return s;
}