Merge pull request #1732 from thecodingmachine/remove-last-message
Remove the last message before adding a new chat peer
This commit is contained in:
commit
0409422a44
@ -2,11 +2,13 @@ import { writable } from "svelte/store";
|
|||||||
import { playersStore } from "./PlayersStore";
|
import { playersStore } from "./PlayersStore";
|
||||||
import type { PlayerInterface } from "../Phaser/Game/PlayerInterface";
|
import type { PlayerInterface } from "../Phaser/Game/PlayerInterface";
|
||||||
import { iframeListener } from "../Api/IframeListener";
|
import { iframeListener } from "../Api/IframeListener";
|
||||||
|
import { Subject } from "rxjs";
|
||||||
|
|
||||||
export const chatVisibilityStore = writable(false);
|
export const chatVisibilityStore = writable(false);
|
||||||
export const chatInputFocusStore = writable(false);
|
export const chatInputFocusStore = writable(false);
|
||||||
|
|
||||||
export const newChatMessageStore = writable<string | null>(null);
|
const _newChatMessageSubject = new Subject<string>();
|
||||||
|
export const newChatMessageSubject = _newChatMessageSubject.asObservable();
|
||||||
|
|
||||||
export enum ChatMessageTypes {
|
export enum ChatMessageTypes {
|
||||||
text = 1,
|
text = 1,
|
||||||
@ -67,10 +69,9 @@ function createChatMessagesStore() {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
addPersonnalMessage(text: string) {
|
addPersonnalMessage(text: string) {
|
||||||
//post message iframe listener
|
|
||||||
iframeListener.sendUserInputChat(text);
|
iframeListener.sendUserInputChat(text);
|
||||||
|
|
||||||
newChatMessageStore.set(text);
|
_newChatMessageSubject.next(text);
|
||||||
update((list) => {
|
update((list) => {
|
||||||
const lastMessage = list[list.length - 1];
|
const lastMessage = list[list.length - 1];
|
||||||
if (lastMessage && lastMessage.type === ChatMessageTypes.me && lastMessage.text) {
|
if (lastMessage && lastMessage.type === ChatMessageTypes.me && lastMessage.text) {
|
||||||
@ -83,7 +84,6 @@ function createChatMessagesStore() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
iframeListener.sendUserInputChat(text);
|
|
||||||
return list;
|
return list;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -7,7 +7,7 @@ import type { UserSimplePeerInterface } from "./SimplePeer";
|
|||||||
import { readable, Readable, Unsubscriber } from "svelte/store";
|
import { readable, Readable, Unsubscriber } from "svelte/store";
|
||||||
import { localStreamStore, obtainedMediaConstraintStore, ObtainedMediaStreamConstraints } from "../Stores/MediaStore";
|
import { localStreamStore, obtainedMediaConstraintStore, ObtainedMediaStreamConstraints } from "../Stores/MediaStore";
|
||||||
import { playersStore } from "../Stores/PlayersStore";
|
import { playersStore } from "../Stores/PlayersStore";
|
||||||
import { chatMessagesStore, newChatMessageStore } from "../Stores/ChatStore";
|
import { chatMessagesStore, newChatMessageSubject } from "../Stores/ChatStore";
|
||||||
import { getIceServersConfig } from "../Components/Video/utils";
|
import { getIceServersConfig } from "../Components/Video/utils";
|
||||||
import { isMobile } from "../Enum/EnvironmentVariable";
|
import { isMobile } from "../Enum/EnvironmentVariable";
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ export class VideoPeer extends Peer {
|
|||||||
public readonly streamStore: Readable<MediaStream | null>;
|
public readonly streamStore: Readable<MediaStream | null>;
|
||||||
public readonly statusStore: Readable<PeerStatus>;
|
public readonly statusStore: Readable<PeerStatus>;
|
||||||
public readonly constraintsStore: Readable<ObtainedMediaStreamConstraints | null>;
|
public readonly constraintsStore: Readable<ObtainedMediaStreamConstraints | null>;
|
||||||
private newMessageunsubscriber: Unsubscriber | null = null;
|
private newMessageSubscribtion: Subscription | undefined;
|
||||||
private closing: Boolean = false; //this is used to prevent destroy() from being called twice
|
private closing: Boolean = false; //this is used to prevent destroy() from being called twice
|
||||||
private localStreamStoreSubscribe: Unsubscriber;
|
private localStreamStoreSubscribe: Unsubscriber;
|
||||||
private obtainedMediaConstraintStoreSubscribe: Unsubscriber;
|
private obtainedMediaConstraintStoreSubscribe: Unsubscriber;
|
||||||
@ -129,7 +129,7 @@ export class VideoPeer extends Peer {
|
|||||||
this._connected = true;
|
this._connected = true;
|
||||||
chatMessagesStore.addIncomingUser(this.userId);
|
chatMessagesStore.addIncomingUser(this.userId);
|
||||||
|
|
||||||
this.newMessageunsubscriber = newChatMessageStore.subscribe((newMessage) => {
|
this.newMessageSubscribtion = newChatMessageSubject.subscribe((newMessage) => {
|
||||||
if (!newMessage) return;
|
if (!newMessage) return;
|
||||||
this.write(
|
this.write(
|
||||||
new Buffer(
|
new Buffer(
|
||||||
@ -138,8 +138,7 @@ export class VideoPeer extends Peer {
|
|||||||
message: newMessage,
|
message: newMessage,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
); //send more data
|
);
|
||||||
newChatMessageStore.set(null); //This is to prevent a newly created SimplePeer to send an old message a 2nd time. Is there a better way?
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -262,7 +261,7 @@ export class VideoPeer extends Peer {
|
|||||||
this.closing = true;
|
this.closing = true;
|
||||||
this.onBlockSubscribe.unsubscribe();
|
this.onBlockSubscribe.unsubscribe();
|
||||||
this.onUnBlockSubscribe.unsubscribe();
|
this.onUnBlockSubscribe.unsubscribe();
|
||||||
if (this.newMessageunsubscriber) this.newMessageunsubscriber();
|
this.newMessageSubscribtion?.unsubscribe();
|
||||||
chatMessagesStore.addOutcomingUser(this.userId);
|
chatMessagesStore.addOutcomingUser(this.userId);
|
||||||
if (this.localStreamStoreSubscribe) this.localStreamStoreSubscribe();
|
if (this.localStreamStoreSubscribe) this.localStreamStoreSubscribe();
|
||||||
if (this.obtainedMediaConstraintStoreSubscribe) this.obtainedMediaConstraintStoreSubscribe();
|
if (this.obtainedMediaConstraintStoreSubscribe) this.obtainedMediaConstraintStoreSubscribe();
|
||||||
|
Loading…
Reference in New Issue
Block a user