File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11var statusController = angular . module ( 'StatusController' , [ ] ) ;
22
33function mainController ( $scope , $http ) {
4- $scope . status = "unknown" ;
54
6- var wsUrl = jsRoutes . controllers . Application . crawlerStatusWs ( ) . webSocketURL ( )
5+ $scope . status = "retrieving" ;
76
8- $scope . socket = new WebSocket ( wsUrl )
7+ function doWebSocket ( ) {
8+ var wsUrl = jsRoutes . controllers . Application . crawlerStatusWs ( ) . webSocketURL ( )
9+
10+ $scope . socket = new WebSocket ( wsUrl )
11+
12+ $scope . socket . onmessage = function ( msg ) {
13+ $scope . $apply ( function ( ) {
14+ console . log ( "received : #{msg}" ) ;
15+ $scope . status = msg . data ;
16+ } )
17+ }
18+ }
19+
20+ $http . get ( jsRoutes . controllers . Application . crawlerStatus ( ) . url )
21+ . success ( function ( data ) {
22+ $scope . status = data ;
23+ doWebSocket ( ) ;
24+ } )
25+ . error ( function ( data ) {
26+ doWebSocket ( ) ;
27+ } ) ;
28+ }
929
10- $scope . socket . onmessage = function ( msg ) {
11- $scope . $apply ( function ( ) {
12- console . log ( "received : #{msg}" ) ;
13- $scope . status = msg . data ;
14- } )
15- }
16- }
Original file line number Diff line number Diff line change @@ -27,7 +27,10 @@ object Application extends Controller {
2727 val stateResponse = crawlControlActor ? CrawlState
2828 stateResponse.map {
2929 case status : ControllerState =>
30- Ok (status.toString)
30+ val json = Map (" state" -> status.toString)
31+ val out : JsValue = Json .toJson(json)
32+
33+ Ok (out.toString)
3134 case _ =>
3235 InternalServerError (" Unknown Error" )
3336 } recover {
@@ -66,7 +69,8 @@ object Application extends Controller {
6669 implicit request =>
6770 Ok (
6871 Routes .javascriptRouter(" jsRoutes" )(
69- routes.javascript.Application .crawlerStatusWs
72+ routes.javascript.Application .crawlerStatusWs,
73+ routes.javascript.Application .crawlerStatus
7074 )
7175 ).as(" text/javascript" )
7276 }
You can’t perform that action at this time.
0 commit comments