Merge pull request #667 from jitsi/history_fix

Fixes unhandled error from history.pushState
This commit is contained in:
Emil Ivov 2016-06-01 17:53:41 -05:00
commit 6c1349c501
1 changed files with 26 additions and 3 deletions

29
app.js
View File

@ -24,6 +24,24 @@ import API from './modules/API/API';
import UIEvents from './service/UI/UIEvents';
/**
* Tries to push history state with the following parameters:
* 'VideoChat', `Room: ${roomName}`, URL. If fail, prints the error and returns
* it.
*/
function pushHistoryState(roomName, URL) {
try {
window.history.pushState(
'VideoChat', `Room: ${roomName}`, URL
);
} catch (e) {
console.warn("Push history state failed with parameters:",
'VideoChat', `Room: ${roomName}`, URL, e);
return e;
}
return null;
}
/**
* Builds and returns the room name.
*/
@ -33,9 +51,14 @@ function buildRoomName () {
if(!roomName) {
let word = RoomnameGenerator.generateRoomWithoutSeparator();
roomName = word.toLowerCase();
window.history.pushState(
'VideoChat', `Room: ${word}`, window.location.pathname + word
);
let historyURL = window.location.pathname + word;
//Trying to push state with URL "/" + roomName
var err = pushHistoryState(word, historyURL);
//If URL "/" + roomName is not good, trying with explicitly adding the
//domain name.
if(err && config.hosts.domain) {
pushHistoryState(word, "//" + config.hosts.domain + historyURL);
}
}
return roomName;