Permit to remove callback

This commit is contained in:
Gregoire Parant 2020-10-26 14:13:51 +01:00
parent 850be63284
commit f95f38b092
3 changed files with 8 additions and 7 deletions

View File

@ -15,7 +15,7 @@ export class DiscussionManager {
private activeDiscussion: boolean = false;
private sendMessageCallBack : Set<SendMessageCallback> = new Set<SendMessageCallback>();
private sendMessageCallBack : Map<number|string, SendMessageCallback> = new Map<number|string, SendMessageCallback>();
constructor(name: string) {
this.mainContainer = HtmlUtils.getElementByIdOrFail<HTMLDivElement>('main-container');
@ -71,7 +71,7 @@ export class DiscussionManager {
if (event.key === 'Enter') {
event.preventDefault();
this.addMessage(name, inputMessage.value, true);
for(const callback of this.sendMessageCallBack) {
for(const callback of this.sendMessageCallBack.values()) {
callback(inputMessage.value);
}
inputMessage.value = "";
@ -160,10 +160,11 @@ export class DiscussionManager {
if(element){
element.remove();
}
this.sendMessageCallBack.delete(userId);
}
public onSendMessageCallback(callback: SendMessageCallback): void {
this.sendMessageCallBack.add(callback);
public onSendMessageCallback(userId: string|number, callback: SendMessageCallback): void {
this.sendMessageCallBack.set(userId, callback);
}
}

View File

@ -579,8 +579,8 @@ export class MediaManager {
this.discussionManager.addMessage(name, message, isMe)
}
public addSendMessageCallback(callback: SendMessageCallback){
this.discussionManager.onSendMessageCallback(callback)
public addSendMessageCallback(userId: string|number, callback: SendMessageCallback){
this.discussionManager.onSendMessageCallback(userId, callback)
}
}

View File

@ -147,7 +147,7 @@ export class SimplePeer {
const peer = new VideoPeer(user.userId, user.initiator ? user.initiator : false, this.Connection);
//permit to send message
mediaManager.addSendMessageCallback((message: string) => {
mediaManager.addSendMessageCallback(user.userId,(message: string) => {
peer.write(new Buffer(JSON.stringify({type: MESSAGE_TYPE_MESSAGE, name: name?.toUpperCase(), message: message})));
});