Compare commits

...

1 Commits

Author SHA1 Message Date
Bettenbuk Zoltan
06af841a86 [RN] Connectivity hints 2019-04-18 14:42:51 +02:00
5 changed files with 117 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
// @flow
/**
* A Redux action type to signal that the app is about to navigate to a new location.
*
* NOTE: For exact {@code location} type see {@code parseURIString}.
*
* {
* location: Object
* type: APP_NAVIGATE
* }
*/
export const APP_NAVIGATE = 'APP_NAVIGATE';

View File

@@ -15,6 +15,7 @@ import { loadConfig } from '../base/lib-jitsi-meet';
import { parseURIString, toURLString } from '../base/util';
import { setFatalError } from '../overlay';
import { APP_NAVIGATE } from './actionTypes';
import { getDefaultURL } from './functions';
const logger = require('jitsi-meet-logger').getLogger(__filename);
@@ -55,6 +56,9 @@ export function appNavigate(uri: ?string) {
}
location.protocol || (location.protocol = 'https:');
dispatch(_navigate(location));
const { contextRoot, host, room } = location;
const locationURL = new URL(location.toString());
@@ -160,3 +164,19 @@ export function reloadWithStoredParams() {
}
};
}
/**
* Constructs a Redux action to signal that the app is about to navigate to a new location.
*
* @param {Object} location - The location we're about to navigate.
* @returns {{
* location: Object,
* type: APP_NAVIGATE
* }}
*/
function _navigate(location) {
return {
location,
type: APP_NAVIGATE
};
}

View File

@@ -1,6 +1,7 @@
// @flow
export * from './actions';
export * from './actionTypes';
export * from './components';
export * from './functions';

View File

@@ -0,0 +1,3 @@
// @flow
import './reducer';

View File

@@ -0,0 +1,80 @@
// @flow
import _ from 'lodash';
import { APP_NAVIGATE } from '../app';
import { ReducerRegistry } from '../base/redux';
const RETRY_TIMEOUT = 1 * 60 * 1000; // Mintes in millisecs
const DEFAULT_STATE = {
connectivityScore: {
conferenceStart: undefined,
score: undefined,
scoreValid: false
},
retryCounter: {
conferenceIdentifier: {
host: undefined,
lastJoin: undefined,
room: undefined
},
count: 0
}
};
/**
* Reduces the redux actions of the feature.
*/
ReducerRegistry.register('features/overlay', (state = DEFAULT_STATE, action) => {
switch (action.type) {
case APP_NAVIGATE:
return _registerNavigateAttempt(state, action.location);
}
return state;
});
/**
* Updates the retry counter based on the navigate action.
*
* @param {Object} state - The current state of the feature.
* @param {Object} location - The location we're navigating to.
* @returns {Object}
*/
function _registerNavigateAttempt(state, location) {
const { room } = location;
if (!room) {
// This is not a join attempt, we don't do anything.
return state;
}
const newState = _.defaultsDeep({}, state);
const { host } = location;
const { conferenceIdentifier } = state.retryCounter;
const {
host: previousHost,
lastJoin,
room: previousRoom
} = conferenceIdentifier;
const now = new Date().getTime();
newState.retryCounter.conferenceIdentifier = {
host,
lastJoin: now,
room
};
if (!previousRoom || previousRoom !== room || previousHost !== host || lastJoin + RETRY_TIMEOUT < now) {
// This is a join to a brand new room, or a non-repetitive join. We reset stuff.
// Count remains 0, as this is not a retry yet.
newState.retryCounter.count = 0;
} else if (previousRoom === room && previousHost === host && lastJoin + RETRY_TIMEOUT > now) {
// This is a repetitive re-join to the same room.
newState.retryCounter.count++;
}
return newState;
}