Initialise global message
- Create new class to manager global message. My idea is that this class permit to manage audio or text message. - Update html to have main content id and inject html in this. - Create front event to receive startMessage and stopMessage. - Delete impoted variable not used.
This commit is contained in:
parent
1ccbea30e4
commit
509196785b
9 changed files with 88 additions and 8 deletions
43
front/src/WebRtc/GlobalMessageManager.ts
Normal file
43
front/src/WebRtc/GlobalMessageManager.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import {HtmlUtils} from "./HtmlUtils";
|
||||
import {Connection, GlobalMessageInterface} from "../Connection";
|
||||
|
||||
export class GlobalMessageManager {
|
||||
|
||||
private Connection: Connection;
|
||||
|
||||
constructor(Connection: Connection) {
|
||||
this.Connection = Connection;
|
||||
this.initialise();
|
||||
}
|
||||
|
||||
initialise(){
|
||||
//receive signal to show message
|
||||
this.Connection.receivePlayGlobalMessage((message: GlobalMessageInterface) => {
|
||||
this.playMessage(message.id, message.message);
|
||||
});
|
||||
|
||||
//receive signal to close message
|
||||
this.Connection.receiveStopGlobalMessage((message: GlobalMessageInterface) => {
|
||||
this.stopMessage(message.id);
|
||||
});
|
||||
}
|
||||
|
||||
playMessage(messageId : number, htmlMessage: string){
|
||||
const div = document.createElement('div');
|
||||
div.innerHTML = htmlMessage;
|
||||
div.id = this.getHtmlMessageId(messageId);
|
||||
div.className = "message-container";
|
||||
|
||||
const mainSectionDiv = HtmlUtils.getElementByIdOrFail<HTMLDivElement>('main-container');
|
||||
mainSectionDiv.appendChild(div);
|
||||
}
|
||||
|
||||
stopMessage(messageId: number){
|
||||
HtmlUtils.removeElementByIdOrFail<HTMLDivElement>(this.getHtmlMessageId(messageId));
|
||||
}
|
||||
|
||||
private getHtmlMessageId(messageId: number){
|
||||
return `message-${messageId}`;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,4 +7,14 @@ export class HtmlUtils {
|
|||
// FIXME: does not check the type of the returned type
|
||||
return elem as T;
|
||||
}
|
||||
|
||||
public static removeElementByIdOrFail<T extends HTMLElement>(id: string): T {
|
||||
const elem = document.getElementById(id);
|
||||
if (elem === null) {
|
||||
throw new Error("Cannot find HTML element with id '"+id+"'");
|
||||
}
|
||||
// FIXME: does not check the type of the returned type
|
||||
elem.remove();
|
||||
return elem as T;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,10 +10,8 @@ import {
|
|||
StopScreenSharingCallback,
|
||||
UpdatedLocalStreamCallback
|
||||
} from "./MediaManager";
|
||||
import * as SimplePeerNamespace from "simple-peer";
|
||||
import {ScreenSharingPeer} from "./ScreenSharingPeer";
|
||||
import {VideoPeer} from "./VideoPeer";
|
||||
const Peer: SimplePeerNamespace.SimplePeer = require('simple-peer');
|
||||
|
||||
export interface UserSimplePeerInterface{
|
||||
userId: string;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue