wip
This commit is contained in:
parent
152d5e9578
commit
fd572707ff
4 changed files with 19 additions and 24 deletions
|
|
@ -21,6 +21,7 @@ import { setGameLink } from './setGameLink';
|
||||||
import { list_SocketListener } from './chatBackHelperFunctions/list_SocketListener';
|
import { list_SocketListener } from './chatBackHelperFunctions/list_SocketListener';
|
||||||
import { isUser_BlockedBy_me } from './chatBackHelperFunctions/isUser_BlockedBy_me';
|
import { isUser_BlockedBy_me } from './chatBackHelperFunctions/isUser_BlockedBy_me';
|
||||||
import type { inviteUserTOGame, ClientInfo, blockedUnBlocked } from './chat_types';
|
import type { inviteUserTOGame, ClientInfo, blockedUnBlocked } from './chat_types';
|
||||||
|
import { PongGameId } from '@shared/database/mixin/pong';
|
||||||
|
|
||||||
|
|
||||||
declare const __SERVICE_NAME: string;
|
declare const __SERVICE_NAME: string;
|
||||||
|
|
@ -216,10 +217,9 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
socket.on('inviteGame', async (data: string) => {
|
socket.on('inviteGame', async (data: string) => {
|
||||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||||
const profilInvite: ClientProfil = JSON.parse(data) || '';
|
const profilInvite: ClientProfil = JSON.parse(data) || '';
|
||||||
const linkGame: Response | undefined = await setGameLink(fastify, data);
|
const linkGame: PongGameId | undefined = await setGameLink(fastify, data);
|
||||||
if (!linkGame) return;
|
if (!linkGame) return;
|
||||||
const tmp: inviteUserTOGame = await linkGame?.json() as inviteUserTOGame;
|
const link: string = `<a href="https://localhost:8888/app/pong?game=${linkGame}" style="color: blue; text-decoration: underline; cursor: pointer;">Click me</a>`;
|
||||||
const link: string = `<a href="https://localhost:8888/app/pong?game=${tmp.gameId}" style="color: blue; text-decoration: underline; cursor: pointer;">Click me</a>`;
|
|
||||||
const inviteHtml: string = 'invites you to a game ' + link;
|
const inviteHtml: string = 'invites you to a game ' + link;
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
sendInvite(fastify, inviteHtml, profilInvite);
|
sendInvite(fastify, inviteHtml, profilInvite);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
import type { ClientProfil } from './chat_types';
|
import type { ClientProfil } from './chat_types';
|
||||||
|
import { PongGameId } from '@shared/database/mixin/pong';
|
||||||
|
|
||||||
|
|
||||||
export async function setGameLink(fastify: FastifyInstance, data: string): Promise<Response | undefined> {
|
export async function setGameLink(fastify: FastifyInstance, data: string): Promise<PongGameId | undefined> {
|
||||||
|
|
||||||
const profilInvite: ClientProfil = JSON.parse(data) || '';
|
const profilInvite: ClientProfil = JSON.parse(data) || '';
|
||||||
|
|
||||||
const payload = { 'user1': `'${profilInvite.SenderID}'`, 'user2':`'${profilInvite.userID}'` };
|
const payload = { 'user1': `'${profilInvite.SenderID}'`, 'user2':`'${profilInvite.userID}'` };
|
||||||
|
|
@ -14,12 +14,17 @@ export async function setGameLink(fastify: FastifyInstance, data: string): Promi
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
|
fastify.log.info("HELLO ?");
|
||||||
throw (resp);
|
throw (resp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fastify.log.info('game-end info to chat success');
|
fastify.log.info('game-end info to chat success');
|
||||||
}
|
}
|
||||||
return resp;
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const json = await resp.json() as any;
|
||||||
|
fastify.log.info(json);
|
||||||
|
return json.payload.gameId;
|
||||||
}
|
}
|
||||||
// disable eslint for err catching
|
// disable eslint for err catching
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,7 @@ import fastify, { FastifyInstance } from 'fastify';
|
||||||
import app from './app';
|
import app from './app';
|
||||||
|
|
||||||
const start = async () => {
|
const start = async () => {
|
||||||
const envToLogger = {
|
const f: FastifyInstance = fastify({ logger: true });
|
||||||
development: {
|
|
||||||
transport: {
|
|
||||||
target: 'pino-pretty',
|
|
||||||
options: {
|
|
||||||
translateTime: 'HH:MM:ss Z',
|
|
||||||
ignore: 'pid,hostname',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
production: true,
|
|
||||||
test: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
const f: FastifyInstance = fastify({ logger: envToLogger.development });
|
|
||||||
try {
|
try {
|
||||||
process.on('SIGTERM', () => {
|
process.on('SIGTERM', () => {
|
||||||
f.log.info('Requested to shutdown');
|
f.log.info('Requested to shutdown');
|
||||||
|
|
|
||||||
|
|
@ -223,9 +223,13 @@ class StateI {
|
||||||
}
|
}
|
||||||
|
|
||||||
public newPausedGame(suid1: string, suid2: string): GameId | undefined {
|
public newPausedGame(suid1: string, suid2: string): GameId | undefined {
|
||||||
if (!this.fastify.db.getUser(suid1) || !this.fastify.db.getUser(suid2)) {
|
|
||||||
return undefined;
|
this.fastify.log.info('suid1:' + suid1);
|
||||||
}
|
this.fastify.log.info('suid2:' + suid2);
|
||||||
|
// if (!this.fastify.db.getUser(suid1) || !this.fastify.db.getUser(suid2)) {
|
||||||
|
// return undefined;
|
||||||
|
// }
|
||||||
|
this.fastify.log.info('new paused start');
|
||||||
const uid1: UserId = suid1 as UserId;
|
const uid1: UserId = suid1 as UserId;
|
||||||
const uid2: UserId = suid2 as UserId;
|
const uid2: UserId = suid2 as UserId;
|
||||||
const g = new Pong(uid1, uid2);
|
const g = new Pong(uid1, uid2);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue