Compile to ES5 properly
This commit is contained in:
parent
850b8a550b
commit
29282ac17c
10 changed files with 3254 additions and 6578 deletions
35
babel.config.js
Normal file
35
babel.config.js
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
module.exports = function (api) {
|
||||||
|
api.cache(false);
|
||||||
|
const presets = [
|
||||||
|
[ "@babel/preset-typescript"],
|
||||||
|
[
|
||||||
|
"@babel/preset-env",
|
||||||
|
{
|
||||||
|
"corejs": { "version": "3.8" },
|
||||||
|
"useBuiltIns": "usage",
|
||||||
|
"targets": {
|
||||||
|
"edge": "15",
|
||||||
|
"firefox": "51",
|
||||||
|
"chrome": "56",
|
||||||
|
"safari": "11.1",
|
||||||
|
"ie": "11"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
];
|
||||||
|
const plugins = [
|
||||||
|
"@babel/plugin-proposal-class-properties",
|
||||||
|
[
|
||||||
|
"@babel/plugin-transform-runtime",
|
||||||
|
{
|
||||||
|
"corejs": 3,
|
||||||
|
"version": "^7.12.5",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"@babel/plugin-transform-arrow-functions",
|
||||||
|
];
|
||||||
|
return {
|
||||||
|
presets,
|
||||||
|
plugins
|
||||||
|
};
|
||||||
|
};
|
33
package.json
33
package.json
|
@ -3,25 +3,38 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "ChatChat ported to HTML5",
|
"description": "ChatChat ported to HTML5",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "webpack"
|
"build": "webpack",
|
||||||
|
"start": "webpack serve"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"repository": "https://gitdab.com/s/chatchat.git",
|
"repository": "https://gitdab.com/s/chatchat.git",
|
||||||
"author": "Soren",
|
"author": "Aly",
|
||||||
"license": "GPL2",
|
"license": "GPL2",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@babel/core": "^7.12.10",
|
||||||
|
"@babel/plugin-proposal-class-properties": "^7.12.1",
|
||||||
|
"@babel/plugin-transform-arrow-functions": "^7.12.1",
|
||||||
|
"@babel/plugin-transform-runtime": "^7.12.10",
|
||||||
|
"@babel/preset-env": "^7.12.11",
|
||||||
|
"@babel/preset-typescript": "^7.12.7",
|
||||||
|
"@babel/runtime-corejs3": "^7.12.5",
|
||||||
"@types/fontfaceobserver": "^0.0.6",
|
"@types/fontfaceobserver": "^0.0.6",
|
||||||
"css-loader": "^4.3.0",
|
"babel-loader": "^8.2.2",
|
||||||
"file-loader": "^6.1.0",
|
"css-loader": "^5.0.1",
|
||||||
|
"file-loader": "^6.2.0",
|
||||||
"html-webpack-plugin": "^4.5.0",
|
"html-webpack-plugin": "^4.5.0",
|
||||||
"style-loader": "^1.2.1",
|
"style-loader": "^2.0.0",
|
||||||
"ts-loader": "^8.0.4",
|
"ts-loader": "^8.0.12",
|
||||||
"typescript": "^4.0.3",
|
"typescript": "^4.1.3",
|
||||||
"webpack": "^4.44.2",
|
"webpack": "^5.11.0",
|
||||||
"webpack-cli": "^3.3.12"
|
"webpack-cli": "^4.3.0",
|
||||||
|
"webpack-dev-server": "^3.11.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.12.5",
|
||||||
|
"core-js": "^3.8.1",
|
||||||
"fontfaceobserver": "^2.1.0",
|
"fontfaceobserver": "^2.1.0",
|
||||||
"pixi.js": "^5.3.3"
|
"pixi.js": "^5.3.6",
|
||||||
|
"whatwg-fetch": "^3.5.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
import './PlayerIOClient.development';
|
|
||||||
|
|
||||||
export const authenticate = function (
|
|
||||||
gameId: string,
|
|
||||||
connectionId: string,
|
|
||||||
authenticationArguments: Record<string, string>,
|
|
||||||
playerInsightSegments: Array<string>,
|
|
||||||
): Promise<PlayerIO.Client> {
|
|
||||||
return new Promise<PlayerIO.Client>((resolve, reject) => {
|
|
||||||
PlayerIO.authenticate(gameId, connectionId, authenticationArguments, playerInsightSegments, resolve, reject);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export const listRooms = function (
|
|
||||||
multiplayer: PlayerIO.Multiplayer,
|
|
||||||
roomType: string,
|
|
||||||
searchCriteria: Record<string, string>,
|
|
||||||
resultLimit: number,
|
|
||||||
resultOffset: number,
|
|
||||||
): Promise<Array<PlayerIO.RoomInfo>> {
|
|
||||||
return new Promise<Array<PlayerIO.RoomInfo>>((resolve, reject) => {
|
|
||||||
multiplayer.listRooms(roomType, searchCriteria, resultLimit, resultOffset, resolve, reject);
|
|
||||||
});
|
|
||||||
}
|
|
31
src/PlayerIOClient.development.d.ts
vendored
31
src/PlayerIOClient.development.d.ts
vendored
|
@ -1,31 +0,0 @@
|
||||||
declare enum PlayerIOErrorCode {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
declare class PlayerIOError {
|
|
||||||
code: PlayerIOErrorCode;
|
|
||||||
message: string;
|
|
||||||
stack: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare namespace PlayerIO {
|
|
||||||
let useSecureApiRequests: boolean;
|
|
||||||
const authenticate: (gameId: string, connectionId: string, authenticationArguments: Record<string, string>, playerInsightSegments: Array<string>, successCallback: (client: PlayerIO.Client) => void, errorCallback: (error: PlayerIOError) => void) => void;
|
|
||||||
|
|
||||||
class Client {
|
|
||||||
multiplayer: Multiplayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Multiplayer {
|
|
||||||
useSecureConnections: boolean;
|
|
||||||
listRooms: (roomType: string, searchCriteria: Record<string, string>, resultLimit: number, resultOffset: number, successCallback: (rooms: Array<RoomInfo>) => void, errorCallback: (error: PlayerIOError) => void) => void
|
|
||||||
}
|
|
||||||
|
|
||||||
class RoomInfo {
|
|
||||||
id: string;
|
|
||||||
onlineUsers: number;
|
|
||||||
roomData: Record<string, string>;
|
|
||||||
roomType: string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
5081
src/PlayerIOClient.development.js
vendored
5081
src/PlayerIOClient.development.js
vendored
File diff suppressed because it is too large
Load diff
170
src/PlayerIOClient.ts
Normal file
170
src/PlayerIOClient.ts
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
type Settings = {
|
||||||
|
apiRoot: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export const settings: Settings = {
|
||||||
|
apiRoot: "https://api.playerio.com/json/",
|
||||||
|
}
|
||||||
|
|
||||||
|
type KVPair = {
|
||||||
|
key: string,
|
||||||
|
value: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
const map2KV = function(rec: Record<string, any>): Array<KVPair> {
|
||||||
|
return Object.entries(rec).map(([key, value]) => {
|
||||||
|
return {
|
||||||
|
key: key,
|
||||||
|
value: value,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const kv2Map = function(kv: Array<KVPair>): Record<string, any> {
|
||||||
|
let obj: Record<string, any> = {}
|
||||||
|
|
||||||
|
kv.forEach(p => {
|
||||||
|
obj[p.key] = p.value
|
||||||
|
})
|
||||||
|
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
class Channel {
|
||||||
|
token: string | undefined
|
||||||
|
|
||||||
|
call<A>(method: number, args: Record<string, any>, converter: (response: Record<string, any>) => A): Promise<A> {
|
||||||
|
const body = "[" + method + "|" + (this.token || "") + "]" + JSON.stringify(args)
|
||||||
|
|
||||||
|
return fetch(settings.apiRoot, {
|
||||||
|
method: "POST",
|
||||||
|
body: body,
|
||||||
|
}).then(resp => resp.text()).then(resp => {
|
||||||
|
if(resp.startsWith("[")) {
|
||||||
|
const end = resp.indexOf("]")
|
||||||
|
this.token = resp.substring(1, end)
|
||||||
|
resp = resp.substring(end + 1)
|
||||||
|
}
|
||||||
|
return JSON.parse(resp)
|
||||||
|
}).then(result => {
|
||||||
|
return converter(result)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
authenticate(
|
||||||
|
gameId: string,
|
||||||
|
connectionId: string,
|
||||||
|
authenticationArguments: Array<KVPair>,
|
||||||
|
playerInsightSegments: Array<string>,
|
||||||
|
clientApi: string,
|
||||||
|
clientInfo: Array<KVPair>,
|
||||||
|
playCodes: Array<string>,
|
||||||
|
converter: (response: Record<string, any>) => Client
|
||||||
|
): Promise<Client> {
|
||||||
|
return this.call(13, {
|
||||||
|
gameid: gameId,
|
||||||
|
connectionid: connectionId,
|
||||||
|
authenticationarguments: authenticationArguments,
|
||||||
|
playerinsightsegments: playerInsightSegments,
|
||||||
|
clientapi: clientApi,
|
||||||
|
clientinfo: clientInfo,
|
||||||
|
playcodes: playCodes
|
||||||
|
}, converter)
|
||||||
|
}
|
||||||
|
|
||||||
|
listRooms(
|
||||||
|
roomType: string,
|
||||||
|
searchCriteria: Record<string, any>,
|
||||||
|
resultLimit: number,
|
||||||
|
resultOffset: number,
|
||||||
|
onlyDevRooms: boolean,
|
||||||
|
converter: (response: Record<string, any>) => Array<RoomInfo>
|
||||||
|
): Promise<Array<RoomInfo>> {
|
||||||
|
return this.call(30, {
|
||||||
|
roomtype: roomType,
|
||||||
|
searchcriteria: searchCriteria,
|
||||||
|
resultlimit: resultLimit,
|
||||||
|
resultoffset: resultOffset,
|
||||||
|
onlydevrooms: onlyDevRooms
|
||||||
|
}, converter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const authenticate = function (
|
||||||
|
gameId: string,
|
||||||
|
connectionId: string,
|
||||||
|
authenticationArguments: Record<string, string>,
|
||||||
|
playerInsightSegments: Array<string>,
|
||||||
|
): Promise<Client> {
|
||||||
|
const channel = new Channel();
|
||||||
|
return channel.authenticate(
|
||||||
|
gameId,
|
||||||
|
connectionId,
|
||||||
|
map2KV(authenticationArguments),
|
||||||
|
playerInsightSegments,
|
||||||
|
"javascript",
|
||||||
|
map2KV({}),
|
||||||
|
[],
|
||||||
|
(result: Record<string, any>) => {
|
||||||
|
channel.token = result.token;
|
||||||
|
return new Client(channel, gameId, result.gamefsredirectmap, result.userid);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Client {
|
||||||
|
connectUserId: string
|
||||||
|
gameId: string
|
||||||
|
multiplayer: Multiplayer
|
||||||
|
|
||||||
|
constructor(channel: Channel, gameId: string, gameFsRedirectMap: string, userId: string) {
|
||||||
|
this.connectUserId = userId;
|
||||||
|
this.gameId = gameId;
|
||||||
|
|
||||||
|
this.multiplayer = new Multiplayer(channel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Multiplayer {
|
||||||
|
developmentServer: string | null
|
||||||
|
useSecureConnections: boolean
|
||||||
|
|
||||||
|
listRooms: (roomType: string, searchCriteria: Record<string, any>, resultLimit: number, resultOffset: number) => Promise<Array<RoomInfo>>
|
||||||
|
|
||||||
|
constructor(channel: Channel) {
|
||||||
|
this.developmentServer = null
|
||||||
|
this.useSecureConnections = true
|
||||||
|
|
||||||
|
this.listRooms = (roomType: string, searchCriteria: Record<string, any>, resultLimit: number, resultOffset: number) =>
|
||||||
|
channel.listRooms(
|
||||||
|
roomType,
|
||||||
|
map2KV(searchCriteria),
|
||||||
|
resultLimit,
|
||||||
|
resultOffset,
|
||||||
|
this.developmentServer != null,
|
||||||
|
(result: Record<string, any>) =>
|
||||||
|
result.rooms.map((room: any) =>
|
||||||
|
new RoomInfo(
|
||||||
|
room.id,
|
||||||
|
room.roomtype,
|
||||||
|
room.onlineusers,
|
||||||
|
kv2Map(room.roomdata)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RoomInfo {
|
||||||
|
id: string
|
||||||
|
roomType: string
|
||||||
|
onlineUsers: number
|
||||||
|
roomData: Record<string, any>
|
||||||
|
|
||||||
|
constructor(id: string, roomType: string, onlineUsers: number, roomData: Record<string, any>) {
|
||||||
|
this.id = id
|
||||||
|
this.roomType = roomType
|
||||||
|
this.onlineUsers = onlineUsers
|
||||||
|
this.roomData = roomData
|
||||||
|
}
|
||||||
|
}
|
17
src/index.ts
17
src/index.ts
|
@ -1,12 +1,12 @@
|
||||||
|
import "core-js/stable";
|
||||||
|
import "whatwg-fetch";
|
||||||
|
|
||||||
import * as FontFaceObserver from 'fontfaceobserver';
|
import * as FontFaceObserver from 'fontfaceobserver';
|
||||||
|
|
||||||
import * as PIXI from 'pixi.js';
|
import * as PIXI from 'pixi.js';
|
||||||
import './assets/css/chatchat.css';
|
import './assets/css/chatchat.css';
|
||||||
|
|
||||||
import './PlayerIOClient.development';
|
import * as PlayerIO from "./PlayerIOClient";
|
||||||
import * as Pio from "./PlayerIOAsync";
|
|
||||||
|
|
||||||
PlayerIO.useSecureApiRequests = true;
|
|
||||||
|
|
||||||
(async function() {
|
(async function() {
|
||||||
let app = new PIXI.Application({width: 640, height: 600});
|
let app = new PIXI.Application({width: 640, height: 600});
|
||||||
|
@ -26,17 +26,16 @@ PlayerIO.useSecureApiRequests = true;
|
||||||
|
|
||||||
app.stage.addChild(message);
|
app.stage.addChild(message);
|
||||||
|
|
||||||
const cli = await Pio.authenticate(
|
const cli = await PlayerIO.authenticate(
|
||||||
"kittygame-48om7qu7teeazkf9gana",
|
"kittygame-48om7qu7teeazkf9gana",
|
||||||
"public",
|
"public",
|
||||||
{ userId: "soren" },
|
{ userId: "aly" },
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
console.log(cli);
|
console.log(cli);
|
||||||
const multiplayer = cli.multiplayer;
|
const multiplayer = cli.multiplayer;
|
||||||
console.log(multiplayer);
|
console.log(multiplayer);
|
||||||
const rooms = await Pio.listRooms(
|
const rooms = await multiplayer.listRooms(
|
||||||
multiplayer,
|
|
||||||
"KittyRpg2",
|
"KittyRpg2",
|
||||||
{},
|
{},
|
||||||
50,
|
50,
|
||||||
|
@ -44,7 +43,7 @@ PlayerIO.useSecureApiRequests = true;
|
||||||
)
|
)
|
||||||
console.log(rooms);
|
console.log(rooms);
|
||||||
|
|
||||||
let messageN = new PIXI.Text("Hello, world! ββ", chatStyle);
|
let messageN = new PIXI.Text("Hello, world! μ : (A ⊗ A) ⇝ A", chatStyle);
|
||||||
messageN.position.set(32, 32);
|
messageN.position.set(32, 32);
|
||||||
|
|
||||||
app.stage.addChild(messageN);
|
app.stage.addChild(messageN);
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"lib": ["dom", "es2020"],
|
"lib": ["dom"],
|
||||||
"target": "es5",
|
"target": "es5",
|
||||||
"jsx": "react",
|
"strict": true,
|
||||||
"allowJs": true
|
"allowJs": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,15 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: './src/index.ts',
|
entry: {
|
||||||
devtool: 'inline-source-map',
|
app: ['whatwg-fetch', 'core-js/stable', './src/index.ts'],
|
||||||
|
},
|
||||||
|
devtool: 'source-map',
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.tsx?$/,
|
test: /\.ts$/,
|
||||||
use: 'ts-loader',
|
use: 'babel-loader',
|
||||||
exclude: /node_modules/,
|
exclude: /node_modules/,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -28,6 +30,10 @@ module.exports = {
|
||||||
filename: 'main.js',
|
filename: 'main.js',
|
||||||
path: path.resolve(__dirname, 'dist'),
|
path: path.resolve(__dirname, 'dist'),
|
||||||
},
|
},
|
||||||
|
target: ["web", "es5"],
|
||||||
plugins: [new HtmlWebpackPlugin()],
|
plugins: [new HtmlWebpackPlugin()],
|
||||||
|
devServer: {
|
||||||
|
contentBase: './dist',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue