playTrumpModule.controller('playTrump', ['$scope',
    '$rootScope',
    '$http',
    'showHttpError',
    function ($scope, $rootScope, $http, showHttpError) {
        $scope.showTargetedPlayerForTrumpSelector = false;
        var playTrumpUrl = '/rest/playTrump';
        var playTrumpMethod = 'GET';

        /**
         * Get the trump the player clicked on and display a pop-up to select the target player and
         * then play the trump or directly play the trump.
         *
         * @type @exp;$rootScope@call;$on
         */
        var unbind = $rootScope.$on('wantToPlayTrump', function (event, trump, players,
                currentPlayerIndex) {
            $scope.trumpName = trump.name;
            // We don't apply the trump on the current player.
            $scope.players = players.filter(function (player) {
                return player.index !== currentPlayerIndex;
            });
            if (trump.mustTargetPlayer) {
                selectTargetedPlayer();
            } else {
                play();
            }
        });
        $rootScope.$on('destroy', unbind);

        var selectTargetedPlayer = function () {
            $scope.showTargetedPlayerForTrumpSelector = true;
        };

        /**
         * Play the trump.
         * @returns {undefined}
         */
        var play = function () {
            $http({
                url: playTrumpUrl,
                method: playTrumpMethod,
                params: {
                    targetIndex: $scope.trumpTargetedPlayer,
                    name: $scope.trumpName
                }
            })
                    .success(function (data) {
                        updateScopeOnSuccessfulTrump(data);
                    })
                    .error(function (data) {
                        showHttpError.show(data);
                    });
        };

        $scope.submitSelectTargetedPlayerForm = function () {
            play();
        };

        $scope.cancelSelectTargetedPlayerForm = function () {
            $scope.trumpTargetedPlayer = undefined;
            hidde();
        };


        var hidde = function () {
            $scope.showTargetedPlayerForTrumpSelector = false;
        };

        var updateScopeOnSuccessfulTrump = function (data) {
            $rootScope.$emit('trumpPlayed', data);
            $scope.trumpTargetedPlayer = undefined;
            hidde();
        };
    }]);

@@ -75,16 +75,34 @@
 $http',%0A
+    '$websocket',%0A
     'sho
@@ -154,16 +154,28 @@
 , $http,
+ $websocket,
  showHtt
@@ -276,13 +276,85 @@
 = '/
-rest/
+api/playTrump';%0A        var playTrumpWs = $websocket('ws://localhost:8080' + 
 play
@@ -350,33 +350,36 @@
 080' + playTrump
-'
+Url)
 ;%0A        var pl
@@ -376,35 +376,138 @@
     
-var playTrumpMethod = 'GET'
+// TODO: handle errors.%0A        playTrumpWs.onMessage(function (data) %7B%0A            updateScopeOnSuccessfulTrump(data);%0A        %7D)
 ;%0A%0A 
@@ -1565,122 +1565,21 @@
     
-$http(%7B%0A                url: playTrumpUrl,%0A                method: playTrumpMethod,%0A                params: %7B%0A    
+var data = %7B%0A
     
@@ -1631,20 +1631,16 @@
 Player,%0A
-    
         
@@ -1686,275 +1686,44 @@
     
-    %7D%0A            %7D)%0A                    .success(function (data) %7B%0A                        updateScopeOnSuccessfulTrump(data);%0A                    %7D)%0A                    .error(function (data) %7B%0A                        showHttpError.show(data);%0A                    %7D
+%7D;%0A            playTrumpWs.send(data
 );%0A 

use websockets.