First commit
This commit is contained in:
commit
e101a4a45a
22 changed files with 4343 additions and 0 deletions
10
.editorconfig
Normal file
10
.editorconfig
Normal file
|
@ -0,0 +1,10 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[*.{js,json,yml}]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
/.yarn/** linguist-vendored
|
||||
/.yarn/releases/* binary
|
||||
/.yarn/plugins/**/* binary
|
||||
/.pnp.* binary linguist-generated
|
17
.gitignore
vendored
Normal file
17
.gitignore
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
**/.yarn/*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/sdks
|
||||
!.yarn/versions
|
||||
|
||||
# Swap the comments on the following lines if you wish to use zero-installs
|
||||
# In that case, don't forget to run `yarn config set enableGlobalCache false`!
|
||||
# Documentation here: https://yarnpkg.com/features/caching#zero-installs
|
||||
|
||||
#!.yarn/cache
|
||||
**/.pnp.*
|
||||
node_modules/
|
||||
**/dist/
|
||||
**/.parcel-cache/
|
1
.yarnrc.yml
Normal file
1
.yarnrc.yml
Normal file
|
@ -0,0 +1 @@
|
|||
nodeLinker: node-modules
|
1
README.md
Normal file
1
README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# msagent-chat
|
8
package.json
Normal file
8
package.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "msagent-chat",
|
||||
"workspaces": [
|
||||
"server",
|
||||
"webapp"
|
||||
],
|
||||
"packageManager": "yarn@4.2.2"
|
||||
}
|
45
protocol/protocol.ts
Normal file
45
protocol/protocol.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
export enum MSAgentProtocolMessageType {
|
||||
// Client-to-server
|
||||
Join = "join",
|
||||
Talk = "talk",
|
||||
// Server-to-client
|
||||
AddUser = "adduser",
|
||||
RemoveUser = "remuser",
|
||||
Message = "msg"
|
||||
}
|
||||
|
||||
export interface MSAgentProtocolMessage {
|
||||
op: MSAgentProtocolMessageType
|
||||
}
|
||||
|
||||
// Client-to-server
|
||||
|
||||
export interface MSAgentJoinMessage extends MSAgentProtocolMessage {
|
||||
op: MSAgentProtocolMessageType.Join,
|
||||
data: {
|
||||
username: string;
|
||||
}
|
||||
}
|
||||
|
||||
export interface MSAgentTalkMessage extends MSAgentProtocolMessage {
|
||||
op: MSAgentProtocolMessageType.Talk,
|
||||
data: {
|
||||
msg: string;
|
||||
}
|
||||
}
|
||||
|
||||
// Server-to-client
|
||||
|
||||
export interface MSAgentAddUserMessage extends MSAgentProtocolMessage {
|
||||
op: MSAgentProtocolMessageType.AddUser,
|
||||
data: {
|
||||
username: string;
|
||||
}
|
||||
}
|
||||
|
||||
export interface MSAgentRemoveUserMessage extends MSAgentProtocolMessage {
|
||||
op: MSAgentProtocolMessageType.RemoveUser,
|
||||
data: {
|
||||
username: string;
|
||||
}
|
||||
}
|
1
server/README.md
Normal file
1
server/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# msagent-chat-server
|
18
server/package.json
Normal file
18
server/package.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "msagent-chat-server",
|
||||
"scripts": {
|
||||
"build": "tsc"
|
||||
},
|
||||
"packageManager": "yarn@4.2.2",
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.14.9",
|
||||
"@types/ws": "^8.5.10",
|
||||
"typescript": "^5.5.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fastify/websocket": "^10.0.1",
|
||||
"fastify": "^4.28.1",
|
||||
"ws": "^8.17.1"
|
||||
},
|
||||
"type": "module"
|
||||
}
|
27
server/src/client.ts
Normal file
27
server/src/client.ts
Normal file
|
@ -0,0 +1,27 @@
|
|||
import EventEmitter from "events";
|
||||
import { WebSocket } from "ws";
|
||||
|
||||
export class Client extends EventEmitter {
|
||||
username: string | null;
|
||||
socket: WebSocket;
|
||||
constructor(socket: WebSocket) {
|
||||
super();
|
||||
this.socket = socket;
|
||||
this.username = null;
|
||||
this.socket.on('message', (msg, isBinary) => {
|
||||
if (isBinary) {
|
||||
this.socket.close();
|
||||
return;
|
||||
}
|
||||
this.parseMessage(msg.toString("utf-8"));
|
||||
});
|
||||
this.socket.on('error', () => {});
|
||||
this.socket.on('close', () => {
|
||||
this.emit('close');
|
||||
});
|
||||
}
|
||||
|
||||
private parseMessage(msg: string) {
|
||||
|
||||
}
|
||||
}
|
20
server/src/index.ts
Normal file
20
server/src/index.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import Fastify from 'fastify';
|
||||
import FastifyWS from '@fastify/websocket';
|
||||
import { Client } from './client.js';
|
||||
|
||||
const app = Fastify({
|
||||
logger: true,
|
||||
});
|
||||
|
||||
app.register(FastifyWS);
|
||||
|
||||
app.get("/socket", {websocket: true}, (socket, req) => {
|
||||
let client = new Client(socket);
|
||||
});
|
||||
|
||||
let port;
|
||||
if (process.argv.length < 3 || isNaN(port = parseInt(process.argv[2]))) {
|
||||
console.error("Usage: index.js [port]");
|
||||
process.exit(1);
|
||||
}
|
||||
app.listen({host: "127.0.0.1", port});
|
16
server/src/room.ts
Normal file
16
server/src/room.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { Client } from "./client.js";
|
||||
|
||||
export class MSAgentChatRoom {
|
||||
clients: Client[];
|
||||
|
||||
constructor() {
|
||||
this.clients = [];
|
||||
}
|
||||
|
||||
addClient(client: Client) {
|
||||
this.clients.push(client);
|
||||
client.on('close', () => {
|
||||
this.clients.splice(this.clients.indexOf(client), 1);
|
||||
});
|
||||
}
|
||||
}
|
108
server/tsconfig.json
Normal file
108
server/tsconfig.json
Normal file
|
@ -0,0 +1,108 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "es2022", /* Specify what module code is generated. */
|
||||
"rootDir": "./src", /* Specify the root folder within your source files. */
|
||||
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
||||
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
||||
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
||||
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
||||
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
1
webapp/README.md
Normal file
1
webapp/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# msagent-chat-webapp
|
BIN
webapp/assets/fonts/micross.ttf
Normal file
BIN
webapp/assets/fonts/micross.ttf
Normal file
Binary file not shown.
17
webapp/package.json
Normal file
17
webapp/package.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "msagent-chat-webapp",
|
||||
"scripts": {
|
||||
"build": "parcel build --no-source-maps --dist-dir dist --public-url '.' src/html/index.html",
|
||||
"serve": "parcel src/html/index.html",
|
||||
"clean": "run-script-os",
|
||||
"clean:darwin:linux": "rm -rf dist .parcel-cache",
|
||||
"clean:win32": "rd /s /q dist .parcel-cache"
|
||||
},
|
||||
"packageManager": "yarn@4.2.2",
|
||||
"devDependencies": {
|
||||
"@parcel/core": "^2.12.0",
|
||||
"parcel": "^2.12.0",
|
||||
"run-script-os": "^1.1.6",
|
||||
"typescript": "^5.5.3"
|
||||
}
|
||||
}
|
112
webapp/src/css/style.css
Normal file
112
webapp/src/css/style.css
Normal file
|
@ -0,0 +1,112 @@
|
|||
@font-face {
|
||||
font-family: "MS Sans Serif";
|
||||
src: url("../../assets/fonts/micross.ttf") format("truetype")
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: "MS Sans Serif", sans-serif;
|
||||
background-color: #3A6EA5;
|
||||
font-size: 8pt;
|
||||
}
|
||||
|
||||
#logonView {
|
||||
display: block;
|
||||
}
|
||||
|
||||
#chatView {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.ms-window {
|
||||
display: none;
|
||||
background-color: #d4d0c8;
|
||||
position: fixed;
|
||||
.ms-window-titlebar {
|
||||
background-image: linear-gradient(to right, #0a246a, #a6caf0);
|
||||
margin: 4px;
|
||||
color: #ffffff;
|
||||
user-select: none;
|
||||
font-weight: bold;
|
||||
font-size: 12pt;
|
||||
}
|
||||
.ms-window-body {
|
||||
margin-right: 4px;
|
||||
margin-left: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
#logonWindowLogo {
|
||||
background-color: #ffffff;
|
||||
margin: 0;
|
||||
padding-top: 2.5rem;
|
||||
padding-bottom: 2.5rem;
|
||||
border-bottom: 8px solid;
|
||||
border-image: linear-gradient(to right, #013755, #9ec0da, #013755) 4;
|
||||
* {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
#logonForm {
|
||||
margin-top: 25px;
|
||||
margin-left: 15px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
div {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
}
|
||||
|
||||
#logonUsername, #logonRoom {
|
||||
align-self: flex-end;
|
||||
margin-left: auto;
|
||||
width: 300px;
|
||||
margin-right: 90px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
#logonButton {
|
||||
align-self: flex-end;
|
||||
margin-left: auto;
|
||||
margin-right: 90px;
|
||||
}
|
||||
|
||||
button, input {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #d4d0c8;
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
input[type="text"]:focus-visible {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
#chatBar {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
position: fixed;
|
||||
bottom: 4px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 4vh;
|
||||
}
|
||||
|
||||
#chatInput {
|
||||
flex-grow: 1;
|
||||
margin-right: 4px;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
#chatSentBtn {
|
||||
font-weight: bold;
|
||||
margin-right: 4px;
|
||||
}
|
44
webapp/src/html/index.html
Normal file
44
webapp/src/html/index.html
Normal file
|
@ -0,0 +1,44 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" prefix="og: https://ogp.me/ns#">
|
||||
<head>
|
||||
<title>MSAgent Chat</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta property="og:title" content="MSAgent Chat" />
|
||||
<meta property="og:type" content="website" />
|
||||
<meta property="og:site_name" content="Computernewb's Internet Pub Hub" />
|
||||
<link type="text/css" rel="stylesheet" href="../css/style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="logonView">
|
||||
<div class="ms-window" id="logonWindow">
|
||||
<div class="ms-window-titlebar">Log on to MSAgent Chat</div>
|
||||
<div class="ms-window-body">
|
||||
<div id="logonWindowLogo">
|
||||
<center><h1>MSAgent Chat Placeholder Logo</h1></center>
|
||||
</div>
|
||||
<form id="logonForm">
|
||||
<div id="logonUsernameContainer">
|
||||
<label for="logonUsername">User name:</label>
|
||||
<input type="text" id="logonUsername" required/>
|
||||
</div>
|
||||
<div id="logonRoomContainer">
|
||||
<label for="logonRoom">Room name:</label>
|
||||
<input type="text" id="logonRoom" placeholder="Optional"/>
|
||||
</div>
|
||||
<div id="logonButtonsContainer">
|
||||
<button type="submit" id="logonButton">Log on</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="chatView">
|
||||
<div id="chatBar">
|
||||
<input type="text" id="chatInput" placeholder="Send a message"/>
|
||||
<button id="chatSendBtn">Send</button>
|
||||
</div>
|
||||
</div>
|
||||
<script type="module" src="../ts/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
87
webapp/src/ts/MSWindow.ts
Normal file
87
webapp/src/ts/MSWindow.ts
Normal file
|
@ -0,0 +1,87 @@
|
|||
export interface MSWindowConfig {
|
||||
width: number,
|
||||
height: number,
|
||||
hasClose: boolean;
|
||||
startPosition: MSWindowStartPosition
|
||||
}
|
||||
|
||||
export enum MSWindowStartPosition {
|
||||
TopLeft,
|
||||
Center
|
||||
}
|
||||
|
||||
export class MSWindow {
|
||||
wnd: HTMLDivElement;
|
||||
config: MSWindowConfig;
|
||||
titlebar: HTMLDivElement;
|
||||
body: HTMLDivElement;
|
||||
shown: boolean;
|
||||
dragging: boolean;
|
||||
x: number;
|
||||
y: number;
|
||||
constructor(wnd: HTMLDivElement, config: MSWindowConfig) {
|
||||
this.shown = false;
|
||||
this.wnd = wnd;
|
||||
this.config = config;
|
||||
this.wnd.style.width = config.width + "px";
|
||||
this.wnd.style.height = config.height + "px";
|
||||
let titlebar = this.wnd.querySelector("div.ms-window-titlebar");
|
||||
let body = this.wnd.querySelector("div.ms-window-body");
|
||||
if (!titlebar || !body)
|
||||
throw new Error("MSWindow is missing titlebar or body element.");
|
||||
this.titlebar = titlebar as HTMLDivElement;
|
||||
this.body = body as HTMLDivElement;
|
||||
// Register window move handlers
|
||||
this.dragging = false;
|
||||
switch (this.config.startPosition) {
|
||||
case MSWindowStartPosition.TopLeft: {
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
break;
|
||||
}
|
||||
case MSWindowStartPosition.Center: {
|
||||
this.x = (document.documentElement.clientWidth / 2) - (this.config.width / 2);
|
||||
this.y = (document.documentElement.clientHeight / 2) - (this.config.height / 2);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error("Invalid start position");
|
||||
}
|
||||
}
|
||||
this.setLoc();
|
||||
this.titlebar.addEventListener('mousedown', () => {
|
||||
this.dragging = true;
|
||||
document.addEventListener('mouseup', () => {
|
||||
this.dragging = false;
|
||||
}, {once: true});
|
||||
});
|
||||
document.addEventListener('mousemove', e => {
|
||||
if (!this.dragging) return;
|
||||
this.x += e.movementX;
|
||||
this.y += e.movementY;
|
||||
this.setLoc();
|
||||
});
|
||||
window.addEventListener('resize', () => {
|
||||
this.setLoc();
|
||||
});
|
||||
}
|
||||
|
||||
show() {
|
||||
this.wnd.style.display = "block";
|
||||
this.shown = true;
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.wnd.style.display = "none";
|
||||
this.shown = false;
|
||||
}
|
||||
|
||||
private setLoc() {
|
||||
if (this.x < 0) this.x = 0;
|
||||
if (this.y < 0) this.y = 0;
|
||||
if (this.x > document.documentElement.clientWidth - this.config.width) this.x = document.documentElement.clientWidth - this.config.width;
|
||||
if (this.y > document.documentElement.clientHeight - this.config.height) this.y = document.documentElement.clientHeight - this.config.height;
|
||||
this.wnd.style.top = this.y + "px";
|
||||
this.wnd.style.left = this.x + "px";
|
||||
}
|
||||
}
|
26
webapp/src/ts/main.ts
Normal file
26
webapp/src/ts/main.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { MSWindow, MSWindowStartPosition } from "./MSWindow.js"
|
||||
|
||||
const elements = {
|
||||
logonView: document.getElementById("logonView") as HTMLDivElement,
|
||||
logonWindow: document.getElementById("logonWindow") as HTMLDivElement,
|
||||
logonForm: document.getElementById("logonForm") as HTMLFormElement,
|
||||
|
||||
chatView: document.getElementById("chatView") as HTMLDivElement,
|
||||
}
|
||||
|
||||
let logonWindow = new MSWindow(elements.logonWindow, {
|
||||
width: 500,
|
||||
height: 275,
|
||||
hasClose: false,
|
||||
startPosition: MSWindowStartPosition.Center
|
||||
});
|
||||
|
||||
logonWindow.show();
|
||||
|
||||
elements.logonForm.addEventListener('submit', e => {
|
||||
e.preventDefault();
|
||||
|
||||
logonWindow.hide();
|
||||
elements.logonView.style.display = "none";
|
||||
elements.chatView.style.display = "block";
|
||||
});
|
108
webapp/tsconfig.json
Normal file
108
webapp/tsconfig.json
Normal file
|
@ -0,0 +1,108 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "es2022", /* Specify what module code is generated. */
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
||||
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
||||
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
||||
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
||||
"resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
||||
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue