" + JSON.stringify(error) + "
").open();
console.error(_translations.PHQN4qwo || (_translations.PHQN4qwo = tr("Failed to initialize the opus codec. Error: %o")), error);
}
else {
console.debug(_translations.ysFQ3wS5 || (_translations.ysFQ3wS5 = tr("Failed to initialize already disabled codec. Error: %o")), error);
}
this._supported = false;
});
}
supported() { return this._supported; }
ownCodec(clientId, create = true) {
return new Promise((resolve, reject) => {
if (!this._supported) {
reject(_translations.yAAdD7jC || (_translations.yAAdD7jC = tr("unsupported codec!")));
return;
}
let freeSlot = 0;
for (let index = 0; index < this.entries.length; index++) {
if (this.entries[index].owner == clientId) {
this.entries[index].last_access = new Date().getTime();
if (this.entries[index].instance.initialized())
resolve(this.entries[index].instance);
else {
this.entries[index].instance.initialise().then((flag) => {
//TODO test success flag
this.ownCodec(clientId, false).then(resolve).catch(reject);
}).catch(error => {
console.error(_translations.tjJfo7Dk || (_translations.tjJfo7Dk = tr("Could not initialize codec!\nError: %o")), error);
reject(typeof (error) === 'string' ? error : _translations.E0WsEWiE || (_translations.E0WsEWiE = tr("Could not initialize codec!")));
});
}
return;
}
else if (freeSlot == 0 && this.entries[index].owner == 0) {
freeSlot = index;
}
}
if (!create) {
resolve(undefined);
return;
}
if (freeSlot == 0) {
freeSlot = this.entries.length;
let entry = new CodecPoolEntry();
entry.instance = audio.codec.new_instance(this.type);
entry.instance.on_encoded_data = buffer => this.handle.handleEncodedVoicePacket(buffer, this.codecIndex);
this.entries.push(entry);
}
this.entries[freeSlot].owner = clientId;
this.entries[freeSlot].last_access = new Date().getTime();
if (this.entries[freeSlot].instance.initialized())
this.entries[freeSlot].instance.reset();
else {
this.ownCodec(clientId, false).then(resolve).catch(reject);
return;
}
resolve(this.entries[freeSlot].instance);
});
}
releaseCodec(clientId) {
for (let index = 0; index < this.entries.length; index++)
if (this.entries[index].owner == clientId)
this.entries[index].owner = 0;
}
}
var VoiceConnectionType;
(function (VoiceConnectionType) {
VoiceConnectionType[VoiceConnectionType["JS_ENCODE"] = 0] = "JS_ENCODE";
VoiceConnectionType[VoiceConnectionType["NATIVE_ENCODE"] = 1] = "NATIVE_ENCODE";
})(VoiceConnectionType || (VoiceConnectionType = {}));
class VoiceConnection {
constructor(client) {
this._type = VoiceConnectionType.NATIVE_ENCODE;
this.codec_pool = [
new CodecPool(this, 0, _translations.YSTA_3JN || (_translations.YSTA_3JN = tr("Speex Narrowband")), CodecType.SPEEX_NARROWBAND),
new CodecPool(this, 1, _translations.nn0gTahg || (_translations.nn0gTahg = tr("Speex Wideband")), CodecType.SPEEX_WIDEBAND),
new CodecPool(this, 2, _translations.YzErO11B || (_translations.YzErO11B = tr("Speex Ultra Wideband")), CodecType.SPEEX_ULTRA_WIDEBAND),
new CodecPool(this, 3, _translations.JlimUN5_ || (_translations.JlimUN5_ = tr("CELT Mono")), CodecType.CELT_MONO),
new CodecPool(this, 4, _translations.INHTsvO8 || (_translations.INHTsvO8 = tr("Opus Voice")), CodecType.OPUS_VOICE),
new CodecPool(this, 5, _translations.SKGjM2fl || (_translations.SKGjM2fl = tr("Opus Music")), CodecType.OPUS_MUSIC)
];
this.vpacketId = 0;
this.chunkVPacketId = 0;
this.voice_send_queue = [];
this._ice_use_cache = true;
this._ice_cache = [];
this.client = client;
this._type = settings.static_global("voice_connection_type", this._type);
this.voiceRecorder = new VoiceRecorder(this);
this.voiceRecorder.on_end = this.handleVoiceEnded.bind(this);
this.voiceRecorder.on_start = this.handleVoiceStarted.bind(this);
this.voiceRecorder.reinitialiseVAD();
audio.player.on_ready(() => {
log.info(LogCategory.VOICE, _translations.gtVYEggq || (_translations.gtVYEggq = tr("Initializing voice handler after AudioController has been initialized!")));
if (native_client) {
this.codec_pool[0].initialize(2);
this.codec_pool[1].initialize(2);
this.codec_pool[2].initialize(2);
this.codec_pool[3].initialize(2);
}
this.codec_pool[4].initialize(2);
this.codec_pool[5].initialize(2);
if (this.type == VoiceConnectionType.NATIVE_ENCODE)
this.setup_native();
else
this.setup_js();
});
this.send_task = setInterval(this.sendNextVoicePacket.bind(this), 20);
}
native_encoding_supported() {
if (!(window.webkitAudioContext || window.AudioContext || { prototype: {} }).prototype.createMediaStreamDestination)
return false; //Required, but not available within edge
return true;
}
javascript_encoding_supported() {
if (!(window.RTCPeerConnection || { prototype: {} }).prototype.createDataChannel)
return false;
return true;
}
current_encoding_supported() {
switch (this._type) {
case VoiceConnectionType.JS_ENCODE:
return this.javascript_encoding_supported();
case VoiceConnectionType.NATIVE_ENCODE:
return this.native_encoding_supported();
}
return false;
}
setup_native() {
log.info(LogCategory.VOICE, _translations.mU7ZAmC6 || (_translations.mU7ZAmC6 = tr("Setting up native voice stream!")));
if (!this.native_encoding_supported()) {
log.warn(LogCategory.VOICE, _translations.F7kOnJnp || (_translations.F7kOnJnp = tr("Native codec isnt supported!")));
return;
}
this.voiceRecorder.on_data = undefined;
let stream = this.voiceRecorder.get_output_stream();
stream.disconnect();
if (!this.local_audio_stream)
this.local_audio_stream = audio.player.context().createMediaStreamDestination();
stream.connect(this.local_audio_stream);
}
setup_js() {
if (!this.javascript_encoding_supported())
return;
this.voiceRecorder.on_data = this.handleVoiceData.bind(this);
}
get type() { return this._type; }
set type(target) {
if (target == this.type)
return;
this._type = target;
if (this.type == VoiceConnectionType.NATIVE_ENCODE)
this.setup_native();
else
this.setup_js();
this.createSession();
}
codecSupported(type) {
return this.codec_pool.length > type && this.codec_pool[type].supported();
}
voice_playback_support() {
return this.dataChannel && this.dataChannel.readyState == "open";
}
voice_send_support() {
if (this.type == VoiceConnectionType.NATIVE_ENCODE)
return this.native_encoding_supported() && this.rtcPeerConnection.getLocalStreams().length > 0;
else
return this.voice_playback_support();
}
handleEncodedVoicePacket(data, codec) {
this.voice_send_queue.push({ data: data, codec: codec });
}
sendNextVoicePacket() {
let buffer = this.voice_send_queue.pop_front();
if (!buffer)
return;
this.sendVoicePacket(buffer.data, buffer.codec);
}
sendVoicePacket(data, codec) {
if (this.dataChannel) {
this.vpacketId++;
if (this.vpacketId > 65535)
this.vpacketId = 0;
let packet = new Uint8Array(data.byteLength + 2 + 3);
packet[0] = this.chunkVPacketId++ < 5 ? 1 : 0; //Flag header
packet[1] = 0; //Flag fragmented
packet[2] = (this.vpacketId >> 8) & 0xFF; //HIGHT (voiceID)
packet[3] = (this.vpacketId >> 0) & 0xFF; //LOW (voiceID)
packet[4] = codec; //Codec
packet.set(data, 5);
try {
this.dataChannel.send(packet);
}
catch (e) {
//TODO may handle error?
}
}
else {
console.warn(_translations.FBBcXTnB || (_translations.FBBcXTnB = tr("Could not transfer audio (not connected)")));
}
}
createSession() {
if (!audio.player.initialized()) {
console.log(_translations.QTx3nvcX || (_translations.QTx3nvcX = tr("Audio player isn't initialized yet. Waiting for gesture.")));
audio.player.on_ready(() => this.createSession());
return;
}
if (!this.current_encoding_supported())
return false;
if (this.rtcPeerConnection) {
this.dropSession();
}
this._ice_use_cache = true;
let config = {};
config.iceServers = [];
config.iceServers.push({ urls: 'stun:stun.l.google.com:19302' });
this.rtcPeerConnection = new RTCPeerConnection(config);
const dataChannelConfig = { ordered: true, maxRetransmits: 0 };
this.dataChannel = this.rtcPeerConnection.createDataChannel('main', dataChannelConfig);
this.dataChannel.onmessage = this.onDataChannelMessage.bind(this);
this.dataChannel.onopen = this.onDataChannelOpen.bind(this);
this.dataChannel.binaryType = "arraybuffer";
let sdpConstraints = {};
sdpConstraints.offerToReceiveAudio = this._type == VoiceConnectionType.NATIVE_ENCODE;
sdpConstraints.offerToReceiveVideo = false;
this.rtcPeerConnection.onicecandidate = this.onIceCandidate.bind(this);
if (this.local_audio_stream) { //May a typecheck?
this.rtcPeerConnection.addStream(this.local_audio_stream.stream);
console.log(_translations.z0mKdtjN || (_translations.z0mKdtjN = tr("Adding stream (%o)!")), this.local_audio_stream.stream);
}
this.rtcPeerConnection.createOffer(this.onOfferCreated.bind(this), () => {
console.error(_translations.DTf5g1uR || (_translations.DTf5g1uR = tr("Could not create ice offer!")));
}, sdpConstraints);
}
dropSession() {
if (this.dataChannel)
this.dataChannel.close();
if (this.rtcPeerConnection)
this.rtcPeerConnection.close();
//TODO here!
}
handleControlPacket(json) {
if (json["request"] === "answer") {
console.log(_translations.A1ka3yfu || (_translations.A1ka3yfu = tr("Set remote sdp! (%o)")), json["msg"]);
this.rtcPeerConnection.setRemoteDescription(new RTCSessionDescription(json["msg"])).catch(error => {
console.log(_translations.BNCVcnv7 || (_translations.BNCVcnv7 = tr("Failed to apply remote description: %o")), error); //FIXME error handling!
});
this._ice_use_cache = false;
for (let msg of this._ice_cache) {
this.rtcPeerConnection.addIceCandidate(new RTCIceCandidate(msg)).catch(error => {
console.log(_translations.B7EYIlQD || (_translations.B7EYIlQD = tr("Failed to add remote cached ice candidate %s: %o")), msg, error);
});
}
}
else if (json["request"] === "ice") {
if (!this._ice_use_cache) {
console.log(_translations.j7WFGiPM || (_translations.j7WFGiPM = tr("Add remote ice! (%s | %o)")), json["msg"], json);
this.rtcPeerConnection.addIceCandidate(new RTCIceCandidate(json["msg"])).catch(error => {
console.log(_translations.Y1UQmWiM || (_translations.Y1UQmWiM = tr("Failed to add remote ice candidate %s: %o")), json["msg"], error);
});
}
else {
console.log(_translations.XOmIStjD || (_translations.XOmIStjD = tr("Cache remote ice! (%s | %o)")), json["msg"], json);
this._ice_cache.push(json["msg"]);
}
}
else if (json["request"] == "status") {
if (json["state"] == "failed") {
chat.serverChat().appendError(_translations.ythe3GnZ || (_translations.ythe3GnZ = tr("Failed to setup voice bridge ({}). Allow reconnect: {}")), json["reason"], json["allow_reconnect"]);
log.error(LogCategory.NETWORKING, _translations._vnSXilG || (_translations._vnSXilG = tr("Failed to setup voice bridge (%s). Allow reconnect: %s")), json["reason"], json["allow_reconnect"]);
if (json["allow_reconnect"] == true) {
this.createSession();
}
//TODO handle fail specially when its not allowed to reconnect
}
}
}
//Listeners
onIceCandidate(event) {
console.log(_translations.sHVFQdqt || (_translations.sHVFQdqt = tr("Got ice candidate! Event:")));
console.log(event);
if (event) {
if (event.candidate)
this.client.serverConnection.sendData(JSON.stringify({
type: 'WebRTC',
request: "ice",
msg: event.candidate,
}));
else {
this.client.serverConnection.sendData(JSON.stringify({
type: 'WebRTC',
request: "ice_finish"
}));
}
}
}
onOfferCreated(localSession) {
console.log(_translations.R64I2bL6 || (_translations.R64I2bL6 = tr("Offer created and accepted")));
this.rtcPeerConnection.setLocalDescription(localSession).catch(error => {
console.log(_translations.rpGfb5bB || (_translations.rpGfb5bB = tr("Failed to apply local description: %o")), error);
//FIXME error handling
});
console.log(_translations.sUrbL8F8 || (_translations.sUrbL8F8 = tr("Send offer: %o")), localSession);
this.client.serverConnection.sendData(JSON.stringify({ type: 'WebRTC', request: "create", msg: localSession }));
}
onDataChannelOpen(channel) {
console.log(_translations.aCeDkOq4 || (_translations.aCeDkOq4 = tr("Got new data channel! (%s)")), this.dataChannel.readyState);
this.client.controlBar.updateVoice();
}
onDataChannelMessage(message) {
if (this.client.controlBar.muteOutput)
return;
let bin = new Uint8Array(message.data);
let clientId = bin[2] << 8 | bin[3];
let packetId = bin[0] << 8 | bin[1];
let codec = bin[4];
//console.log("Client id " + clientId + " PacketID " + packetId + " Codec: " + codec);
let client = this.client.channelTree.findClient(clientId);
if (!client) {
console.error(_translations.u9oEsZpv || (_translations.u9oEsZpv = tr("Having voice from unknown client? (ClientID: %o)")), clientId);
return;
}
let codecPool = this.codec_pool[codec];
if (!codecPool) {
console.error(_translations.sQ8Ba2oR || (_translations.sQ8Ba2oR = tr("Could not playback codec %o")), codec);
return;
}
let encodedData;
if (message.data.subarray)
encodedData = message.data.subarray(5);
else
encodedData = new Uint8Array(message.data, 5);
if (encodedData.length == 0) {
client.getAudioController().stopAudio();
codecPool.releaseCodec(clientId);
}
else {
codecPool.ownCodec(clientId)
.then(decoder => decoder.decodeSamples(client.getAudioController().codecCache(codec), encodedData))
.then(buffer => client.getAudioController().playBuffer(buffer)).catch(error => {
console.error(_translations.vH2yGkAk || (_translations.vH2yGkAk = tr("Could not playback client's (%o) audio (%o)")), clientId, error);
if (error instanceof Error)
console.error(error.stack);
});
}
}
current_channel_codec() {
return (this.client.getClient().currentChannel() || { properties: { channel_codec: 4 } }).properties.channel_codec;
}
handleVoiceData(data, head) {
if (!this.voiceRecorder)
return;
if (!this.client.connected)
return false;
if (this.client.controlBar.muteInput)
return;
if (head) {
this.chunkVPacketId = 0;
this.client.getClient().speaking = true;
}
//TODO Use channel codec!
const codec = this.current_channel_codec();
this.codec_pool[codec].ownCodec(this.client.getClientId())
.then(encoder => encoder.encodeSamples(this.client.getClient().getAudioController().codecCache(codec), data));
}
handleVoiceEnded() {
if (this.client && this.client.getClient())
this.client.getClient().speaking = false;
if (!this.voiceRecorder)
return;
if (!this.client.connected)
return;
console.log(_translations.S2lnS5ls || (_translations.S2lnS5ls = tr("Local voice ended")));
if (this.dataChannel)
this.sendVoicePacket(new Uint8Array(0), this.current_channel_codec()); //TODO Use channel codec!
}
handleVoiceStarted() {
console.log(_translations.PXSYJ5v0 || (_translations.PXSYJ5v0 = tr("Local voice started")));
if (this.client && this.client.getClient())
this.client.getClient().speaking = true;
}
}
typeof _translations !== "undefined" || (_translations = {});
_translations["declared"] = _translations["declared"] || (_translations["declared"] = {});
_translations["declared_files"] = _translations["declared_files"] || (_translations["declared_files"] = {});
unique_translation_check: {
if (_translations["declared_files"]["775ab808069a9c2be9cc5e58e0bd80887fbc8b52ca9b9db14075a1018288337a"] !== undefined) {
console.warn("This file has already been loaded!\nAre you executing scripts twice?");
break unique_translation_check;
}
else
_translations["declared_files"]["775ab808069a9c2be9cc5e58e0bd80887fbc8b52ca9b9db14075a1018288337a"] = "775ab808069a9c2be9cc5e58e0bd80887fbc8b52ca9b9db14075a1018288337a";
/*Auto generated helper for testing if the translation keys are unique*/
for (var { name: _i, path: _a } of []) {
if (_translations["declared"][_i] !== undefined)
throw "Translation with generated name \"" + _i + "\" already exists!\nIt has been already defined here: " + _translations["declared"][_i] + "\nAttempted to redefine here: " + _a + "\nRegenerate and/or fix your program!";
else
_translations["declared"][_i] = _a;
}
}
let context_menu;
$(document).bind("mousedown", function (e) {
let menu = context_menu || (context_menu = $(".context-menu"));
if (!menu.is(":visible"))
return;
if ($(e.target).parents(".context-menu").length == 0) {
despawn_context_menu();
}
});
let contextMenuCloseFn = undefined;
function despawn_context_menu() {
let menu = context_menu || (context_menu = $(".context-menu"));
if (!menu.is(":visible"))
return;
menu.hide(100);
if (contextMenuCloseFn)
contextMenuCloseFn();
}
var MenuEntryType;
(function (MenuEntryType) {
MenuEntryType[MenuEntryType["CLOSE"] = 0] = "CLOSE";
MenuEntryType[MenuEntryType["ENTRY"] = 1] = "ENTRY";
MenuEntryType[MenuEntryType["HR"] = 2] = "HR";
MenuEntryType[MenuEntryType["SUB_MENU"] = 3] = "SUB_MENU";
})(MenuEntryType || (MenuEntryType = {}));
class MenuEntry {
static HR() {
return {
callback: () => { },
type: MenuEntryType.HR,
name: "",
icon: ""
};
}
;
static CLOSE(callback) {
return {
callback: callback,
type: MenuEntryType.CLOSE,
name: "",
icon: ""
};
}
}
function generate_tag(entry) {
if (entry.type == MenuEntryType.HR) {
return $.spawn("hr");
}
else if (entry.type == MenuEntryType.ENTRY) {
console.log(entry.icon);
let icon = $.isFunction(entry.icon) ? entry.icon() : entry.icon;
if (typeof (icon) === "string") {
if (!icon || icon.length == 0)
icon = "icon_empty";
else
icon = "icon " + icon;
}
let tag = $.spawn("div").addClass("entry");
tag.append(typeof (icon) === "string" ? $.spawn("div").addClass(icon) : icon);
tag.append($.spawn("div").html($.isFunction(entry.name) ? entry.name() : entry.name));
if (entry.disabled || entry.invalidPermission)
tag.addClass("disabled");
else {
tag.click(function () {
if ($.isFunction(entry.callback))
entry.callback();
despawn_context_menu();
});
}
return tag;
}
else if (entry.type == MenuEntryType.SUB_MENU) {
let icon = $.isFunction(entry.icon) ? entry.icon() : entry.icon;
if (typeof (icon) === "string") {
if (!icon || icon.length == 0)
icon = "icon_empty";
else
icon = "icon " + icon;
}
let tag = $.spawn("div").addClass("entry").addClass("sub-container");
tag.append(typeof (icon) === "string" ? $.spawn("div").addClass(icon) : icon);
tag.append($.spawn("div").html($.isFunction(entry.name) ? entry.name() : entry.name));
tag.append($.spawn("div").addClass("arrow right"));
if (entry.disabled || entry.invalidPermission)
tag.addClass("disabled");
else {
let menu = $.spawn("div").addClass("sub-menu").addClass("context-menu");
for (let e of entry.sub_menu)
menu.append(generate_tag(e));
menu.appendTo(tag);
}
return tag;
}
return $.spawn("div").text("undefined");
}
function spawn_context_menu(x, y, ...entries) {
let menu = context_menu || (context_menu = $(".context-menu"));
menu.finish().empty();
contextMenuCloseFn = undefined;
for (let entry of entries) {
if (entry.type == MenuEntryType.CLOSE) {
contextMenuCloseFn = entry.callback;
}
else
menu.append(generate_tag(entry));
}
menu.show(100);
// In the right position (the mouse)
menu.css({
"top": y + "px",
"left": x + "px"
});
}
typeof _translations !== "undefined" || (_translations = {});
_translations["declared"] = _translations["declared"] || (_translations["declared"] = {});
_translations["declared_files"] = _translations["declared_files"] || (_translations["declared_files"] = {});
unique_translation_check: {
if (_translations["declared_files"]["51a461c33127132fca0884de56176443fbdb7d1b6404f440f36b4489afd06853"] !== undefined) {
console.warn("This file has already been loaded!\nAre you executing scripts twice?");
break unique_translation_check;
}
else
_translations["declared_files"]["51a461c33127132fca0884de56176443fbdb7d1b6404f440f36b4489afd06853"] = "51a461c33127132fca0884de56176443fbdb7d1b6404f440f36b4489afd06853";
/*Auto generated helper for testing if the translation keys are unique*/
for (var { name: _i, path: _a } of []) {
if (_translations["declared"][_i] !== undefined)
throw "Translation with generated name \"" + _i + "\" already exists!\nIt has been already defined here: " + _translations["declared"][_i] + "\nAttempted to redefine here: " + _a + "\nRegenerate and/or fix your program!";
else
_translations["declared"][_i] = _a;
}
}
var sha;
(function (sha) {
/*
* [js-sha1]{@link https://github.com/emn178/js-sha1}
*
* @version 0.6.0
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2017
* @license MIT
*/
/*jslint bitwise: true */
(function () {
'use strict';
let root = typeof window === 'object' ? window : {};
let NODE_JS = !root.JS_SHA1_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if (NODE_JS) {
root = global;
}
let COMMON_JS = !root.JS_SHA1_NO_COMMON_JS && typeof module === 'object' && module.exports;
let AMD = typeof define === 'function' && define.amd;
let HEX_CHARS = '0123456789abcdef'.split('');
let EXTRA = [-2147483648, 8388608, 32768, 128];
let SHIFT = [24, 16, 8, 0];
let OUTPUT_TYPES = ['hex', 'array', 'digest', 'arrayBuffer'];
let blocks = [];
let createOutputMethod = function (outputType) {
return function (message) {
return new Sha1(true).update(message)[outputType]();
};
};
let createMethod = function () {
let method = createOutputMethod('hex');
if (NODE_JS) {
method = nodeWrap(method);
}
method.create = function () {
return new Sha1();
};
method.update = function (message) {
return method.create().update(message);
};
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createOutputMethod(type);
}
return method;
};
var nodeWrap = function (method) {
var crypto = eval("require('crypto')");
var Buffer = eval("require('buffer').Buffer");
var nodeMethod = function (message) {
if (typeof message === 'string') {
return crypto.createHash('sha1').update(message, 'utf8').digest('hex');
}
else if (message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
}
else if (message.length === undefined) {
return method(message);
}
return crypto.createHash('sha1').update(new Buffer(message)).digest('hex');
};
return nodeMethod;
};
function Sha1(sharedMemory) {
if (sharedMemory) {
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
this.blocks = blocks;
}
else {
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
this.h0 = 0x67452301;
this.h1 = 0xEFCDAB89;
this.h2 = 0x98BADCFE;
this.h3 = 0x10325476;
this.h4 = 0xC3D2E1F0;
this.block = this.start = this.bytes = this.hBytes = 0;
this.finalized = this.hashed = false;
this.first = true;
}
Sha1.prototype.update = function (message) {
if (this.finalized) {
return;
}
var notString = typeof (message) !== 'string';
if (notString && message.constructor === root.ArrayBuffer) {
message = new Uint8Array(message);
}
var code, index = 0, i, length = message.length || 0, blocks = this.blocks;
while (index < length) {
if (this.hashed) {
this.hashed = false;
blocks[0] = this.block;
blocks[16] = blocks[1] = blocks[2] = blocks[3] =
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
if (notString) {
for (i = this.start; index < length && i < 64; ++index) {
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
}
}
else {
for (i = this.start; index < length && i < 64; ++index) {
code = message.charCodeAt(index);
if (code < 0x80) {
blocks[i >> 2] |= code << SHIFT[i++ & 3];
}
else if (code < 0x800) {
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
else if (code < 0xd800 || code >= 0xe000) {
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
else {
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
}
}
this.lastByteIndex = i;
this.bytes += i - this.start;
if (i >= 64) {
this.block = blocks[16];
this.start = i - 64;
this.hash();
this.hashed = true;
}
else {
this.start = i;
}
}
if (this.bytes > 4294967295) {
this.hBytes += this.bytes / 4294967296 << 0;
this.bytes = this.bytes % 4294967296;
}
return this;
};
Sha1.prototype.finalize = function () {
if (this.finalized) {
return;
}
this.finalized = true;
var blocks = this.blocks, i = this.lastByteIndex;
blocks[16] = this.block;
blocks[i >> 2] |= EXTRA[i & 3];
this.block = blocks[16];
if (i >= 56) {
if (!this.hashed) {
this.hash();
}
blocks[0] = this.block;
blocks[16] = blocks[1] = blocks[2] = blocks[3] =
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
blocks[14] = this.hBytes << 3 | this.bytes >>> 29;
blocks[15] = this.bytes << 3;
this.hash();
};
Sha1.prototype.hash = function () {
var a = this.h0, b = this.h1, c = this.h2, d = this.h3, e = this.h4;
var f, j, t, blocks = this.blocks;
for (j = 16; j < 80; ++j) {
t = blocks[j - 3] ^ blocks[j - 8] ^ blocks[j - 14] ^ blocks[j - 16];
blocks[j] = (t << 1) | (t >>> 31);
}
for (j = 0; j < 20; j += 5) {
f = (b & c) | ((~b) & d);
t = (a << 5) | (a >>> 27);
e = t + f + e + 1518500249 + blocks[j] << 0;
b = (b << 30) | (b >>> 2);
f = (a & b) | ((~a) & c);
t = (e << 5) | (e >>> 27);
d = t + f + d + 1518500249 + blocks[j + 1] << 0;
a = (a << 30) | (a >>> 2);
f = (e & a) | ((~e) & b);
t = (d << 5) | (d >>> 27);
c = t + f + c + 1518500249 + blocks[j + 2] << 0;
e = (e << 30) | (e >>> 2);
f = (d & e) | ((~d) & a);
t = (c << 5) | (c >>> 27);
b = t + f + b + 1518500249 + blocks[j + 3] << 0;
d = (d << 30) | (d >>> 2);
f = (c & d) | ((~c) & e);
t = (b << 5) | (b >>> 27);
a = t + f + a + 1518500249 + blocks[j + 4] << 0;
c = (c << 30) | (c >>> 2);
}
for (; j < 40; j += 5) {
f = b ^ c ^ d;
t = (a << 5) | (a >>> 27);
e = t + f + e + 1859775393 + blocks[j] << 0;
b = (b << 30) | (b >>> 2);
f = a ^ b ^ c;
t = (e << 5) | (e >>> 27);
d = t + f + d + 1859775393 + blocks[j + 1] << 0;
a = (a << 30) | (a >>> 2);
f = e ^ a ^ b;
t = (d << 5) | (d >>> 27);
c = t + f + c + 1859775393 + blocks[j + 2] << 0;
e = (e << 30) | (e >>> 2);
f = d ^ e ^ a;
t = (c << 5) | (c >>> 27);
b = t + f + b + 1859775393 + blocks[j + 3] << 0;
d = (d << 30) | (d >>> 2);
f = c ^ d ^ e;
t = (b << 5) | (b >>> 27);
a = t + f + a + 1859775393 + blocks[j + 4] << 0;
c = (c << 30) | (c >>> 2);
}
for (; j < 60; j += 5) {
f = (b & c) | (b & d) | (c & d);
t = (a << 5) | (a >>> 27);
e = t + f + e - 1894007588 + blocks[j] << 0;
b = (b << 30) | (b >>> 2);
f = (a & b) | (a & c) | (b & c);
t = (e << 5) | (e >>> 27);
d = t + f + d - 1894007588 + blocks[j + 1] << 0;
a = (a << 30) | (a >>> 2);
f = (e & a) | (e & b) | (a & b);
t = (d << 5) | (d >>> 27);
c = t + f + c - 1894007588 + blocks[j + 2] << 0;
e = (e << 30) | (e >>> 2);
f = (d & e) | (d & a) | (e & a);
t = (c << 5) | (c >>> 27);
b = t + f + b - 1894007588 + blocks[j + 3] << 0;
d = (d << 30) | (d >>> 2);
f = (c & d) | (c & e) | (d & e);
t = (b << 5) | (b >>> 27);
a = t + f + a - 1894007588 + blocks[j + 4] << 0;
c = (c << 30) | (c >>> 2);
}
for (; j < 80; j += 5) {
f = b ^ c ^ d;
t = (a << 5) | (a >>> 27);
e = t + f + e - 899497514 + blocks[j] << 0;
b = (b << 30) | (b >>> 2);
f = a ^ b ^ c;
t = (e << 5) | (e >>> 27);
d = t + f + d - 899497514 + blocks[j + 1] << 0;
a = (a << 30) | (a >>> 2);
f = e ^ a ^ b;
t = (d << 5) | (d >>> 27);
c = t + f + c - 899497514 + blocks[j + 2] << 0;
e = (e << 30) | (e >>> 2);
f = d ^ e ^ a;
t = (c << 5) | (c >>> 27);
b = t + f + b - 899497514 + blocks[j + 3] << 0;
d = (d << 30) | (d >>> 2);
f = c ^ d ^ e;
t = (b << 5) | (b >>> 27);
a = t + f + a - 899497514 + blocks[j + 4] << 0;
c = (c << 30) | (c >>> 2);
}
this.h0 = this.h0 + a << 0;
this.h1 = this.h1 + b << 0;
this.h2 = this.h2 + c << 0;
this.h3 = this.h3 + d << 0;
this.h4 = this.h4 + e << 0;
};
Sha1.prototype.hex = function () {
this.finalize();
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4;
return HEX_CHARS[(h0 >> 28) & 0x0F] + HEX_CHARS[(h0 >> 24) & 0x0F] +
HEX_CHARS[(h0 >> 20) & 0x0F] + HEX_CHARS[(h0 >> 16) & 0x0F] +
HEX_CHARS[(h0 >> 12) & 0x0F] + HEX_CHARS[(h0 >> 8) & 0x0F] +
HEX_CHARS[(h0 >> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
HEX_CHARS[(h1 >> 28) & 0x0F] + HEX_CHARS[(h1 >> 24) & 0x0F] +
HEX_CHARS[(h1 >> 20) & 0x0F] + HEX_CHARS[(h1 >> 16) & 0x0F] +
HEX_CHARS[(h1 >> 12) & 0x0F] + HEX_CHARS[(h1 >> 8) & 0x0F] +
HEX_CHARS[(h1 >> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
HEX_CHARS[(h2 >> 28) & 0x0F] + HEX_CHARS[(h2 >> 24) & 0x0F] +
HEX_CHARS[(h2 >> 20) & 0x0F] + HEX_CHARS[(h2 >> 16) & 0x0F] +
HEX_CHARS[(h2 >> 12) & 0x0F] + HEX_CHARS[(h2 >> 8) & 0x0F] +
HEX_CHARS[(h2 >> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
HEX_CHARS[(h3 >> 28) & 0x0F] + HEX_CHARS[(h3 >> 24) & 0x0F] +
HEX_CHARS[(h3 >> 20) & 0x0F] + HEX_CHARS[(h3 >> 16) & 0x0F] +
HEX_CHARS[(h3 >> 12) & 0x0F] + HEX_CHARS[(h3 >> 8) & 0x0F] +
HEX_CHARS[(h3 >> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
HEX_CHARS[(h4 >> 28) & 0x0F] + HEX_CHARS[(h4 >> 24) & 0x0F] +
HEX_CHARS[(h4 >> 20) & 0x0F] + HEX_CHARS[(h4 >> 16) & 0x0F] +
HEX_CHARS[(h4 >> 12) & 0x0F] + HEX_CHARS[(h4 >> 8) & 0x0F] +
HEX_CHARS[(h4 >> 4) & 0x0F] + HEX_CHARS[h4 & 0x0F];
};
Sha1.prototype.toString = Sha1.prototype.hex;
Sha1.prototype.digest = function () {
this.finalize();
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3, h4 = this.h4;
return [
(h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, h0 & 0xFF,
(h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, h1 & 0xFF,
(h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, h2 & 0xFF,
(h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, h3 & 0xFF,
(h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, h4 & 0xFF
];
};
Sha1.prototype.array = Sha1.prototype.digest;
Sha1.prototype.arrayBuffer = function () {
this.finalize();
var buffer = new ArrayBuffer(20);
var dataView = new DataView(buffer);
dataView.setUint32(0, this.h0);
dataView.setUint32(4, this.h1);
dataView.setUint32(8, this.h2);
dataView.setUint32(12, this.h3);
dataView.setUint32(16, this.h4);
return buffer;
};
var exports = createMethod();
if (COMMON_JS) {
module.exports = exports;
}
else {
root._sha1 = exports;
if (AMD) {
define(function () {
return exports;
});
}
}
})();
function encode_text(buffer) {
if (window.TextEncoder) {
return new TextEncoder().encode(buffer).buffer;
}
let utf8 = unescape(encodeURIComponent(buffer));
let result = new Uint8Array(utf8.length);
for (let i = 0; i < utf8.length; i++) {
result[i] = utf8.charCodeAt(i);
}
return result.buffer;
}
sha.encode_text = encode_text;
function sha1(message) {
if (!(typeof (message) === "string" || message instanceof ArrayBuffer))
throw "Invalid type!";
let buffer = message instanceof ArrayBuffer ? message : encode_text(message);
if (!crypto || !crypto.subtle || !crypto.subtle.digest || /Edge/.test(navigator.userAgent))
return new Promise(resolve => {
resolve(_sha1.arrayBuffer(buffer));
});
else
return crypto.subtle.digest("SHA-1", buffer);
}
sha.sha1 = sha1;
})(sha || (sha = {}));
typeof _translations !== "undefined" || (_translations = {});
_translations["declared"] = _translations["declared"] || (_translations["declared"] = {});
_translations["declared_files"] = _translations["declared_files"] || (_translations["declared_files"] = {});
unique_translation_check: {
if (_translations["declared_files"]["517d19bc00e3255e9af067c1436f53169327e8a5ef9fb42c1f675a97eda58851"] !== undefined) {
console.warn("This file has already been loaded!\nAre you executing scripts twice?");
break unique_translation_check;
}
else
_translations["declared_files"]["517d19bc00e3255e9af067c1436f53169327e8a5ef9fb42c1f675a97eda58851"] = "517d19bc00e3255e9af067c1436f53169327e8a5ef9fb42c1f675a97eda58851";
/*Auto generated helper for testing if the translation keys are unique*/
for (var { name: _i, path: _a } of []) {
if (_translations["declared"][_i] !== undefined)
throw "Translation with generated name \"" + _i + "\" already exists!\nIt has been already defined here: " + _translations["declared"][_i] + "\nAttempted to redefine here: " + _a + "\nRegenerate and/or fix your program!";
else
_translations["declared"][_i] = _a;
}
}
/// '; }, closeTag: function (params, content) { return ''; } }, "right": { openTag: function (params, content) { return ''; }, closeTag: function (params, content) { return ''; } }, "s": { openTag: function (params, content) { return ''; }, closeTag: function (params, content) { return ''; } }, "size": { openTag: function (params, content) { params = params || ''; var mySize = parseInt(params.substr(1), 10) || 0; if (mySize < 4 || mySize > 40) { mySize = 14; } return ''; }, closeTag: function (params, content) { return ''; } }, "small": { openTag: function (params, content) { params = params || ''; var colorCode = params.substr(1) || "inherit"; colorNamePattern.lastIndex = 0; colorCodePattern.lastIndex = 0; if (!colorNamePattern.test(colorCode)) { if (!colorCodePattern.test(colorCode)) { colorCode = "inherit"; } else { if (colorCode.substr(0, 1) !== "#") { colorCode = "#" + colorCode; } } } return ''; }, closeTag: function (params, content) { return ''; } }, "sub": { openTag: function (params, content) { return ''; }, closeTag: function (params, content) { return ''; } }, "sup": { openTag: function (params, content) { return ''; }, closeTag: function (params, content) { return ''; } }, "table": { openTag: function (params, content) { return '