Users blocking now rely on UUID rather than ID
This way, if a user A blocks another user B, if user B refreshes the browser or leaves and re-enters the room, user B will still be blocked. As a side effect, this allows us to completely remove the "sockets" property in the SocketManager on the Pusher.
This commit is contained in:
parent
28e4f59e50
commit
34cb0ebf39
15 changed files with 143 additions and 141 deletions
|
@ -1,24 +1,27 @@
|
|||
import {Subject} from 'rxjs';
|
||||
import { Subject } from "rxjs";
|
||||
|
||||
class BlackListManager {
|
||||
private list: number[] = [];
|
||||
public onBlockStream: Subject<number> = new Subject();
|
||||
public onUnBlockStream: Subject<number> = new Subject();
|
||||
|
||||
isBlackListed(userId: number): boolean {
|
||||
return this.list.find((data) => data === userId) !== undefined;
|
||||
}
|
||||
|
||||
blackList(userId: number): void {
|
||||
if (this.isBlackListed(userId)) return;
|
||||
this.list.push(userId);
|
||||
this.onBlockStream.next(userId);
|
||||
private list: string[] = [];
|
||||
public onBlockStream: Subject<string> = new Subject();
|
||||
public onUnBlockStream: Subject<string> = new Subject();
|
||||
|
||||
isBlackListed(userUuid: string): boolean {
|
||||
return this.list.find((data) => data === userUuid) !== undefined;
|
||||
}
|
||||
|
||||
cancelBlackList(userId: number): void {
|
||||
this.list.splice(this.list.findIndex(data => data === userId), 1);
|
||||
this.onUnBlockStream.next(userId);
|
||||
blackList(userUuid: string): void {
|
||||
if (this.isBlackListed(userUuid)) return;
|
||||
this.list.push(userUuid);
|
||||
this.onBlockStream.next(userUuid);
|
||||
}
|
||||
|
||||
cancelBlackList(userUuid: string): void {
|
||||
this.list.splice(
|
||||
this.list.findIndex((data) => data === userUuid),
|
||||
1
|
||||
);
|
||||
this.onUnBlockStream.next(userUuid);
|
||||
}
|
||||
}
|
||||
|
||||
export const blackListManager = new BlackListManager();
|
||||
export const blackListManager = new BlackListManager();
|
||||
|
|
|
@ -11,7 +11,7 @@ import { get } from "svelte/store";
|
|||
import { localStreamStore, LocalStreamStoreValue, obtainedMediaConstraintStore } from "../Stores/MediaStore";
|
||||
import { screenSharingLocalStreamStore } from "../Stores/ScreenSharingStore";
|
||||
import { discussionManager } from "./DiscussionManager";
|
||||
import {playersStore} from "../Stores/PlayersStore";
|
||||
import { playersStore } from "../Stores/PlayersStore";
|
||||
|
||||
export interface UserSimplePeerInterface {
|
||||
userId: number;
|
||||
|
@ -199,7 +199,7 @@ export class SimplePeer {
|
|||
}
|
||||
|
||||
private getName(userId: number): string {
|
||||
return playersStore.getPlayerById(userId)?.name || '';
|
||||
return playersStore.getPlayerById(userId)?.name || "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -364,7 +364,8 @@ export class SimplePeer {
|
|||
}
|
||||
|
||||
private receiveWebrtcScreenSharingSignal(data: WebRtcSignalReceivedMessageInterface) {
|
||||
if (blackListManager.isBlackListed(data.userId)) return;
|
||||
const uuid = playersStore.getPlayerById(data.userId)?.userUuid || "";
|
||||
if (blackListManager.isBlackListed(uuid)) return;
|
||||
console.log("receiveWebrtcScreenSharingSignal", data);
|
||||
const streamResult = get(screenSharingLocalStreamStore);
|
||||
let stream: MediaStream | null = null;
|
||||
|
@ -465,7 +466,8 @@ export class SimplePeer {
|
|||
}
|
||||
|
||||
private sendLocalScreenSharingStreamToUser(userId: number, localScreenCapture: MediaStream): void {
|
||||
if (blackListManager.isBlackListed(userId)) return;
|
||||
const uuid = playersStore.getPlayerById(userId)?.userUuid || "";
|
||||
if (blackListManager.isBlackListed(uuid)) return;
|
||||
// If a connection already exists with user (because it is already sharing a screen with us... let's use this connection)
|
||||
if (this.PeerScreenSharingConnectionArray.has(userId)) {
|
||||
this.pushScreenSharingToRemoteUser(userId, localScreenCapture);
|
||||
|
|
|
@ -8,6 +8,7 @@ import type { UserSimplePeerInterface } from "./SimplePeer";
|
|||
import { get, readable, Readable } from "svelte/store";
|
||||
import { obtainedMediaConstraintStore } from "../Stores/MediaStore";
|
||||
import { discussionManager } from "./DiscussionManager";
|
||||
import { playersStore } from "../Stores/PlayersStore";
|
||||
|
||||
const Peer: SimplePeerNamespace.SimplePeer = require("simple-peer");
|
||||
|
||||
|
@ -26,6 +27,7 @@ export class VideoPeer extends Peer {
|
|||
private remoteStream!: MediaStream;
|
||||
private blocked: boolean = false;
|
||||
public readonly userId: number;
|
||||
public readonly userUuid: string;
|
||||
public readonly uniqueId: string;
|
||||
private onBlockSubscribe: Subscription;
|
||||
private onUnBlockSubscribe: Subscription;
|
||||
|
@ -60,6 +62,7 @@ export class VideoPeer extends Peer {
|
|||
});
|
||||
|
||||
this.userId = user.userId;
|
||||
this.userUuid = playersStore.getPlayerById(this.userId)?.userUuid || "";
|
||||
this.uniqueId = "video_" + this.userId;
|
||||
|
||||
this.streamStore = readable<MediaStream | null>(null, (set) => {
|
||||
|
@ -181,20 +184,20 @@ export class VideoPeer extends Peer {
|
|||
});
|
||||
|
||||
this.pushVideoToRemoteUser(localStream);
|
||||
this.onBlockSubscribe = blackListManager.onBlockStream.subscribe((userId) => {
|
||||
if (userId === this.userId) {
|
||||
this.onBlockSubscribe = blackListManager.onBlockStream.subscribe((userUuid) => {
|
||||
if (userUuid === this.userUuid) {
|
||||
this.toggleRemoteStream(false);
|
||||
this.sendBlockMessage(true);
|
||||
}
|
||||
});
|
||||
this.onUnBlockSubscribe = blackListManager.onUnBlockStream.subscribe((userId) => {
|
||||
if (userId === this.userId) {
|
||||
this.onUnBlockSubscribe = blackListManager.onUnBlockStream.subscribe((userUuid) => {
|
||||
if (userUuid === this.userUuid) {
|
||||
this.toggleRemoteStream(true);
|
||||
this.sendBlockMessage(false);
|
||||
}
|
||||
});
|
||||
|
||||
if (blackListManager.isBlackListed(this.userId)) {
|
||||
if (blackListManager.isBlackListed(this.userUuid)) {
|
||||
this.sendBlockMessage(true);
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +234,7 @@ export class VideoPeer extends Peer {
|
|||
private stream(stream: MediaStream) {
|
||||
try {
|
||||
this.remoteStream = stream;
|
||||
if (blackListManager.isBlackListed(this.userId) || this.blocked) {
|
||||
if (blackListManager.isBlackListed(this.userUuid) || this.blocked) {
|
||||
this.toggleRemoteStream(false);
|
||||
}
|
||||
} catch (err) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue