public static ProcessId Inbox(ProcessId hub, RelayMsg msg) { try { switch (msg.Tag) { case RelayMsg.MsgTag.Connected: SpawnConnection(msg, hub); break; case RelayMsg.MsgTag.Disconnected: kill(Self[msg.ConnectionId]); break; case RelayMsg.MsgTag.Inbound: case RelayMsg.MsgTag.Subscribe: case RelayMsg.MsgTag.Unsubscribe: fwd(SpawnConnection(msg, hub), msg); break; } } catch (Exception e) { tell(Errors, e); } return hub; }
public static ProcessId Inbox(ProcessId hub, RelayMsg msg) { try { switch (msg.Tag) { case RelayMsg.MsgTag.Connected: SpawnConnection(msg, hub); break; case RelayMsg.MsgTag.Disconnected: kill(Self[msg.ConnectionId]); break; case RelayMsg.MsgTag.Inbound: case RelayMsg.MsgTag.Subscribe: case RelayMsg.MsgTag.Unsubscribe: fwd(SpawnConnection(msg, hub), msg); break; } } catch (Exception e) { tell(Errors(hub.System), e); } return(hub); }
public static ProcessId ConnectionInbox(ProcessId hub, RelayMsg rmsg) { switch (rmsg.Tag) { case RelayMsg.MsgTag.Inbound: var inmsg = rmsg as InboundRelayMsg; if (rmsg.IsAsk) { // Ask not supported tell(Errors, "'ask' not supported from JS to server."); } else { tell(rmsg.To, inmsg.Message, rmsg.Sender.IsValid ? Self.Append(rmsg.Sender) : ProcessId.NoSender); } break; case RelayMsg.MsgTag.Outbound: fwd(hub, rmsg); break; case RelayMsg.MsgTag.Subscribe: var pid = rmsg.To; var subscriber = rmsg.Sender; var connectionId = rmsg.ConnectionId; ActorContext.SelfProcess.Actor.AddSubscription( rmsg.To, ActorContext.Observe<object>(pid).Subscribe(x => tell(hub, new OutboundRelayMsg( connectionId, new RemoteMessageDTO { MessageId = Guid.NewGuid(), Content = JsonConvert.SerializeObject(x), Sender = pid.Path, To = subscriber.Path, ContentType = x.GetType().AssemblyQualifiedName, ReplyTo = pid.Path, Tag = (int)Message.TagSpec.User, Type = (int)Message.Type.User }, subscriber, pid, false), pid))); break; case RelayMsg.MsgTag.Unsubscribe: ActorContext.SelfProcess.Actor.RemoveSubscription(rmsg.To); break; } return hub; }
public static ProcessId ConnectionInbox(ProcessId hub, RelayMsg rmsg) { switch (rmsg.Tag) { case RelayMsg.MsgTag.Inbound: var inmsg = rmsg as InboundRelayMsg; if (rmsg.IsAsk) { // Ask not supported tell(Errors(hub.System), "'ask' not supported from JS to server."); } else { tell(rmsg.To, inmsg.Message, rmsg.Sender.IsValid ? Self.Append(rmsg.Sender) : ProcessId.NoSender); } break; case RelayMsg.MsgTag.Outbound: fwd(hub, rmsg); break; case RelayMsg.MsgTag.Subscribe: var pid = rmsg.To; var subscriber = rmsg.Sender; var connectionId = rmsg.ConnectionId; ActorContext.Request.Self.Actor.AddSubscription( rmsg.To, ActorContext.System(pid).Observe <object>(pid).Subscribe(x => tell(hub, new OutboundRelayMsg( connectionId, new RemoteMessageDTO { MessageId = Guid.NewGuid(), Content = JsonConvert.SerializeObject(x), Sender = pid.ToString(), To = subscriber.ToString(), ContentType = x.GetType().AssemblyQualifiedName, ReplyTo = pid.ToString(), Tag = (int)Message.TagSpec.User, Type = (int)Message.Type.User }, subscriber, pid, false), pid))); break; case RelayMsg.MsgTag.Unsubscribe: ActorContext.Request.Self.Actor.RemoveSubscription(rmsg.To); break; } return(hub); }
private static ProcessId SpawnConnection(RelayMsg msg, ProcessId hub) => Children.ContainsKey(msg.ConnectionId) ? Self[msg.ConnectionId] : spawn<ProcessId, RelayMsg>(msg.ConnectionId, () => hub, ConnectionInbox);
private static ProcessId SpawnConnection(RelayMsg msg, ProcessId hub) => Children.ContainsKey(msg.ConnectionId) ? Self[msg.ConnectionId] : spawn <ProcessId, RelayMsg>(msg.ConnectionId, () => hub, ConnectionInbox);