No known key found for this signature in database
GPG Key ID: 86A4D290ED03FAB4
3 changed files with
19 additions and
7 deletions
-
server/src/class/Socket.ts
-
server/src/index.ts
-
server/src/routes/Routes.ts
|
@ -5,6 +5,10 @@ interface database { |
|
|
closeWrite(): void; |
|
|
closeWrite(): void; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface server extends SocketIO.Server { |
|
|
|
|
|
allSockets(): Promise<{}>; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
interface packet { |
|
|
interface packet { |
|
|
uuid: string; |
|
|
uuid: string; |
|
|
measurement: number; |
|
|
measurement: number; |
|
@ -12,7 +16,7 @@ interface packet { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export class Socket<T> { |
|
|
export class Socket<T> { |
|
|
private io!: SocketIO.Server; |
|
|
private io!: server; |
|
|
|
|
|
|
|
|
constructor( |
|
|
constructor( |
|
|
private eventName: string, |
|
|
private eventName: string, |
|
@ -50,8 +54,16 @@ export class Socket<T> { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
get rooms() { |
|
|
get rooms(): Array<String> { |
|
|
return this.io.sockets.adapter.rooms; |
|
|
let roomsArray: Array<String> = []; |
|
|
|
|
|
this.io.allSockets().then((msg: any) => { |
|
|
|
|
|
console.log(msg); |
|
|
|
|
|
const iterator = msg.entries(); |
|
|
|
|
|
for (const entry of iterator) { |
|
|
|
|
|
roomsArray.push(entry[0]); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
return roomsArray; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
closeSocket(): void { |
|
|
closeSocket(): void { |
|
|
|
@ -1,6 +1,7 @@ |
|
|
require('dotenv').config(); |
|
|
require('dotenv').config(); |
|
|
import express from 'express'; |
|
|
import express from 'express'; |
|
|
import chalk from 'chalk'; |
|
|
import chalk from 'chalk'; |
|
|
|
|
|
var cors = require('cors'); |
|
|
import { Service } from './class/Service'; |
|
|
import { Service } from './class/Service'; |
|
|
import { AppRouter } from './AppRouter'; |
|
|
import { AppRouter } from './AppRouter'; |
|
|
import { Routes } from './routes/Routes'; |
|
|
import { Routes } from './routes/Routes'; |
|
@ -11,6 +12,7 @@ const app = express(); |
|
|
const http = require('http').Server(app); |
|
|
const http = require('http').Server(app); |
|
|
const service = new Service(http); |
|
|
const service = new Service(http); |
|
|
|
|
|
|
|
|
|
|
|
app.use(cors()); |
|
|
app.use(AppRouter.getInstance()); |
|
|
app.use(AppRouter.getInstance()); |
|
|
|
|
|
|
|
|
const route = new Routes(app, service); |
|
|
const route = new Routes(app, service); |
|
|
|
@ -11,11 +11,9 @@ export class Routes { |
|
|
|
|
|
|
|
|
private devices(): void { |
|
|
private devices(): void { |
|
|
this.app.get('/devices', async (req, res) => { |
|
|
this.app.get('/devices', async (req, res) => { |
|
|
const data = this.service.socket.rooms; |
|
|
const data = await this.service.socket.rooms; |
|
|
console.log(data); |
|
|
|
|
|
const parsedOata = JSON.stringify(data); |
|
|
|
|
|
res.header('Content-Type', 'application/json'); |
|
|
res.header('Content-Type', 'application/json'); |
|
|
res.send(parsedOata); |
|
|
res.send(JSON.stringify(data)); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|