Remove old polling stuff from RoomController. Added service comments. Do not start the event stream on startup unless you have credentials.
This commit is contained in:
parent
7ddb7a5cbb
commit
5ac87292c4
|
@ -46,7 +46,9 @@ angular.module('MatrixWebClientController', ['matrixService'])
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
eventStreamService.resume();
|
if (matrixService.config()) {
|
||||||
|
eventStreamService.resume();
|
||||||
|
}
|
||||||
|
|
||||||
// Logs the user out
|
// Logs the user out
|
||||||
$scope.logout = function() {
|
$scope.logout = function() {
|
||||||
|
|
|
@ -17,9 +17,10 @@ limitations under the License.
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This service manages where in the event stream the web client currently is and
|
This service manages where in the event stream the web client currently is,
|
||||||
provides methods to resume/pause/stop the event stream. This service is not
|
repolling the event stream, and provides methods to resume/pause/stop the event
|
||||||
responsible for parsing event data. For that, see the eventHandlerService.
|
stream. This service is not responsible for parsing event data. For that, see
|
||||||
|
the eventHandlerService.
|
||||||
*/
|
*/
|
||||||
angular.module('eventStreamService', [])
|
angular.module('eventStreamService', [])
|
||||||
.factory('eventStreamService', ['$q', '$timeout', 'matrixService', 'eventHandlerService', function($q, $timeout, matrixService, eventHandlerService) {
|
.factory('eventStreamService', ['$q', '$timeout', 'matrixService', 'eventHandlerService', function($q, $timeout, matrixService, eventHandlerService) {
|
||||||
|
@ -39,7 +40,7 @@ angular.module('eventStreamService', [])
|
||||||
// interrupts the stream. Only valid if there is a stream conneciton
|
// interrupts the stream. Only valid if there is a stream conneciton
|
||||||
// open.
|
// open.
|
||||||
var interrupt = function(shouldPoll) {
|
var interrupt = function(shouldPoll) {
|
||||||
console.log("p[EventStream] interrupt("+shouldPoll+") "+
|
console.log("[EventStream] interrupt("+shouldPoll+") "+
|
||||||
JSON.stringify(settings));
|
JSON.stringify(settings));
|
||||||
settings.shouldPoll = shouldPoll;
|
settings.shouldPoll = shouldPoll;
|
||||||
settings.isActive = false;
|
settings.isActive = false;
|
||||||
|
|
|
@ -16,6 +16,12 @@ limitations under the License.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/*
|
||||||
|
This service wraps up Matrix API calls.
|
||||||
|
|
||||||
|
This serves to isolate the caller from changes to the underlying url paths, as
|
||||||
|
well as attach common params (e.g. access_token) to requests.
|
||||||
|
*/
|
||||||
angular.module('matrixService', [])
|
angular.module('matrixService', [])
|
||||||
.factory('matrixService', ['$http', '$q', '$rootScope', function($http, $q, $rootScope) {
|
.factory('matrixService', ['$http', '$q', '$rootScope', function($http, $q, $rootScope) {
|
||||||
|
|
||||||
|
@ -36,10 +42,16 @@ angular.module('matrixService', [])
|
||||||
var MAPPING_PREFIX = "alias_for_";
|
var MAPPING_PREFIX = "alias_for_";
|
||||||
|
|
||||||
var doRequest = function(method, path, params, data) {
|
var doRequest = function(method, path, params, data) {
|
||||||
|
if (!config) {
|
||||||
|
console.warn("No config exists. Cannot perform request to "+path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Inject the access token
|
// Inject the access token
|
||||||
if (!params) {
|
if (!params) {
|
||||||
params = {};
|
params = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
params.access_token = config.access_token;
|
params.access_token = config.access_token;
|
||||||
|
|
||||||
return doBaseRequest(config.homeserver, method, path, params, data, undefined);
|
return doBaseRequest(config.homeserver, method, path, params, data, undefined);
|
||||||
|
|
|
@ -29,7 +29,6 @@ angular.module('RoomController', [])
|
||||||
stream_failure: undefined // the response when the stream fails
|
stream_failure: undefined // the response when the stream fails
|
||||||
};
|
};
|
||||||
$scope.members = {};
|
$scope.members = {};
|
||||||
$scope.stopPoll = false;
|
|
||||||
|
|
||||||
$scope.imageURLToSend = "";
|
$scope.imageURLToSend = "";
|
||||||
$scope.userIDToInvite = "";
|
$scope.userIDToInvite = "";
|
||||||
|
@ -71,40 +70,6 @@ angular.module('RoomController', [])
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
var shortPoll = function() {
|
|
||||||
eventStreamService.resume().then(
|
|
||||||
function(response) {
|
|
||||||
$scope.state.stream_failure = undefined;
|
|
||||||
console.log("Got response from "+$scope.state.events_from+" to "+response.data.end);
|
|
||||||
$scope.state.events_from = response.data.end;
|
|
||||||
$scope.feedback = "";
|
|
||||||
|
|
||||||
eventHandlerService.handleEvents(response.data.chunk, true);
|
|
||||||
|
|
||||||
if ($scope.stopPoll) {
|
|
||||||
console.log("Stopping polling.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$timeout(shortPoll, 0);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
function(error) {
|
|
||||||
$scope.state.stream_failure = error;
|
|
||||||
|
|
||||||
if (error.status == 403) {
|
|
||||||
$scope.stopPoll = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($scope.stopPoll) {
|
|
||||||
console.log("Stopping polling.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$timeout(shortPoll, 5000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
var updateMemberList = function(chunk) {
|
var updateMemberList = function(chunk) {
|
||||||
var isNewMember = !(chunk.target_user_id in $scope.members);
|
var isNewMember = !(chunk.target_user_id in $scope.members);
|
||||||
if (isNewMember) {
|
if (isNewMember) {
|
||||||
|
@ -260,9 +225,4 @@ angular.module('RoomController', [])
|
||||||
$scope.loadMoreHistory = function() {
|
$scope.loadMoreHistory = function() {
|
||||||
paginate(MESSAGES_PER_PAGINATION);
|
paginate(MESSAGES_PER_PAGINATION);
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.$on('$destroy', function(e) {
|
|
||||||
console.log("onDestroyed: Stopping poll.");
|
|
||||||
$scope.stopPoll = true;
|
|
||||||
});
|
|
||||||
}]);
|
}]);
|
||||||
|
|
Loading…
Reference in New Issue