Migrating messages locally into back and front
This commit is contained in:
parent
b4f971c501
commit
d7209d8864
@ -6,7 +6,7 @@ RUN yarn install && yarn proto
|
|||||||
FROM thecodingmachine/nodejs:12
|
FROM thecodingmachine/nodejs:12
|
||||||
|
|
||||||
COPY --chown=docker:docker back .
|
COPY --chown=docker:docker back .
|
||||||
COPY --from=builder --chown=docker:docker /var/www/messages /var/www/messages
|
COPY --from=builder --chown=docker:docker /var/www/messages/generated /var/www/html/src/Messages/generated
|
||||||
RUN yarn install
|
RUN yarn install
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
"body-parser": "^1.19.0",
|
"body-parser": "^1.19.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"generic-type-guard": "^3.2.0",
|
"generic-type-guard": "^3.2.0",
|
||||||
|
"google-protobuf": "^3.13.0",
|
||||||
"http-status-codes": "^1.4.0",
|
"http-status-codes": "^1.4.0",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"prom-client": "^12.0.0",
|
"prom-client": "^12.0.0",
|
||||||
@ -50,6 +51,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/express": "^4.17.4",
|
"@types/express": "^4.17.4",
|
||||||
|
"@types/google-protobuf": "^3.7.3",
|
||||||
"@types/http-status-codes": "^1.2.0",
|
"@types/http-status-codes": "^1.2.0",
|
||||||
"@types/jasmine": "^3.5.10",
|
"@types/jasmine": "^3.5.10",
|
||||||
"@types/jsonwebtoken": "^8.3.8",
|
"@types/jsonwebtoken": "^8.3.8",
|
||||||
|
@ -28,8 +28,8 @@ import {
|
|||||||
SubMessage,
|
SubMessage,
|
||||||
UserMovedMessage,
|
UserMovedMessage,
|
||||||
BatchMessage, GroupUpdateMessage, PointMessage, GroupDeleteMessage
|
BatchMessage, GroupUpdateMessage, PointMessage, GroupDeleteMessage
|
||||||
} from "../../../messages/generated/messages_pb";
|
} from "../Messages/generated/messages_pb";
|
||||||
import {UserMovesMessage} from "../../../messages/generated/messages_pb";
|
import {UserMovesMessage} from "../Messages/generated/messages_pb";
|
||||||
import Direction = PositionMessage.Direction;
|
import Direction = PositionMessage.Direction;
|
||||||
import {ProtobufUtils} from "../Model/Websocket/ProtobufUtils";
|
import {ProtobufUtils} from "../Model/Websocket/ProtobufUtils";
|
||||||
|
|
||||||
|
1
back/src/Messages/.gitignore
vendored
Normal file
1
back/src/Messages/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/generated/
|
@ -3,7 +3,7 @@ import {PointInterface} from "./PointInterface";
|
|||||||
import {Identificable} from "./Identificable";
|
import {Identificable} from "./Identificable";
|
||||||
import {TokenInterface} from "../../Controller/AuthenticateController";
|
import {TokenInterface} from "../../Controller/AuthenticateController";
|
||||||
import {ViewportInterface} from "_Model/Websocket/ViewportMessage";
|
import {ViewportInterface} from "_Model/Websocket/ViewportMessage";
|
||||||
import {BatchMessage, SubMessage} from "../../../../messages/generated/messages_pb";
|
import {BatchMessage, SubMessage} from "../../Messages/generated/messages_pb";
|
||||||
|
|
||||||
export interface ExSocketInterface extends Socket, Identificable {
|
export interface ExSocketInterface extends Socket, Identificable {
|
||||||
token: string;
|
token: string;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import {PointInterface} from "./PointInterface";
|
import {PointInterface} from "./PointInterface";
|
||||||
import {PositionMessage} from "../../../../messages/generated/messages_pb";
|
import {PositionMessage} from "../../Messages/generated/messages_pb";
|
||||||
import {ExSocketInterface} from "_Model/Websocket/ExSocketInterface";
|
import {ExSocketInterface} from "_Model/Websocket/ExSocketInterface";
|
||||||
import Direction = PositionMessage.Direction;
|
import Direction = PositionMessage.Direction;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
"downlevelIteration": true,
|
"downlevelIteration": true,
|
||||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
"allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
// "checkJs": true, /* Report errors in .js files. */
|
// "checkJs": true, /* Report errors in .js files. */
|
||||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||||
|
@ -57,6 +57,11 @@
|
|||||||
"@types/qs" "*"
|
"@types/qs" "*"
|
||||||
"@types/serve-static" "*"
|
"@types/serve-static" "*"
|
||||||
|
|
||||||
|
"@types/google-protobuf@^3.7.3":
|
||||||
|
version "3.7.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/google-protobuf/-/google-protobuf-3.7.3.tgz#429512e541bbd777f2c867692e6335ee08d1f6d4"
|
||||||
|
integrity sha512-FRwj40euE2bYkG+0X5w2nEA8yAzgJRcEa7RBd0Gsdkb9/tPM2pctVVAvnOUTbcXo2VmIHPo0Ae94Gl9vRHfKzg==
|
||||||
|
|
||||||
"@types/http-status-codes@^1.2.0":
|
"@types/http-status-codes@^1.2.0":
|
||||||
version "1.2.0"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/@types/http-status-codes/-/http-status-codes-1.2.0.tgz#6e5244835aaf7164dd306f1d4d2dfdbb2159d909"
|
resolved "https://registry.yarnpkg.com/@types/http-status-codes/-/http-status-codes-1.2.0.tgz#6e5244835aaf7164dd306f1d4d2dfdbb2159d909"
|
||||||
@ -822,6 +827,11 @@ globals@^12.1.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
type-fest "^0.8.1"
|
type-fest "^0.8.1"
|
||||||
|
|
||||||
|
google-protobuf@^3.13.0:
|
||||||
|
version "3.13.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.13.0.tgz#909c5983d75dd6101ed57c79e0528d000cdc3251"
|
||||||
|
integrity sha512-ZIf3qfLFayVrPvAjeKKxO5FRF1/NwRxt6Dko+fWEMuHwHbZx8/fcaAao9b0wCM6kr8qeg2te8XTpyuvKuD9aKw==
|
||||||
|
|
||||||
graceful-fs@^4.1.2:
|
graceful-fs@^4.1.2:
|
||||||
version "4.2.3"
|
version "4.2.3"
|
||||||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.3.tgz#4a12ff1b60376ef09862c2093edd908328be8423"
|
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.3.tgz#4a12ff1b60376ef09862c2093edd908328be8423"
|
||||||
|
@ -33,7 +33,6 @@ services:
|
|||||||
command: yarn run start
|
command: yarn run start
|
||||||
volumes:
|
volumes:
|
||||||
- ./front:/usr/src/app
|
- ./front:/usr/src/app
|
||||||
- ./messages:/usr/src/messages/
|
|
||||||
labels:
|
labels:
|
||||||
- "traefik.http.routers.front.rule=Host(`play.workadventure.localhost`)"
|
- "traefik.http.routers.front.rule=Host(`play.workadventure.localhost`)"
|
||||||
- "traefik.http.routers.front.entryPoints=web,traefik"
|
- "traefik.http.routers.front.entryPoints=web,traefik"
|
||||||
@ -76,7 +75,6 @@ services:
|
|||||||
ALLOW_ARTILLERY: "true"
|
ALLOW_ARTILLERY: "true"
|
||||||
volumes:
|
volumes:
|
||||||
- ./back:/usr/src/app
|
- ./back:/usr/src/app
|
||||||
- ./messages:/usr/src/messages/
|
|
||||||
labels:
|
labels:
|
||||||
- "traefik.http.routers.back.rule=Host(`api.workadventure.localhost`)"
|
- "traefik.http.routers.back.rule=Host(`api.workadventure.localhost`)"
|
||||||
- "traefik.http.routers.back.entryPoints=web"
|
- "traefik.http.routers.back.entryPoints=web"
|
||||||
@ -111,3 +109,5 @@ services:
|
|||||||
STARTUP_COMMAND_2: yarn run proto:watch
|
STARTUP_COMMAND_2: yarn run proto:watch
|
||||||
volumes:
|
volumes:
|
||||||
- ./messages:/usr/src/app
|
- ./messages:/usr/src/app
|
||||||
|
- ./back:/usr/src/back
|
||||||
|
- ./front:/usr/src/front
|
||||||
|
@ -7,7 +7,7 @@ RUN yarn install && yarn proto
|
|||||||
FROM thecodingmachine/nodejs:14-apache
|
FROM thecodingmachine/nodejs:14-apache
|
||||||
|
|
||||||
COPY --chown=docker:docker front .
|
COPY --chown=docker:docker front .
|
||||||
COPY --from=builder --chown=docker:docker /var/www/messages /var/www/messages
|
COPY --from=builder --chown=docker:docker /var/www/messages/generated /var/www/html/src/Messages/generated
|
||||||
RUN yarn install
|
RUN yarn install
|
||||||
|
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"license": "SEE LICENSE IN LICENSE.txt",
|
"license": "SEE LICENSE IN LICENSE.txt",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/google-protobuf": "^3.7.3",
|
||||||
"@types/jasmine": "^3.5.10",
|
"@types/jasmine": "^3.5.10",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.26.0",
|
"@typescript-eslint/eslint-plugin": "^2.26.0",
|
||||||
"@typescript-eslint/parser": "^2.26.0",
|
"@typescript-eslint/parser": "^2.26.0",
|
||||||
@ -23,6 +24,7 @@
|
|||||||
"@types/simple-peer": "^9.6.0",
|
"@types/simple-peer": "^9.6.0",
|
||||||
"@types/socket.io-client": "^1.4.32",
|
"@types/socket.io-client": "^1.4.32",
|
||||||
"generic-type-guard": "^3.2.0",
|
"generic-type-guard": "^3.2.0",
|
||||||
|
"google-protobuf": "^3.13.0",
|
||||||
"phaser": "^3.22.0",
|
"phaser": "^3.22.0",
|
||||||
"queue-typescript": "^1.0.1",
|
"queue-typescript": "^1.0.1",
|
||||||
"simple-peer": "^9.6.2",
|
"simple-peer": "^9.6.2",
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
SetPlayerDetailsMessage, UserMovedMessage,
|
SetPlayerDetailsMessage, UserMovedMessage,
|
||||||
UserMovesMessage,
|
UserMovesMessage,
|
||||||
ViewportMessage
|
ViewportMessage
|
||||||
} from "../../messages/generated/messages_pb"
|
} from "./Messages/generated/messages_pb"
|
||||||
|
|
||||||
const SocketIo = require('socket.io-client');
|
const SocketIo = require('socket.io-client');
|
||||||
import Socket = SocketIOClient.Socket;
|
import Socket = SocketIOClient.Socket;
|
||||||
|
1
front/src/Messages/.gitignore
vendored
Normal file
1
front/src/Messages/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/generated/
|
@ -1,4 +1,4 @@
|
|||||||
import {PositionMessage} from "../../../messages/generated/messages_pb";
|
import {PositionMessage} from "../Messages/generated/messages_pb";
|
||||||
import {PointInterface} from "../Connection";
|
import {PointInterface} from "../Connection";
|
||||||
import Direction = PositionMessage.Direction;
|
import Direction = PositionMessage.Direction;
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ import {FourOFourSceneName} from "../Reconnecting/FourOFourScene";
|
|||||||
import {ItemFactoryInterface} from "../Items/ItemFactoryInterface";
|
import {ItemFactoryInterface} from "../Items/ItemFactoryInterface";
|
||||||
import {ActionableItem} from "../Items/ActionableItem";
|
import {ActionableItem} from "../Items/ActionableItem";
|
||||||
import {UserInputManager} from "../UserInput/UserInputManager";
|
import {UserInputManager} from "../UserInput/UserInputManager";
|
||||||
import {UserMovedMessage} from "../../../../messages/generated/messages_pb";
|
import {UserMovedMessage} from "../../Messages/generated/messages_pb";
|
||||||
import {ProtobufClientUtils} from "../../Network/ProtobufClientUtils";
|
import {ProtobufClientUtils} from "../../Network/ProtobufClientUtils";
|
||||||
|
|
||||||
|
|
||||||
@ -220,6 +220,7 @@ export class GameScene extends Phaser.Scene implements CenterListener {
|
|||||||
if (position === undefined) {
|
if (position === undefined) {
|
||||||
throw new Error('Position missing from UserMovedMessage');
|
throw new Error('Position missing from UserMovedMessage');
|
||||||
}
|
}
|
||||||
|
//console.log('Received position ', position.getX(), position.getY(), "from user", message.getUserid());
|
||||||
|
|
||||||
const messageUserMoved: MessageUserMovedInterface = {
|
const messageUserMoved: MessageUserMovedInterface = {
|
||||||
userId: message.getUserid(),
|
userId: message.getUserid(),
|
||||||
@ -1079,6 +1080,7 @@ export class GameScene extends Phaser.Scene implements CenterListener {
|
|||||||
// We do not update the player position directly (because it is sent only every 200ms).
|
// We do not update the player position directly (because it is sent only every 200ms).
|
||||||
// Instead we use the PlayersPositionInterpolator that will do a smooth animation over the next 200ms.
|
// Instead we use the PlayersPositionInterpolator that will do a smooth animation over the next 200ms.
|
||||||
const playerMovement = new PlayerMovement({ x: player.x, y: player.y }, this.currentTick, message.position, this.currentTick + POSITION_DELAY);
|
const playerMovement = new PlayerMovement({ x: player.x, y: player.y }, this.currentTick, message.position, this.currentTick + POSITION_DELAY);
|
||||||
|
//console.log('Target position: ', player.x, player.y);
|
||||||
this.playersPositionInterpolator.updatePlayerPosition(player.userId, playerMovement);
|
this.playersPositionInterpolator.updatePlayerPosition(player.userId, playerMovement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,12 +20,13 @@ export class PlayerMovement {
|
|||||||
public getPosition(tick: number): HasMovedEvent {
|
public getPosition(tick: number): HasMovedEvent {
|
||||||
// Special case: end position reached and end position is not moving
|
// Special case: end position reached and end position is not moving
|
||||||
if (tick >= this.endTick && this.endPosition.moving === false) {
|
if (tick >= this.endTick && this.endPosition.moving === false) {
|
||||||
|
//console.log('Movement finished ', this.endPosition)
|
||||||
return this.endPosition;
|
return this.endPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
const x = (this.endPosition.x - this.startPosition.x) * ((tick - this.startTick) / (this.endTick - this.startTick)) + this.startPosition.x;
|
const x = (this.endPosition.x - this.startPosition.x) * ((tick - this.startTick) / (this.endTick - this.startTick)) + this.startPosition.x;
|
||||||
const y = (this.endPosition.y - this.startPosition.y) * ((tick - this.startTick) / (this.endTick - this.startTick)) + this.startPosition.y;
|
const y = (this.endPosition.y - this.startPosition.y) * ((tick - this.startTick) / (this.endTick - this.startTick)) + this.startPosition.y;
|
||||||
|
//console.log('Computed position ', x, y)
|
||||||
return {
|
return {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
|
@ -66,6 +66,11 @@
|
|||||||
"@types/minimatch" "*"
|
"@types/minimatch" "*"
|
||||||
"@types/node" "*"
|
"@types/node" "*"
|
||||||
|
|
||||||
|
"@types/google-protobuf@^3.7.3":
|
||||||
|
version "3.7.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/google-protobuf/-/google-protobuf-3.7.3.tgz#429512e541bbd777f2c867692e6335ee08d1f6d4"
|
||||||
|
integrity sha512-FRwj40euE2bYkG+0X5w2nEA8yAzgJRcEa7RBd0Gsdkb9/tPM2pctVVAvnOUTbcXo2VmIHPo0Ae94Gl9vRHfKzg==
|
||||||
|
|
||||||
"@types/html-minifier-terser@^5.0.0":
|
"@types/html-minifier-terser@^5.0.0":
|
||||||
version "5.1.0"
|
version "5.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/@types/html-minifier-terser/-/html-minifier-terser-5.1.0.tgz#551a4589b6ee2cc9c1dff08056128aec29b94880"
|
resolved "https://registry.yarnpkg.com/@types/html-minifier-terser/-/html-minifier-terser-5.1.0.tgz#551a4589b6ee2cc9c1dff08056128aec29b94880"
|
||||||
@ -2237,6 +2242,11 @@ globby@^6.1.0:
|
|||||||
pify "^2.0.0"
|
pify "^2.0.0"
|
||||||
pinkie-promise "^2.0.0"
|
pinkie-promise "^2.0.0"
|
||||||
|
|
||||||
|
google-protobuf@^3.13.0:
|
||||||
|
version "3.13.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/google-protobuf/-/google-protobuf-3.13.0.tgz#909c5983d75dd6101ed57c79e0528d000cdc3251"
|
||||||
|
integrity sha512-ZIf3qfLFayVrPvAjeKKxO5FRF1/NwRxt6Dko+fWEMuHwHbZx8/fcaAao9b0wCM6kr8qeg2te8XTpyuvKuD9aKw==
|
||||||
|
|
||||||
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2:
|
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2:
|
||||||
version "4.2.4"
|
version "4.2.4"
|
||||||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
|
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
|
||||||
|
@ -5,7 +5,10 @@
|
|||||||
"main": "generated/src/proto/messages_pb.js",
|
"main": "generated/src/proto/messages_pb.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"proto": "protoc --plugin=\"protoc-gen-ts=./node_modules/.bin/protoc-gen-ts\" --js_out=\"import_style=commonjs,binary:generated\" --ts_out=\"generated\" messages.proto",
|
"proto": "protoc --plugin=\"protoc-gen-ts=./node_modules/.bin/protoc-gen-ts\" --js_out=\"import_style=commonjs,binary:generated\" --ts_out=\"generated\" messages.proto",
|
||||||
"proto:watch": "yarn run proto || inotifywait -q -m -e close_write messages.proto | while read -r filename event; do yarn run proto; done"
|
"copy-to-back": "rm -rf ../back/src/Messages/generated && cp -rf generated/ ../back/src/Messages/generated",
|
||||||
|
"copy-to-front": "rm -rf ../front/src/Messages/generated && cp -rf generated/ ../front/src/Messages/generated",
|
||||||
|
"proto-all": "yarn run proto && yarn run copy-to-back && yarn run copy-to-front",
|
||||||
|
"proto:watch": "yarn run proto-all; inotifywait -q -m -e close_write messages.proto | while read -r filename event; do yarn run proto-all; done"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
Loading…
Reference in New Issue
Block a user