Added U Game system
This commit is contained in:
parent
62705c4a7e
commit
96cfbef642
15 changed files with 56 additions and 93 deletions
|
|
@ -43,6 +43,14 @@ declare module "ft_state" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DivPrivate extends HTMLElement {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customElements.define("div-private", DivPrivate);
|
||||||
|
|
||||||
export function getSocket(): Socket {
|
export function getSocket(): Socket {
|
||||||
if (window.__state.chatSock === undefined)
|
if (window.__state.chatSock === undefined)
|
||||||
window.__state.chatSock = io(window.location.host, {
|
window.__state.chatSock = io(window.location.host, {
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,5 @@ import { addMessage } from './addMessage';
|
||||||
export function inviteToPlayPong(profil: ClientProfil, senderSocket: Socket) {
|
export function inviteToPlayPong(profil: ClientProfil, senderSocket: Socket) {
|
||||||
profil.SenderName = getUser()?.name ?? '';
|
profil.SenderName = getUser()?.name ?? '';
|
||||||
if (profil.SenderName === profil.user) return;
|
if (profil.SenderName === profil.user) return;
|
||||||
addMessage(`You invited to play: ${profil.user}🏓`)
|
|
||||||
senderSocket.emit('inviteGame', JSON.stringify(profil));
|
senderSocket.emit('inviteGame', JSON.stringify(profil));
|
||||||
};
|
};
|
||||||
|
|
@ -235,7 +235,7 @@ if (!window.__state._routingHandler) {
|
||||||
|
|
||||||
if (sameOrigin) {
|
if (sameOrigin) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
navigateTo(url.pathname);
|
navigateTo(`${url.pathname}${url.search}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* {{#lambda.indented_star_1}}{{{unescapedDescription}}}{{/lambda.indented_star_1}}
|
* {{#lambda.indented_star_1}}{{{unedDescription}}}{{/lambda.indented_star_1}}
|
||||||
* @export
|
* @export
|
||||||
* @interface {{classname}}
|
* @interface {{classname}}
|
||||||
*/
|
*/
|
||||||
|
|
@ -9,7 +9,7 @@ export interface {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{
|
||||||
{{/additionalPropertiesType}}
|
{{/additionalPropertiesType}}
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
/**
|
/**
|
||||||
* {{#lambda.indented_star_4}}{{{unescapedDescription}}}{{/lambda.indented_star_4}}
|
* {{#lambda.indented_star_4}}{{{unedDescription}}}{{/lambda.indented_star_4}}
|
||||||
* @type {{=<% %>=}}{<%&datatype%>}<%={{ }}=%>
|
* @type {{=<% %>=}}{<%&datatype%>}<%={{ }}=%>
|
||||||
* @memberof {{classname}}
|
* @memberof {{classname}}
|
||||||
{{#deprecated}}
|
{{#deprecated}}
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ export function isNullish<T>(v: T | undefined | null): v is null | undefined {
|
||||||
return v === null || v === undefined;
|
return v === null || v === undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function escape(s: string): string {
|
export function e(s: string): string {
|
||||||
return s.replace(
|
return s.replace(
|
||||||
/[^0-9A-Za-z ]/g,
|
/[^0-9A-Za-z ]/g,
|
||||||
c => '&#' + c.charCodeAt(0) + ';',
|
c => '&#' + c.charCodeAt(0) + ';',
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,9 @@ import { makeProfil } from './chatBackHelperFunctions/makeProfil';
|
||||||
import { isBlocked } from './chatBackHelperFunctions/isBlocked';
|
import { isBlocked } from './chatBackHelperFunctions/isBlocked';
|
||||||
import { sendProfil } from './chatBackHelperFunctions/sendProfil';
|
import { sendProfil } from './chatBackHelperFunctions/sendProfil';
|
||||||
import { setGameLink } from './setGameLink';
|
import { setGameLink } from './setGameLink';
|
||||||
//import { nextGame_SocketListener } from './nextGame_SocketListener';
|
|
||||||
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 { ClientInfo, blockedUnBlocked } from './chat_types';
|
import type { inviteUserTOGame, ClientInfo, blockedUnBlocked } from './chat_types';
|
||||||
|
|
||||||
|
|
||||||
declare const __SERVICE_NAME: string;
|
declare const __SERVICE_NAME: string;
|
||||||
|
|
@ -103,7 +102,7 @@ async function onReady(fastify: FastifyInstance) {
|
||||||
broadcast(fastify, obj, obj.SenderWindowID);
|
broadcast(fastify, obj, obj.SenderWindowID);
|
||||||
fastify.log.info(`Client connected: ${socket.id}`);
|
fastify.log.info(`Client connected: ${socket.id}`);
|
||||||
});
|
});
|
||||||
//nextGame_SocketListener(fastify, socket);
|
|
||||||
list_SocketListener(fastify, socket);
|
list_SocketListener(fastify, socket);
|
||||||
|
|
||||||
socket.on('updateClientName', (object) => {
|
socket.on('updateClientName', (object) => {
|
||||||
|
|
@ -217,13 +216,11 @@ 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);
|
const linkGame: Response | undefined = await setGameLink(fastify, data);
|
||||||
if (!linkGame) return;
|
if (!linkGame) return;
|
||||||
const tmp: any = await linkGame?.json();
|
const tmp: inviteUserTOGame = await linkGame?.json() as inviteUserTOGame;
|
||||||
const link: string = `'<a href=\'https://localhost:8888/pong?game=${tmp.payload.gameId}\' 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;
|
||||||
console.log(link);
|
|
||||||
const inviteHtml: string = 'invites you to a game' + link;
|
|
||||||
if (clientName !== null) {
|
if (clientName !== null) {
|
||||||
sendInvite(fastify, inviteHtml, profilInvite);
|
sendInvite(fastify, inviteHtml, profilInvite);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import type { ClientProfil } from '../chat_types';
|
||||||
import type { User } from '@shared/database/mixin/user';
|
import type { User } from '@shared/database/mixin/user';
|
||||||
import { getUserByName } from './getUserByName';
|
import { getUserByName } from './getUserByName';
|
||||||
import { Socket } from 'socket.io';
|
import { Socket } from 'socket.io';
|
||||||
import { escape } from '@shared/utils';
|
import { e } from '@shared/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function makeProfil - translates the Users[] to a one user looking by name
|
* function makeProfil - translates the Users[] to a one user looking by name
|
||||||
|
|
@ -32,7 +32,7 @@ export async function makeProfil(fastify: FastifyInstance, user: string, socket:
|
||||||
user: `${allUsers.name}`,
|
user: `${allUsers.name}`,
|
||||||
loginName: loginState,
|
loginName: loginState,
|
||||||
userID: `${allUsers?.id ?? ''}`,
|
userID: `${allUsers?.id ?? ''}`,
|
||||||
text: escape(allUsers.desc),
|
text: e(allUsers.desc),
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
SenderWindowID: socket.id,
|
SenderWindowID: socket.id,
|
||||||
SenderName: '',
|
SenderName: '',
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export async function sendInvite(fastify: FastifyInstance, innerHtml: string, pr
|
||||||
const sockets = await fastify.io.fetchSockets();
|
const sockets = await fastify.io.fetchSockets();
|
||||||
let targetSocket;
|
let targetSocket;
|
||||||
for (const socket of sockets) {
|
for (const socket of sockets) {
|
||||||
const clientInfo: string = clientChat.get(socket.id)?.user || '';
|
const clientInfo: string | undefined = clientChat.get(socket.id)?.user || undefined;
|
||||||
targetSocket = socket || null;
|
targetSocket = socket || null;
|
||||||
if (!targetSocket) continue;
|
if (!targetSocket) continue;
|
||||||
if (clientInfo === profil.user) {
|
if (clientInfo === profil.user) {
|
||||||
|
|
@ -36,12 +36,12 @@ export async function sendInvite(fastify: FastifyInstance, innerHtml: string, pr
|
||||||
command: `@${clientInfo}`,
|
command: `@${clientInfo}`,
|
||||||
destination: 'inviteMsg',
|
destination: 'inviteMsg',
|
||||||
type: 'chat',
|
type: 'chat',
|
||||||
user: profil.SenderName,
|
user: profil.user,
|
||||||
token: '',
|
token: '',
|
||||||
text: getGameNumber(),
|
text: getGameNumber(),
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
SenderWindowID: socket.id,
|
SenderWindowID: socket.id,
|
||||||
userID: '',
|
userID: profil.userID,
|
||||||
frontendUserName: '',
|
frontendUserName: '',
|
||||||
frontendUser: '',
|
frontendUser: '',
|
||||||
SenderUserName: profil.SenderName,
|
SenderUserName: profil.SenderName,
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
||||||
|
|
||||||
for (const socket of sockets) {
|
for (const socket of sockets) {
|
||||||
if (socket.id === sender) continue;
|
if (socket.id === sender) continue;
|
||||||
const UserID = getUserByName(allUsers, data.user)?.id ?? '';
|
const UserID: string = getUserByName(allUsers, data.user as string)?.id as string ?? undefined;
|
||||||
const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
|
const list:BlockRelation[] = whoBlockedMe(fastify, UserID);
|
||||||
const clientInfo = clientChat.get(socket.id);
|
const clientInfo = clientChat.get(socket.id);
|
||||||
if (!clientInfo) continue;
|
if (!clientInfo) continue;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ export type ClientMessage = {
|
||||||
innerHtml?: string,
|
innerHtml?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export type ClientProfil = {
|
export type ClientProfil = {
|
||||||
command: string,
|
command: string,
|
||||||
destination: string,
|
destination: string,
|
||||||
|
|
@ -35,7 +34,6 @@ export type ClientProfil = {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export interface ClientInfo {
|
export interface ClientInfo {
|
||||||
user: string;
|
user: string;
|
||||||
socket: string
|
socket: string
|
||||||
|
|
@ -49,21 +47,11 @@ export type blockedUnBlocked =
|
||||||
by: string,
|
by: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type inviteUserTOGame = {
|
||||||
// export type obj =
|
user1: string,
|
||||||
// {
|
user2: string,
|
||||||
// command: string,
|
gameId: string
|
||||||
// destination: string,
|
}
|
||||||
// type: string,
|
|
||||||
// user: string,
|
|
||||||
// frontendUserName: string,
|
|
||||||
// frontendUser: string,
|
|
||||||
// token: string,
|
|
||||||
// text: string,
|
|
||||||
// timestamp: number,
|
|
||||||
// SenderWindowID: string,
|
|
||||||
// Sendertext: string,
|
|
||||||
// };
|
|
||||||
|
|
||||||
export type BlockRelation = {
|
export type BlockRelation = {
|
||||||
blocked: string;
|
blocked: string;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
// /**
|
|
||||||
// /* TODO find the description info for profil / or profil game link and return
|
|
||||||
// **/
|
|
||||||
// export function createNextGame() {
|
|
||||||
// return '<a href=\'https://localhost:8888/app/\' style=\'color: blue; text-decoration: underline; cursor: pointer;\'>The next Game is Starting click here to watch</a>';
|
|
||||||
// };
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
// import type { FastifyInstance } from 'fastify';
|
|
||||||
// import { broadcastNextGame } from './broadcastNextGame';
|
|
||||||
// import { Socket } from 'socket.io';
|
|
||||||
// import { createNextGame } from './createNextGame';
|
|
||||||
// import { sendGameLinkToChatService } from './sendGameLinkToChatService';
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * function listens to the socket for a nextGame emit
|
|
||||||
// * once triggered it broadcasts the pop up
|
|
||||||
// * TODO plug this into backend of the game Chat
|
|
||||||
// * @param fastify
|
|
||||||
// * @param socket
|
|
||||||
// */
|
|
||||||
// export function nextGame_SocketListener(fastify: FastifyInstance, socket: Socket) {
|
|
||||||
// socket.on('nextGame', () => {
|
|
||||||
// const link: string = createNextGame();
|
|
||||||
// const game: Promise<string> = sendGameLinkToChatService(link);
|
|
||||||
// broadcastNextGame(fastify, game);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
@ -1,33 +1,29 @@
|
||||||
import { FastifyInstance } from 'fastify';
|
import { FastifyInstance } from 'fastify';
|
||||||
|
import type { ClientProfil } from './chat_types';
|
||||||
|
|
||||||
|
|
||||||
export async function setGameLink(fastify: FastifyInstance): Promise<Response | undefined> {
|
export async function setGameLink(fastify: FastifyInstance, data: string): Promise<Response | undefined> {
|
||||||
|
|
||||||
|
const profilInvite: ClientProfil = JSON.parse(data) || '';
|
||||||
|
|
||||||
let payload = {"user1":"019bad60-1e4a-7e28-af95-a8a88146107a", "user2":"019bad56-6468-748d-827e-110eb6aa4514"};
|
const payload = { 'user1': `'${profilInvite.SenderID}'`, 'user2':`'${profilInvite.userID}'` };
|
||||||
try {
|
try {
|
||||||
const resp = await fetch('http://app-pong/api/pong/createPausedGame', {
|
const resp = await fetch('http://app-pong/api/pong/createPausedGame', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-type': 'application/json' },
|
headers: { 'Content-type': 'application/json' },
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
|
if (!resp.ok) {
|
||||||
if (!resp.ok) {
|
throw (resp);
|
||||||
|
|
||||||
console.log("chat detect fail :( ", resp.status);
|
|
||||||
|
|
||||||
throw (resp);
|
|
||||||
}
|
|
||||||
|
|
||||||
else { fastify.log.info('game-end info to chat success');
|
|
||||||
console.log("caht detect success :)");
|
|
||||||
// console.log("chat gets:", await resp.json());
|
|
||||||
}
|
|
||||||
return resp;
|
|
||||||
}
|
}
|
||||||
// disable eslint for err catching
|
else {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
fastify.log.info('game-end info to chat success');
|
||||||
catch (e: any) {
|
|
||||||
fastify.log.error(`game-end info to chat failed: ${e}`);
|
|
||||||
}
|
}
|
||||||
};
|
return resp;
|
||||||
|
}
|
||||||
|
// disable eslint for err catching
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
catch (e: any) {
|
||||||
|
fastify.log.error(`game-end info to chat failed: ${e}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -31,13 +31,10 @@ const route: FastifyPluginAsync = async (fastify): Promise<void> => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
async function(req, res) {
|
async function(req, res) {
|
||||||
console.log('herererererererererer');
|
|
||||||
const resp = State.newPausedGame(req.body.user1 as UserId, req.body.user2 as UserId);
|
const resp = State.newPausedGame(req.body.user1 as UserId, req.body.user2 as UserId);
|
||||||
console.log('resp - game id: ',resp );
|
|
||||||
|
|
||||||
if (isNullish(resp)) { return (res.makeResponse(404, 'failure', 'createPausedGame.generic.fail')); }
|
if (isNullish(resp)) { return (res.makeResponse(404, 'failure', 'createPausedGame.generic.fail')); }
|
||||||
// else
|
// else
|
||||||
return (res.makeResponse(200, 'success', 'createPausedGame.success', {gameId: resp}));
|
return (res.makeResponse(200, 'success', 'createPausedGame.success', { gameId: resp }));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -223,12 +223,16 @@ class StateI {
|
||||||
}
|
}
|
||||||
|
|
||||||
public newPausedGame(suid1: string, suid2: string): GameId | undefined {
|
public newPausedGame(suid1: string, suid2: string): GameId | undefined {
|
||||||
|
<<<<<<< HEAD
|
||||||
if (
|
if (
|
||||||
!this.users.has(suid1 as UserId) ||
|
!this.users.has(suid1 as UserId) ||
|
||||||
!this.users.has(suid2 as UserId)
|
!this.users.has(suid2 as UserId)
|
||||||
) {
|
) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
=======
|
||||||
|
|
||||||
|
>>>>>>> 78eb546 (Added U Game system)
|
||||||
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