Heiko Seeberger, codecentric
case object GetFlows case class FlowDescriptor(name: String, label: String) case class AddFlow(label: String) case class FlowAdded(flowDescriptor: FlowDescriptor) case class FlowExists(label: String) case class RemoveFlow(name: String) case class FlowRemoved(name: String) case class FlowUnknown(name: String) case class GetMessages(flowName: String) case class AddMessage(flowName: String, text: String)
case object GetMessages case class Message(text: String, time: LocalDateTime) case class AddMessage(text: String) case class MessageAdded(flowName: String, message: Message)
<div ng-repeat="msg in messages | orderBy:'date':true">
<div>
<div class="date-time">{{msg.date}}</div>
<div class="text">{{msg.text}}</div>
</div>
</div>
reactiveFlowsControllers.controller('HomeCtrl', ['$scope', function($scope) {
$scope.flows = [
{name: 'akka', label: 'Akka'},
{name: 'angularjs', label: 'AngularJS'}
];
$scope.messages = [
{text: 'Akka rocks!', dateTime: '2015-04-14 19:20:21'}
];
}
Http(context.system)
.bindAndHandle(route(self), interface, port)
.pipeTo(self)
def route(httpService: ActorRef)(implicit ec: ExecutionContext) = {
import Directives._
def assets = getFromResourceDirectory("web") ~ path("")(getFromResource("web/index.html"))
def shutdown = path("") {
delete {
complete {
httpService ! Shutdown
"Shutting down now ..."
}
}
}
assets ~ shutdown
}
// SSE for messages
var messageSource = new EventSource('/message-events');
messageSource.addEventListener(
'added',
function(event) {
$scope.$apply(function() {
var messageAdded = JSON.parse(event.data);
if ($scope.currentFlowName == messageAdded.flowName)
$scope.messages.push(messageAdded.message);
});
},
false
);
def messageEvents = path("message-events") {
implicit val timeout = httpServiceTimeout
get {
complete {
(httpService ? CreateMessageEventSource)
.mapTo[Source[ServerSentEvent, Any]]
}
}
}
This work is licensed under a Creative Commons Attribution 4.0 International License and powered by reveal.js under its LICENSE.