Merge pull request #1262 from thecodingmachine/players_store
Adding a playersStore
This commit is contained in:
commit
28e4f59e50
@ -425,7 +425,6 @@ export class SocketManager {
|
||||
// Let's send 2 messages: one to the user joining the group and one to the other user
|
||||
const webrtcStartMessage1 = new WebRtcStartMessage();
|
||||
webrtcStartMessage1.setUserid(otherUser.id);
|
||||
webrtcStartMessage1.setName(otherUser.name);
|
||||
webrtcStartMessage1.setInitiator(true);
|
||||
if (TURN_STATIC_AUTH_SECRET !== "") {
|
||||
const { username, password } = this.getTURNCredentials("" + otherUser.id, TURN_STATIC_AUTH_SECRET);
|
||||
@ -443,7 +442,6 @@ export class SocketManager {
|
||||
|
||||
const webrtcStartMessage2 = new WebRtcStartMessage();
|
||||
webrtcStartMessage2.setUserid(user.id);
|
||||
webrtcStartMessage2.setName(user.name);
|
||||
webrtcStartMessage2.setInitiator(false);
|
||||
if (TURN_STATIC_AUTH_SECRET !== "") {
|
||||
const { username, password } = this.getTURNCredentials("" + user.id, TURN_STATIC_AUTH_SECRET);
|
||||
|
@ -466,7 +466,6 @@ export class RoomConnection implements RoomConnection {
|
||||
this.onMessage(EventMessage.WEBRTC_START, (message: WebRtcStartMessage) => {
|
||||
callback({
|
||||
userId: message.getUserid(),
|
||||
name: message.getName(),
|
||||
initiator: message.getInitiator(),
|
||||
webRtcUser: message.getWebrtcusername() ?? undefined,
|
||||
webRtcPassword: message.getWebrtcpassword() ?? undefined,
|
||||
|
@ -1,11 +1,6 @@
|
||||
import type {PointInterface} from "../../Connexion/ConnexionModels";
|
||||
import type {BodyResourceDescriptionInterface} from "../Entity/PlayerTextures";
|
||||
import type {PlayerInterface} from "./PlayerInterface";
|
||||
|
||||
export interface AddPlayerInterface {
|
||||
userId: number;
|
||||
name: string;
|
||||
characterLayers: BodyResourceDescriptionInterface[];
|
||||
export interface AddPlayerInterface extends PlayerInterface {
|
||||
position: PointInterface;
|
||||
visitCardUrl: string|null;
|
||||
companion: string|null;
|
||||
}
|
||||
|
@ -91,6 +91,7 @@ import { soundManager } from "./SoundManager";
|
||||
import { peerStore, screenSharingPeerStore } from "../../Stores/PeerStore";
|
||||
import { videoFocusStore } from "../../Stores/VideoFocusStore";
|
||||
import { biggestAvailableAreaStore } from "../../Stores/BiggestAvailableAreaStore";
|
||||
import {playersStore} from "../../Stores/PlayersStore";
|
||||
|
||||
export interface GameSceneInitInterface {
|
||||
initPosition: PointInterface | null;
|
||||
@ -597,6 +598,8 @@ export class GameScene extends DirtyScene {
|
||||
.then((onConnect: OnConnectInterface) => {
|
||||
this.connection = onConnect.connection;
|
||||
|
||||
playersStore.connectToRoomConnection(this.connection);
|
||||
|
||||
this.connection.onUserJoins((message: MessageUserJoined) => {
|
||||
const userMessage: AddPlayerInterface = {
|
||||
userId: message.userId,
|
||||
|
9
front/src/Phaser/Game/PlayerInterface.ts
Normal file
9
front/src/Phaser/Game/PlayerInterface.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import type {BodyResourceDescriptionInterface} from "../Entity/PlayerTextures";
|
||||
|
||||
export interface PlayerInterface {
|
||||
userId: number;
|
||||
name: string;
|
||||
characterLayers: BodyResourceDescriptionInterface[];
|
||||
visitCardUrl: string|null;
|
||||
companion: string|null;
|
||||
}
|
43
front/src/Stores/PlayersStore.ts
Normal file
43
front/src/Stores/PlayersStore.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { writable } from "svelte/store";
|
||||
import type {PlayerInterface} from "../Phaser/Game/PlayerInterface";
|
||||
import type {RoomConnection} from "../Connexion/RoomConnection";
|
||||
|
||||
/**
|
||||
* A store that contains the list of players currently known.
|
||||
*/
|
||||
function createPlayersStore() {
|
||||
let players = new Map<number, PlayerInterface>();
|
||||
|
||||
const { subscribe, set, update } = writable(players);
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
connectToRoomConnection: (roomConnection: RoomConnection) => {
|
||||
players = new Map<number, PlayerInterface>();
|
||||
set(players);
|
||||
roomConnection.onUserJoins((message) => {
|
||||
update((users) => {
|
||||
users.set(message.userId, {
|
||||
userId: message.userId,
|
||||
name: message.name,
|
||||
characterLayers: message.characterLayers,
|
||||
visitCardUrl: message.visitCardUrl,
|
||||
companion: message.companion,
|
||||
});
|
||||
return users;
|
||||
});
|
||||
});
|
||||
roomConnection.onUserLeft((userId) => {
|
||||
update((users) => {
|
||||
users.delete(userId);
|
||||
return users;
|
||||
});
|
||||
});
|
||||
},
|
||||
getPlayerById(userId: number): PlayerInterface|undefined {
|
||||
return players.get(userId);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const playersStore = createPlayersStore();
|
@ -11,10 +11,10 @@ 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";
|
||||
|
||||
export interface UserSimplePeerInterface {
|
||||
userId: number;
|
||||
name?: string;
|
||||
initiator?: boolean;
|
||||
webRtcUser?: string | undefined;
|
||||
webRtcPassword?: string | undefined;
|
||||
@ -153,10 +153,7 @@ export class SimplePeer {
|
||||
}
|
||||
}
|
||||
|
||||
let name = user.name;
|
||||
if (!name) {
|
||||
name = this.getName(user.userId);
|
||||
}
|
||||
const name = this.getName(user.userId);
|
||||
|
||||
discussionManager.removeParticipant(user.userId);
|
||||
|
||||
@ -191,7 +188,7 @@ export class SimplePeer {
|
||||
|
||||
//Create a notification for first user in circle discussion
|
||||
if (this.PeerConnectionArray.size === 0) {
|
||||
mediaManager.createNotification(user.name ?? "");
|
||||
mediaManager.createNotification(name);
|
||||
}
|
||||
this.PeerConnectionArray.set(user.userId, peer);
|
||||
|
||||
@ -202,12 +199,7 @@ export class SimplePeer {
|
||||
}
|
||||
|
||||
private getName(userId: number): string {
|
||||
const userSearch = this.Users.find((userSearch: UserSimplePeerInterface) => userSearch.userId === userId);
|
||||
if (userSearch) {
|
||||
return userSearch.name || "";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
return playersStore.getPlayerById(userId)?.name || '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -183,7 +183,6 @@ message RoomJoinedMessage {
|
||||
|
||||
message WebRtcStartMessage {
|
||||
int32 userId = 1;
|
||||
string name = 2;
|
||||
bool initiator = 3;
|
||||
string webrtcUserName = 4;
|
||||
string webrtcPassword = 5;
|
||||
|
Loading…
Reference in New Issue
Block a user