/// <summary> /// Listen to messages on the specified route, and output instances of T using the scene serializer. /// </summary> /// <typeparam name="T">Type into which message contents should be deserialized.</typeparam> /// <param name="scene">The scene to listen to.</param> /// <param name="route">A string describing the route to listen to.</param> /// <returns>An observable instance providing the messages.</returns> public static IObservable <T> OnMessage <T>(this Scene scene, string route) { return(scene.OnMessage(route).Select(packet => { var value = packet.Serializer().Deserialize <T>(packet.Stream); return value; })); }
/// <summary> /// Listen to messages on the specified route, deserialize them and execute the given handler for eah of them. /// </summary> /// <typeparam name="TData"></typeparam> /// <param name="scene">The remote scene proxy on which the route messages will be listened.</param> /// <param name="route">The route to listen.</param> /// <param name="handler">The handler to execute for each message on the route.</param> /// <returns>An IDisposable object you can use to unregister the handler.</returns> public static IDisposable AddRoute <TData>(this Scene scene, string route, Action <TData> handler) { return(scene.OnMessage <TData>(route).Subscribe(handler)); }