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 {
|
||||
if (window.__state.chatSock === undefined)
|
||||
window.__state.chatSock = io(window.location.host, {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,5 @@ import { addMessage } from './addMessage';
|
|||
export function inviteToPlayPong(profil: ClientProfil, senderSocket: Socket) {
|
||||
profil.SenderName = getUser()?.name ?? '';
|
||||
if (profil.SenderName === profil.user) return;
|
||||
addMessage(`You invited to play: ${profil.user}🏓`)
|
||||
senderSocket.emit('inviteGame', JSON.stringify(profil));
|
||||
};
|
||||
|
|
@ -235,7 +235,7 @@ if (!window.__state._routingHandler) {
|
|||
|
||||
if (sameOrigin) {
|
||||
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
|
||||
* @interface {{classname}}
|
||||
*/
|
||||
|
|
@ -9,7 +9,7 @@ export interface {{classname}} {{#parent}}extends {{{.}}} {{/parent}}{
|
|||
{{/additionalPropertiesType}}
|
||||
{{#vars}}
|
||||
/**
|
||||
* {{#lambda.indented_star_4}}{{{unescapedDescription}}}{{/lambda.indented_star_4}}
|
||||
* {{#lambda.indented_star_4}}{{{unedDescription}}}{{/lambda.indented_star_4}}
|
||||
* @type {{=<% %>=}}{<%&datatype%>}<%={{ }}=%>
|
||||
* @memberof {{classname}}
|
||||
{{#deprecated}}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ export function isNullish<T>(v: T | undefined | null): v is null | undefined {
|
|||
return v === null || v === undefined;
|
||||
}
|
||||
|
||||
export function escape(s: string): string {
|
||||
export function e(s: string): string {
|
||||
return s.replace(
|
||||
/[^0-9A-Za-z ]/g,
|
||||
c => '&#' + c.charCodeAt(0) + ';',
|
||||
|
|
|
|||
|
|
@ -18,10 +18,9 @@ import { makeProfil } from './chatBackHelperFunctions/makeProfil';
|
|||
import { isBlocked } from './chatBackHelperFunctions/isBlocked';
|
||||
import { sendProfil } from './chatBackHelperFunctions/sendProfil';
|
||||
import { setGameLink } from './setGameLink';
|
||||
//import { nextGame_SocketListener } from './nextGame_SocketListener';
|
||||
import { list_SocketListener } from './chatBackHelperFunctions/list_SocketListener';
|
||||
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;
|
||||
|
|
@ -103,7 +102,7 @@ async function onReady(fastify: FastifyInstance) {
|
|||
broadcast(fastify, obj, obj.SenderWindowID);
|
||||
fastify.log.info(`Client connected: ${socket.id}`);
|
||||
});
|
||||
//nextGame_SocketListener(fastify, socket);
|
||||
|
||||
list_SocketListener(fastify, socket);
|
||||
|
||||
socket.on('updateClientName', (object) => {
|
||||
|
|
@ -217,13 +216,11 @@ async function onReady(fastify: FastifyInstance) {
|
|||
socket.on('inviteGame', async (data: string) => {
|
||||
const clientName: string = clientChat.get(socket.id)?.user || '';
|
||||
const profilInvite: ClientProfil = JSON.parse(data) || '';
|
||||
const linkGame: Response | undefined = await setGameLink(fastify);
|
||||
const linkGame: Response | undefined = await setGameLink(fastify, data);
|
||||
if (!linkGame) return;
|
||||
const tmp: any = await linkGame?.json();
|
||||
const link: string = `'<a href=\'https://localhost:8888/pong?game=${tmp.payload.gameId}\' style=\'color: blue; text-decoration: underline; cursor: pointer;\'>Click me</a>'`;
|
||||
|
||||
console.log(link);
|
||||
const inviteHtml: string = 'invites you to a game' + link;
|
||||
const tmp: inviteUserTOGame = await linkGame?.json() as inviteUserTOGame;
|
||||
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;
|
||||
if (clientName !== null) {
|
||||
sendInvite(fastify, inviteHtml, profilInvite);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import type { ClientProfil } from '../chat_types';
|
|||
import type { User } from '@shared/database/mixin/user';
|
||||
import { getUserByName } from './getUserByName';
|
||||
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
|
||||
|
|
@ -32,7 +32,7 @@ export async function makeProfil(fastify: FastifyInstance, user: string, socket:
|
|||
user: `${allUsers.name}`,
|
||||
loginName: loginState,
|
||||
userID: `${allUsers?.id ?? ''}`,
|
||||
text: escape(allUsers.desc),
|
||||
text: e(allUsers.desc),
|
||||
timestamp: Date.now(),
|
||||
SenderWindowID: socket.id,
|
||||
SenderName: '',
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ export async function sendInvite(fastify: FastifyInstance, innerHtml: string, pr
|
|||
const sockets = await fastify.io.fetchSockets();
|
||||
let targetSocket;
|
||||
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;
|
||||
if (!targetSocket) continue;
|
||||
if (clientInfo === profil.user) {
|
||||
|
|
@ -36,12 +36,12 @@ export async function sendInvite(fastify: FastifyInstance, innerHtml: string, pr
|
|||
command: `@${clientInfo}`,
|
||||
destination: 'inviteMsg',
|
||||
type: 'chat',
|
||||
user: profil.SenderName,
|
||||
user: profil.user,
|
||||
token: '',
|
||||
text: getGameNumber(),
|
||||
timestamp: Date.now(),
|
||||
SenderWindowID: socket.id,
|
||||
userID: '',
|
||||
userID: profil.userID,
|
||||
frontendUserName: '',
|
||||
frontendUser: '',
|
||||
SenderUserName: profil.SenderName,
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ export async function sendPrivMessage(fastify: FastifyInstance, data: ClientMess
|
|||
|
||||
for (const socket of sockets) {
|
||||
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 clientInfo = clientChat.get(socket.id);
|
||||
if (!clientInfo) continue;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ export type ClientMessage = {
|
|||
innerHtml?: string,
|
||||
};
|
||||
|
||||
|
||||
export type ClientProfil = {
|
||||
command: string,
|
||||
destination: string,
|
||||
|
|
@ -35,7 +34,6 @@ export type ClientProfil = {
|
|||
|
||||
};
|
||||
|
||||
|
||||
export interface ClientInfo {
|
||||
user: string;
|
||||
socket: string
|
||||
|
|
@ -49,21 +47,11 @@ export type blockedUnBlocked =
|
|||
by: string,
|
||||
};
|
||||
|
||||
|
||||
// export type obj =
|
||||
// {
|
||||
// command: string,
|
||||
// destination: string,
|
||||
// type: string,
|
||||
// user: string,
|
||||
// frontendUserName: string,
|
||||
// frontendUser: string,
|
||||
// token: string,
|
||||
// text: string,
|
||||
// timestamp: number,
|
||||
// SenderWindowID: string,
|
||||
// Sendertext: string,
|
||||
// };
|
||||
export type inviteUserTOGame = {
|
||||
user1: string,
|
||||
user2: string,
|
||||
gameId: string
|
||||
}
|
||||
|
||||
export type BlockRelation = {
|
||||
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,27 +1,23 @@
|
|||
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 {
|
||||
const resp = await fetch('http://app-pong/api/pong/createPausedGame', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-type': 'application/json' },
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
|
||||
if (!resp.ok) {
|
||||
|
||||
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());
|
||||
else {
|
||||
fastify.log.info('game-end info to chat success');
|
||||
}
|
||||
return resp;
|
||||
}
|
||||
|
|
@ -30,4 +26,4 @@ export async function setGameLink(fastify: FastifyInstance): Promise<Response |
|
|||
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) {
|
||||
console.log('herererererererererer');
|
||||
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')); }
|
||||
// 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 {
|
||||
<<<<<<< HEAD
|
||||
if (
|
||||
!this.users.has(suid1 as UserId) ||
|
||||
!this.users.has(suid2 as UserId)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
=======
|
||||
|
||||
>>>>>>> 78eb546 (Added U Game system)
|
||||
const uid1: UserId = suid1 as UserId;
|
||||
const uid2: UserId = suid2 as UserId;
|
||||
const g = new Pong(uid1, uid2);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue