Commit 235b8e0ecc0740b6d24c357e8a69401b2838d59c
1 parent
cefff57319
Exists in
master
and in
1 other branch
realtime is hard, let's just refresh the whole page
Showing 3 changed files with 32 additions and 8 deletions Side-by-side Diff
config.js
View file @
235b8e0
... | ... | @@ -15,14 +15,14 @@ |
15 | 15 | 'ngCookies']). |
16 | 16 | config(['$stateProvider', '$urlRouterProvider', '$httpProvider', |
17 | 17 | '$locationProvider', |
18 | - function ($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { | |
18 | + function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) { | |
19 | 19 | 'use strict'; |
20 | 20 | $httpProvider.defaults.withCredentials = true; |
21 | 21 | $httpProvider.defaults.xsrfCookieName = 'csrftoken'; |
22 | 22 | $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; |
23 | - $httpProvider.interceptors.push(function ($q) { | |
23 | + $httpProvider.interceptors.push(function($q) { | |
24 | 24 | return { |
25 | - 'responseError': function (rejection) { | |
25 | + 'responseError': function(rejection) { | |
26 | 26 | if (rejection.status >= 500) { |
27 | 27 | console.log('got error'); |
28 | 28 | console.log(rejection); |
... | ... | @@ -36,7 +36,7 @@ |
36 | 36 | $urlRouterProvider.otherwise('/login'); |
37 | 37 | var auth_resolve = { |
38 | 38 | authorize: ['$q', 'UserService', |
39 | - function ($q, UserService) { | |
39 | + function($q, UserService) { | |
40 | 40 | console.log('resolving user before continuing'); |
41 | 41 | return UserService.getUserData(); |
42 | 42 | } |
... | ... | @@ -115,8 +115,8 @@ |
115 | 115 | } |
116 | 116 | ]). |
117 | 117 | run(['$rootScope', '$state', '$stateParams', '$location', 'UserService', |
118 | - function ($rootScope, $state, $stateParams, $location, UserService) { | |
119 | - $rootScope.$on('$stateChangeStart', function (event, toState, toStateParams) { | |
118 | + function($rootScope, $state, $stateParams, $location, UserService) { | |
119 | + $rootScope.$on('$stateChangeStart', function(event, toState, toStateParams) { | |
120 | 120 | if (UserService.isLoggedIn()) return console.log('no login required; going straight to ' + toState.name); |
121 | 121 | if (toState.name == 'login') return console.log('we are going to login anyway; just let it happen :)'); |
122 | 122 | if (!UserService.isUserResolved()) return console.log('user not yet resolved; hold off'); |
... | ... | @@ -125,7 +125,7 @@ |
125 | 125 | console.log('going to ' + toState.name + ' after login'); |
126 | 126 | $state.go('login'); |
127 | 127 | }); |
128 | - $rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, error) { | |
128 | + $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { | |
129 | 129 | console.log('failed to change state: ' + error); |
130 | 130 | $state.go('login'); |
131 | 131 | }); |
scripts/ClassAddController.js
View file @
235b8e0
scripts/FeedController.js
View file @
235b8e0
... | ... | @@ -4,7 +4,29 @@ |
4 | 4 | console.log('Hello from feed'); |
5 | 5 | sectionId = $stateParams.sectionId; |
6 | 6 | $scope.cards = []; |
7 | + var loc = window.location, new_uri; | |
8 | + if (loc.protocol === 'https:') { | |
9 | + new_uri = 'wss:'; | |
10 | + } else { | |
11 | + new_uri = 'ws:'; | |
12 | + } | |
13 | + new_uri += '//' + loc.host; | |
14 | + var ws = new WebSocket(new_uri + '/ws/feed/' + sectionId + '?subscribe-broadcast'); | |
7 | 15 | |
16 | + ws.onopen = function() { | |
17 | + console.log('websocket connected'); | |
18 | + }; | |
19 | + ws.onmessage = function(e) { | |
20 | + console.log('got websocket message ' + e.data); | |
21 | + $scope.refreshCards(); | |
22 | + }; | |
23 | + ws.onerror = function(e) { | |
24 | + console.error(e); | |
25 | + }; | |
26 | + ws.onclose = function(e) { | |
27 | + console.log('connection closed'); | |
28 | + }; | |
29 | + | |
8 | 30 | $http.get('/api/sections/' + sectionId + '/feed/'). |
9 | 31 | success(function(data) { |
10 | 32 | console.log(data); |
... | ... | @@ -94,6 +116,7 @@ |
94 | 116 | }); |
95 | 117 | |
96 | 118 | $scope.$on('$destroy', function() { |
119 | + ws.close(); | |
97 | 120 | $(document).off('keydown'); |
98 | 121 | }); |
99 | 122 |