Browse Source

👕 Change file structure

main
Haris Razis 4 years ago
parent
commit
c162eb5586
No known key found for this signature in database GPG Key ID: 86A4D290ED03FAB4
  1. 6
      broker/src/index.ts
  2. 0
      client/package-lock.json
  3. 6
      client/package.json
  4. 21
      client/src/class/ClientService.ts
  5. 15
      client/src/class/ClientSocket.ts
  6. 11
      client/src/class/Sensor.ts
  7. 3
      client/src/index.ts
  8. 4
      client/tsconfig.json
  9. 9
      sensor/src/index.ts
  10. 11
      server/package-lock.json
  11. 7
      server/package.json
  12. 3
      server/src/class/Database.ts
  13. 20
      server/src/class/ServerSocket.ts
  14. 3
      server/src/index.ts
  15. 8
      server/tsconfig.json

6
broker/src/index.ts

@ -1,6 +0,0 @@
import chalk from 'chalk';
import { ServerSocket } from './controllers/ServerSocket';
console.log(chalk.cyan('Started Anchiale broker...'));
const socket = new ServerSocket('/', 3000);

0
sensor/package-lock.json → client/package-lock.json

6
sensor/package.json → client/package.json

@ -5,8 +5,10 @@
"main": "index.js",
"scripts": {
"start:build": "tsc -w",
"start:run": "nodemon build/index.js",
"start": "concurrently npm:start:*"
"start:run": "node build/index.js",
"dev": "nodemon build/index.js",
"test": "concurrently npm:start:build npm:dev",
"start": "concurrently start:*"
},
"repository": {
"type": "git",

21
client/src/class/ClientService.ts

@ -0,0 +1,21 @@
import { ClientSocket } from './ClientSocket';
import { Sensor } from './Sensor';
export class ClientService {
clientSocket: ClientSocket = new ClientSocket(3000, '/');
sensor: Sensor = new Sensor();
constructor() {}
tempService() {
setInterval(() => {
this.clientSocket.sendTemp(this.sensor.takeMeasure);
}, 1000);
}
tempTestService() {
setInterval(() => {
this.clientSocket.sendTemp(this.sensor.takeTestMeasure);
}, 1000);
}
}

15
sensor/src/controllers/ClientSocket.ts → client/src/class/ClientSocket.ts

@ -4,7 +4,7 @@ import io from 'socket.io-client';
export class ClientSocket {
private socket!: SocketIOClient.Socket;
constructor(private path: string, private port: number) {
constructor(private port: number, private path: string) {
this.initSocket();
this.connStatus();
}
@ -16,7 +16,7 @@ export class ClientSocket {
private connStatus() {
this.socket.on('connect', () => {
console.log(chalk.magenta('Connected to server!'));
console.log(chalk.green('Connected to server!'));
});
this.socket.on('disconnect', (reason: string) => {
@ -29,4 +29,15 @@ export class ClientSocket {
console.log(chalk.yellow('Reconecting...'));
});
}
closeConn() {
console.log(chalk.yellow('Closing socket...'));
this.socket.disconnect();
}
sendTemp(temp: number) {
this.socket.emit('temp', temp, (data: string) => {
console.log(data);
});
}
}

11
client/src/class/Sensor.ts

@ -0,0 +1,11 @@
export class Sensor {
constructor() {}
get takeMeasure(): number {
return 0;
}
get takeTestMeasure(): number {
return Math.floor(Math.random() * 50);
}
}

3
client/src/index.ts

@ -0,0 +1,3 @@
import chalk from 'chalk';
console.log(chalk.cyan('Started Anchiale Client...'));

4
sensor/tsconfig.json → client/tsconfig.json

@ -14,8 +14,8 @@
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./build" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */

9
sensor/src/index.ts

@ -1,9 +0,0 @@
import chalk from 'chalk';
import { ClientSocket } from './controllers/ClientSocket';
import { Sensor } from './controllers/Sensor';
console.log(chalk.cyan('Started Anchiale measure...'));
const socket = new ClientSocket('/', 3000);
const sensor = new Sensor();

11
broker/package-lock.json → server/package-lock.json

@ -9,6 +9,7 @@
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"@influxdata/influxdb-client": "^1.8.0",
"@types/node": "^14.14.7",
"@types/socket.io": "^2.1.11",
"chalk": "^3.0.0",
@ -16,6 +17,11 @@
"socket.io": "^3.0.1"
}
},
"node_modules/@influxdata/influxdb-client": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client/-/influxdb-client-1.8.0.tgz",
"integrity": "sha512-fygvCHBUrcuduMRZf1oGhQzvIJG6gEA+0JX4ffxq5cxAeHKUGCYt30GafBc23QyrnCc50zc0IsPSG2Tw47aw+w=="
},
"node_modules/@sindresorhus/is": {
"version": "0.14.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz",
@ -1385,6 +1391,11 @@
}
},
"dependencies": {
"@influxdata/influxdb-client": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/@influxdata/influxdb-client/-/influxdb-client-1.8.0.tgz",
"integrity": "sha512-fygvCHBUrcuduMRZf1oGhQzvIJG6gEA+0JX4ffxq5cxAeHKUGCYt30GafBc23QyrnCc50zc0IsPSG2Tw47aw+w=="
},
"@sindresorhus/is": {
"version": "0.14.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz",

7
broker/package.json → server/package.json

@ -5,8 +5,10 @@
"main": "index.js",
"scripts": {
"start:build": "tsc -w",
"start:run": "nodemon build/index.js",
"start": "concurrently npm:start:*"
"start:run": "node build/index.js",
"dev": "nodemon build/index.js",
"test": "concurrently npm:start:build npm:dev",
"start": "concurrently start:*"
},
"repository": {
"type": "git",
@ -20,6 +22,7 @@
},
"homepage": "https://github.com/xrazis/Anchiale-pi#readme",
"dependencies": {
"@influxdata/influxdb-client": "^1.8.0",
"@types/node": "^14.14.7",
"@types/socket.io": "^2.1.11",
"chalk": "^3.0.0",

3
server/src/class/Database.ts

@ -0,0 +1,3 @@
export class localdb {
constructor() {}
}

20
broker/src/controllers/ServerSocket.ts → server/src/class/ServerSocket.ts

@ -1,10 +1,14 @@
import chalk from 'chalk';
import { Server } from 'socket.io';
export class ServerSocket {
interface DatabaseHas {
push(temp: number): void;
}
export class ServerSocket<T extends DatabaseHas> {
private io!: Server;
constructor(private path: string, private port: number) {
constructor(private path: string, private port: number, private database: T) {
this.initSocket();
this.connStatus();
}
@ -18,11 +22,21 @@ export class ServerSocket {
private connStatus() {
this.io.on('connect', (socket) => {
console.log(chalk.magenta('Client connected!'));
console.log(chalk.green('Client connected!'));
socket.on('disconnect', () => {
console.log(chalk.red('Client disconected!'));
});
socket.on('temp', (temp: number) => {
this.database.push(temp);
});
});
}
closeSocket() {
this.io.close(() => {
console.log(chalk.red('Closing socket...'));
});
}
}

3
server/src/index.ts

@ -0,0 +1,3 @@
import chalk from 'chalk';
console.log(chalk.cyan('Started Anchiale Server...'));

8
broker/tsconfig.json → server/tsconfig.json

@ -4,7 +4,7 @@
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', '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. */
// "allowJs": true, /* Allow javascript files to be compiled. */
@ -14,8 +14,8 @@
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./build" /* Redirect output structure to the directory. */,
"rootDir": "./src" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */,
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
@ -47,7 +47,7 @@
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
Loading…
Cancel
Save