Push message when user is connected on new room

This commit is contained in:
Gregoire Parant 2020-10-20 09:20:00 +02:00
parent eb1f62bb1c
commit 8d1d6fc8dc
3 changed files with 24 additions and 5 deletions

View File

@ -18,7 +18,7 @@ import {UserMovesMessage} from "../Messages/generated/messages_pb";
import {TemplatedApp} from "uWebSockets.js" import {TemplatedApp} from "uWebSockets.js"
import {parse} from "query-string"; import {parse} from "query-string";
import {jwtTokenManager} from "../Services/JWTTokenManager"; import {jwtTokenManager} from "../Services/JWTTokenManager";
import {adminApi} from "../Services/AdminApi"; import {adminApi, fetchMemberDataByUuidResponse} from "../Services/AdminApi";
import {socketManager} from "../Services/SocketManager"; import {socketManager} from "../Services/SocketManager";
import {emitInBatch, resetPing} from "../Services/IoSocketHelpers"; import {emitInBatch, resetPing} from "../Services/IoSocketHelpers";
import Jwt from "jsonwebtoken"; import Jwt from "jsonwebtoken";
@ -226,6 +226,23 @@ export class IoSocketController {
const client = this.initClient(ws); //todo: into the upgrade instead? const client = this.initClient(ws); //todo: into the upgrade instead?
socketManager.handleJoinRoom(client); socketManager.handleJoinRoom(client);
resetPing(client); resetPing(client);
//get data information and shwo messages
adminApi.fetchMemberDataByUuid(client.userUuid).then((res: fetchMemberDataByUuidResponse) => {
if (!res.messages) {
return;
}
res.messages.forEach((c: unknown) => {
let messageToSend = c as { type: string, message: string };
socketManager.emitSendUserMessage({
userUuid: client.userUuid,
type: messageToSend.type,
message: messageToSend.message
})
});
}).catch((err) => {
console.error('fetchMemberDataByUuid => err', err);
});
}, },
message: (ws, arrayBuffer, isBinary): void => { message: (ws, arrayBuffer, isBinary): void => {
const client = ws as ExSocketInterface; const client = ws as ExSocketInterface;

View File

@ -9,11 +9,13 @@ export interface AdminApiData {
tags: string[] tags: string[]
policy_type: number policy_type: number
userUuid: string userUuid: string
messages?: unknown[]
} }
export interface fetchMemberDataByUuidResponse { export interface fetchMemberDataByUuidResponse {
uuid: string; uuid: string;
tags: string[]; tags: string[];
messages: unknown[];
} }
class AdminApi { class AdminApi {
@ -32,9 +34,9 @@ class AdminApi {
params.roomSlug = roomSlug; params.roomSlug = roomSlug;
} }
const res = await Axios.get(ADMIN_API_URL+'/api/map', const res = await Axios.get(ADMIN_API_URL + '/api/map',
{ {
headers: {"Authorization" : `${ADMIN_API_TOKEN}`}, headers: {"Authorization": `${ADMIN_API_TOKEN}`},
params params
} }
) )
@ -45,7 +47,7 @@ class AdminApi {
if (!ADMIN_API_URL) { if (!ADMIN_API_URL) {
return Promise.reject('No admin backoffice set!'); return Promise.reject('No admin backoffice set!');
} }
const res = await Axios.get(ADMIN_API_URL+'/membership/'+uuid, const res = await Axios.get(ADMIN_API_URL+'/api/membership/'+uuid,
{ headers: {"Authorization" : `${ADMIN_API_TOKEN}`} } { headers: {"Authorization" : `${ADMIN_API_TOKEN}`} }
) )
return res.data; return res.data;

View File

@ -29,7 +29,7 @@ export class TypeMessageExt implements TypeMessageInterface{
const mainSectionDiv = HtmlUtils.getElementByIdOrFail<HTMLDivElement>('main-container'); const mainSectionDiv = HtmlUtils.getElementByIdOrFail<HTMLDivElement>('main-container');
mainSectionDiv.appendChild(div); mainSectionDiv.appendChild(div);
const reportMessageAudio = HtmlUtils.getElementByIdOrFail<HTMLAudioElement>('audio-webrtc-in'); const reportMessageAudio = HtmlUtils.getElementByIdOrFail<HTMLAudioElement>('report-message');
reportMessageAudio.play(); reportMessageAudio.play();
this.nbSecond = this.maxNbSecond; this.nbSecond = this.maxNbSecond;