This commit is contained in:
Gregoire Parant 2020-09-23 18:44:24 +02:00
parent 3cb079c80c
commit 7584c3a04d
3 changed files with 18 additions and 12 deletions

View File

@ -35,7 +35,9 @@ export class ConsoleGlobalMessageManager {
initialise() { initialise() {
try { try {
HtmlUtils.removeElementByIdOrFail(CLASS_CONSOLE_MESSAGE); HtmlUtils.removeElementByIdOrFail(CLASS_CONSOLE_MESSAGE);
}catch (err){} }catch (err){
console.error(err);
}
const typeConsole = document.createElement('input'); const typeConsole = document.createElement('input');
typeConsole.id = INPUT_TYPE_CONSOLE; typeConsole.id = INPUT_TYPE_CONSOLE;
@ -169,11 +171,11 @@ export class ConsoleGlobalMessageManager {
const input = document.createElement('input'); const input = document.createElement('input');
input.type = 'file'; input.type = 'file';
input.id = UPLOAD_CONSOLE_MESSAGE input.id = UPLOAD_CONSOLE_MESSAGE
input.addEventListener('input', (e: any) => { input.addEventListener('input', (e: Event) => {
if(!e.target || !e.target.files || e.target.files.length === 0){ if(!e.target || !e.target.files || e.target.files.length === 0){
return; return;
} }
let file : File = e.target.files[0]; const file : File = e.target.files[0];
if(!file){ if(!file){
return; return;
@ -181,7 +183,9 @@ export class ConsoleGlobalMessageManager {
try { try {
HtmlUtils.removeElementByIdOrFail('audi-message-filename'); HtmlUtils.removeElementByIdOrFail('audi-message-filename');
}catch (e) {} }catch (err) {
console.error(err)
}
const p = document.createElement('p'); const p = document.createElement('p');
p.id = 'audi-message-filename'; p.id = 'audi-message-filename';
@ -223,12 +227,12 @@ export class ConsoleGlobalMessageManager {
} }
private sendTextMessage(){ private sendTextMessage(){
let elements = document.getElementsByClassName('ql-editor'); const elements = document.getElementsByClassName('ql-editor');
let quillEditor = elements.item(0); const quillEditor = elements.item(0);
if(!quillEditor){ if(!quillEditor){
throw "Error get quill node"; throw "Error get quill node";
} }
let GlobalMessage : GlobalMessageInterface = { const GlobalMessage : GlobalMessageInterface = {
id: 1, id: 1,
message: quillEditor.innerHTML, message: quillEditor.innerHTML,
type: MESSAGE_TYPE type: MESSAGE_TYPE
@ -246,9 +250,9 @@ export class ConsoleGlobalMessageManager {
const fd = new FormData(); const fd = new FormData();
fd.append('file', selectedFile); fd.append('file', selectedFile);
let res = await this.Connection.uploadAudio(fd); const res = await this.Connection.uploadAudio(fd);
let GlobalMessage : GlobalMessageInterface = { const GlobalMessage : GlobalMessageInterface = {
id: res.id, id: res.id,
message: res.path, message: res.path,
type: AUDIO_TYPE type: AUDIO_TYPE
@ -256,7 +260,9 @@ export class ConsoleGlobalMessageManager {
inputAudio.value = ''; inputAudio.value = '';
try { try {
HtmlUtils.removeElementByIdOrFail('audi-message-filename'); HtmlUtils.removeElementByIdOrFail('audi-message-filename');
}catch (e) {} }catch (err) {
console.error(err);
}
this.Connection.emitGlobalMessage(GlobalMessage); this.Connection.emitGlobalMessage(GlobalMessage);
} }

View File

@ -25,7 +25,7 @@ export class GlobalMessageManager {
} }
private playMessage(message : GlobalMessageInterface){ private playMessage(message : GlobalMessageInterface){
let previousMessage = document.getElementById(this.getHtmlMessageId(message.id)); const previousMessage = document.getElementById(this.getHtmlMessageId(message.id));
if(previousMessage){ if(previousMessage){
previousMessage.remove(); previousMessage.remove();
} }

View File

@ -200,7 +200,7 @@ export class Connection implements Connection {
} }
public uploadAudio(file : FormData){ public uploadAudio(file : FormData){
return Axios.post(`${API_URL}/upload-audio-message`, file).then((res: any) => { return Axios.post(`${API_URL}/upload-audio-message`, file).then((res: {data:{}}) => {
return res.data; return res.data;
}).catch((err) => { }).catch((err) => {
console.error(err); console.error(err);