2018-02-27 16:20:49 +00:00
|
|
|
/// <reference path="chat.ts" />
|
|
|
|
/// <reference path="client.ts" />
|
2018-04-11 15:56:09 +00:00
|
|
|
/// <reference path="Identity.ts" />
|
2018-02-27 16:20:49 +00:00
|
|
|
/// <reference path="utils/modal.ts" />
|
2018-03-07 18:06:52 +00:00
|
|
|
/// <reference path="ui/modal/ModalConnect.ts" />
|
2018-04-16 18:38:35 +00:00
|
|
|
/// <reference path="ui/modal/ModalCreateChannel.ts" />
|
2018-10-20 17:58:06 +00:00
|
|
|
/// <reference path="ui/modal/ModalBanCreate.ts" />
|
2018-04-30 21:57:21 +00:00
|
|
|
/// <reference path="ui/modal/ModalBanClient.ts" />
|
2018-06-20 17:06:55 +00:00
|
|
|
/// <reference path="ui/modal/ModalYesNo.ts" />
|
2018-10-20 17:58:06 +00:00
|
|
|
/// <reference path="ui/modal/ModalBanList.ts" />
|
2018-04-11 15:56:09 +00:00
|
|
|
/// <reference path="settings.ts" />
|
2018-04-16 18:38:35 +00:00
|
|
|
/// <reference path="log.ts" />
|
2018-02-27 16:20:49 +00:00
|
|
|
|
2018-04-16 18:38:35 +00:00
|
|
|
let settings: Settings;
|
2018-04-11 15:56:09 +00:00
|
|
|
let globalClient: TSClient;
|
|
|
|
let chat: ChatBox;
|
|
|
|
|
|
|
|
let forumIdentity: TeaForumIdentity;
|
2018-02-27 16:20:49 +00:00
|
|
|
|
2018-10-03 20:04:29 +00:00
|
|
|
const js_render = window.jsrender || $;
|
2018-10-06 13:13:45 +00:00
|
|
|
const native_client = window.require !== undefined;
|
|
|
|
|
2018-10-28 22:01:09 +00:00
|
|
|
function getUserMediaFunction() {
|
2018-12-23 21:56:04 +00:00
|
|
|
if((navigator as any).mediaDevices && (navigator as any).mediaDevices.getUserMedia)
|
|
|
|
return (settings, success, fail) => { (navigator as any).mediaDevices.getUserMedia(settings).then(success).catch(fail); };
|
|
|
|
return (navigator as any).getUserMedia || (navigator as any).webkitGetUserMedia || (navigator as any).mozGetUserMedia;
|
2018-10-28 22:01:09 +00:00
|
|
|
}
|
|
|
|
|
2018-10-06 13:13:45 +00:00
|
|
|
function setup_close() {
|
|
|
|
if(settings.static(Settings.KEY_DISABLE_UNLOAD_DIALOG, false)) return;
|
|
|
|
|
|
|
|
window.onbeforeunload = event => {
|
|
|
|
if(!globalClient.serverConnection || !globalClient.serverConnection.connected) return;
|
|
|
|
|
|
|
|
if(!native_client) {
|
|
|
|
event.returnValue = "Are you really sure?<br>You're still connected!";
|
|
|
|
} else {
|
|
|
|
event.preventDefault();
|
|
|
|
event.returnValue = "question";
|
|
|
|
|
|
|
|
const {remote} = require('electron');
|
|
|
|
const dialog = remote.dialog;
|
|
|
|
|
|
|
|
dialog.showMessageBox(remote.getCurrentWindow(), {
|
|
|
|
type: 'question',
|
|
|
|
buttons: ['Yes', 'No'],
|
|
|
|
title: 'Confirm',
|
|
|
|
message: 'Are you really sure?\nYou\'re still connected!'
|
|
|
|
}, choice => {
|
|
|
|
if(choice === 0) {
|
|
|
|
window.onbeforeunload = undefined;
|
|
|
|
remote.getCurrentWindow().close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2018-10-03 20:04:29 +00:00
|
|
|
|
2018-10-20 17:58:06 +00:00
|
|
|
declare function moment(...arguments) : any;
|
2018-10-14 11:27:48 +00:00
|
|
|
function setup_jsrender() : boolean {
|
2018-10-03 20:04:29 +00:00
|
|
|
if(!js_render) {
|
|
|
|
displayCriticalError("Missing jsrender extension!");
|
2018-10-14 11:27:48 +00:00
|
|
|
return false;
|
2018-10-03 20:04:29 +00:00
|
|
|
}
|
2018-10-07 16:21:28 +00:00
|
|
|
if(!js_render.views) {
|
|
|
|
displayCriticalError("Missing jsrender viewer extension!");
|
2018-10-14 11:27:48 +00:00
|
|
|
return false;
|
2018-10-07 16:21:28 +00:00
|
|
|
}
|
2018-10-03 20:04:29 +00:00
|
|
|
js_render.views.settings.allowCode(true);
|
|
|
|
js_render.views.tags("rnd", (argument) => {
|
2018-06-24 11:38:53 +00:00
|
|
|
let min = parseInt(argument.substr(0, argument.indexOf('~')));
|
|
|
|
let max = parseInt(argument.substr(argument.indexOf('~') + 1));
|
|
|
|
|
|
|
|
return (Math.round(Math.random() * (min + max + 1) - min)).toString();
|
|
|
|
});
|
2018-10-14 11:27:48 +00:00
|
|
|
|
2018-10-20 17:58:06 +00:00
|
|
|
js_render.views.tags("fmt_date", (...arguments) => {
|
|
|
|
return moment(arguments[0]).format(arguments[1]);
|
|
|
|
});
|
|
|
|
|
2018-12-08 22:13:33 +00:00
|
|
|
js_render.views.tags("tr", (...arguments) => {
|
|
|
|
return tr(arguments[0]);
|
|
|
|
});
|
|
|
|
|
2018-10-14 11:27:48 +00:00
|
|
|
$(".jsrender-template").each((idx, _entry) => {
|
|
|
|
if(!js_render.templates(_entry.id, _entry.innerHTML)) { //, _entry.innerHTML
|
|
|
|
console.error("Failed to cache template " + _entry.id + " for js render!");
|
|
|
|
} else
|
|
|
|
console.debug("Successfully loaded jsrender template " + _entry.id);
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-09 19:18:49 +00:00
|
|
|
async function initialize() {
|
2018-12-14 23:09:47 +00:00
|
|
|
const display_load_error = message => {
|
|
|
|
if(typeof(display_critical_load) !== "undefined")
|
|
|
|
display_critical_load(message);
|
|
|
|
else
|
|
|
|
displayCriticalError(message);
|
|
|
|
};
|
|
|
|
|
2018-12-15 12:06:41 +00:00
|
|
|
try {
|
|
|
|
await i18n.initialize();
|
|
|
|
} catch(error) {
|
|
|
|
console.error(tr("Failed to initialized the translation system!\nError: %o"), error);
|
|
|
|
displayCriticalError("Failed to setup the translation system");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-14 23:09:47 +00:00
|
|
|
try {
|
|
|
|
if(!setup_jsrender())
|
|
|
|
throw "invalid load";
|
|
|
|
} catch (error) {
|
|
|
|
display_load_error(tr("Failed to setup jsrender"));
|
|
|
|
console.error(tr("Failed to load jsrender! %o"), error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try { //Initialize main template
|
|
|
|
const main = $("#tmpl_main").renderTag();
|
|
|
|
$("body").append(main);
|
|
|
|
} catch(error) {
|
|
|
|
display_load_error(tr("Failed to setup main page!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-11 15:56:09 +00:00
|
|
|
AudioController.initializeAudioController();
|
2018-12-05 19:46:33 +00:00
|
|
|
if(!TSIdentityHelper.setup()) {
|
2018-12-09 19:18:49 +00:00
|
|
|
console.error(tr("Could not setup the TeamSpeak identity parser!"));
|
2018-12-05 19:46:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-04-11 15:56:09 +00:00
|
|
|
|
2018-12-09 19:18:49 +00:00
|
|
|
try {
|
|
|
|
await ppt.initialize();
|
|
|
|
} catch(error) {
|
|
|
|
console.error(tr("Failed to initialize ppt!\nError: %o"), error);
|
|
|
|
displayCriticalError(tr("Failed to initialize ppt!"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function main() {
|
|
|
|
//http://localhost:63343/Web-Client/index.php?_ijt=omcpmt8b9hnjlfguh8ajgrgolr&default_connect_url=true&default_connect_type=teamspeak&default_connect_url=localhost%3A9987&disableUnloadDialog=1&loader_ignore_age=1
|
|
|
|
|
2018-04-16 18:38:35 +00:00
|
|
|
settings = new Settings();
|
2018-03-24 22:38:01 +00:00
|
|
|
globalClient = new TSClient();
|
2018-04-11 15:56:09 +00:00
|
|
|
/** Setup the XF forum identity **/
|
2018-04-16 18:38:35 +00:00
|
|
|
if(settings.static("forum_user_data")) {
|
|
|
|
forumIdentity = new TeaForumIdentity(settings.static("forum_user_data"), settings.static("forum_user_sign"));
|
2018-04-11 15:56:09 +00:00
|
|
|
}
|
|
|
|
|
2018-03-24 22:38:01 +00:00
|
|
|
chat = new ChatBox($("#chat"));
|
|
|
|
globalClient.setup();
|
2018-03-10 08:03:29 +00:00
|
|
|
|
2018-04-16 18:38:35 +00:00
|
|
|
|
2018-10-06 13:13:45 +00:00
|
|
|
if(!settings.static(Settings.KEY_DISABLE_UNLOAD_DIALOG, false) && !native_client) {
|
|
|
|
|
2018-04-16 18:38:35 +00:00
|
|
|
}
|
2018-03-24 22:38:01 +00:00
|
|
|
//Modals.spawnConnectModal();
|
|
|
|
//Modals.spawnSettingsModal();
|
2018-04-16 18:38:35 +00:00
|
|
|
//Modals.createChannelModal(undefined);
|
2018-03-24 22:38:01 +00:00
|
|
|
|
2018-04-16 18:38:35 +00:00
|
|
|
if(settings.static("default_connect_url")) {
|
2018-05-05 12:58:30 +00:00
|
|
|
switch (settings.static("default_connect_type")) {
|
|
|
|
case "teaforo":
|
2018-12-03 17:56:36 +00:00
|
|
|
if(forumIdentity && forumIdentity.valid())
|
2018-05-05 12:58:30 +00:00
|
|
|
globalClient.startConnection(settings.static("default_connect_url"), forumIdentity);
|
|
|
|
else
|
2018-12-03 17:56:36 +00:00
|
|
|
Modals.spawnConnectModal({
|
|
|
|
url: settings.static<string>("default_connect_url"),
|
|
|
|
enforce: true
|
|
|
|
}, { identity: IdentitifyType.TEAFORO, enforce: true});
|
2018-05-05 12:58:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "teamspeak":
|
|
|
|
let connectIdentity = TSIdentityHelper.loadIdentity(settings.global("connect_identity_teamspeak_identity", ""));
|
2018-06-27 13:53:03 +00:00
|
|
|
if(!connectIdentity || !connectIdentity.valid())
|
2018-12-03 17:56:36 +00:00
|
|
|
Modals.spawnConnectModal({
|
|
|
|
url: settings.static<string>("default_connect_url"),
|
|
|
|
enforce: true
|
|
|
|
}, { identity: IdentitifyType.TEAMSPEAK, enforce: true});
|
2018-05-05 12:58:30 +00:00
|
|
|
else
|
|
|
|
globalClient.startConnection(settings.static("default_connect_url"), connectIdentity);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-12-03 17:56:36 +00:00
|
|
|
Modals.spawnConnectModal({
|
|
|
|
url: settings.static<string>("default_connect_url"),
|
|
|
|
enforce: true
|
|
|
|
});
|
2018-05-05 12:58:30 +00:00
|
|
|
}
|
2018-04-16 18:38:35 +00:00
|
|
|
}
|
2018-04-30 21:57:21 +00:00
|
|
|
|
|
|
|
/*
|
2018-06-24 11:38:53 +00:00
|
|
|
let tag = $("#tmpl_music_frame").renderTag({
|
|
|
|
//thumbnail: "img/loading_image.svg"
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$("#music-test").replaceWith(tag);
|
2018-04-30 21:57:21 +00:00
|
|
|
|
2018-10-28 17:25:43 +00:00
|
|
|
Modals.spawnSettingsModal();
|
2018-06-20 17:06:55 +00:00
|
|
|
/*
|
|
|
|
Modals.spawnYesNo("Are your sure?", "Do you really want to exit?", flag => {
|
|
|
|
console.log("Response: " + flag);
|
|
|
|
})
|
|
|
|
*/
|
2018-09-30 19:50:59 +00:00
|
|
|
|
2018-10-06 13:13:45 +00:00
|
|
|
setup_close();
|
2018-11-03 23:39:29 +00:00
|
|
|
|
|
|
|
let _resize_timeout: NodeJS.Timer;
|
2018-10-06 13:13:45 +00:00
|
|
|
$(window).on('resize', () => {
|
2018-11-03 23:39:29 +00:00
|
|
|
if(_resize_timeout)
|
|
|
|
clearTimeout(_resize_timeout);
|
|
|
|
_resize_timeout = setTimeout(() => {
|
|
|
|
globalClient.channelTree.handle_resized();
|
|
|
|
}, 1000);
|
2018-10-06 13:13:45 +00:00
|
|
|
});
|
2018-04-19 16:42:34 +00:00
|
|
|
}
|
|
|
|
|
2018-12-09 19:18:49 +00:00
|
|
|
app.loadedListener.push(async () => {
|
2018-09-25 15:39:38 +00:00
|
|
|
try {
|
2018-12-09 19:18:49 +00:00
|
|
|
await initialize();
|
2018-09-25 15:39:38 +00:00
|
|
|
main();
|
2018-10-28 17:25:43 +00:00
|
|
|
if(!audio.player.initialized()) {
|
2018-12-05 19:46:33 +00:00
|
|
|
log.info(LogCategory.VOICE, tr("Initialize audio controller later!"));
|
2018-10-28 17:25:43 +00:00
|
|
|
if(!audio.player.initializeFromGesture) {
|
2018-12-05 19:46:33 +00:00
|
|
|
console.error(tr("Missing audio.player.initializeFromGesture"));
|
2018-10-28 17:25:43 +00:00
|
|
|
} else
|
|
|
|
$(document).one('click', event => audio.player.initializeFromGesture());
|
2018-09-25 15:39:38 +00:00
|
|
|
}
|
|
|
|
} catch (ex) {
|
2018-10-28 17:25:43 +00:00
|
|
|
console.error(ex.stack);
|
2018-10-20 17:58:06 +00:00
|
|
|
if(ex instanceof ReferenceError || ex instanceof TypeError)
|
2018-10-28 17:25:43 +00:00
|
|
|
ex = ex.name + ": " + ex.message;
|
2018-10-04 20:49:20 +00:00
|
|
|
displayCriticalError("Failed to invoke main function:<br>" + ex);
|
2018-09-25 15:39:38 +00:00
|
|
|
}
|
2018-10-06 13:13:45 +00:00
|
|
|
});
|