Transmission plus immédiate via websockets
This commit is contained in:
18
server/src/geolocations/geolocations.gateway.spec.ts
Normal file
18
server/src/geolocations/geolocations.gateway.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing'
|
||||
import { GeolocationsGateway } from './geolocations.gateway'
|
||||
|
||||
describe('GeolocationsGateway', () => {
|
||||
let gateway: GeolocationsGateway
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [GeolocationsGateway],
|
||||
}).compile();
|
||||
|
||||
gateway = module.get<GeolocationsGateway>(GeolocationsGateway)
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(gateway).toBeDefined()
|
||||
})
|
||||
})
|
13
server/src/geolocations/geolocations.gateway.ts
Normal file
13
server/src/geolocations/geolocations.gateway.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { SubscribeMessage, WebSocketGateway, WebSocketServer } from '@nestjs/websockets'
|
||||
import { Server, Socket } from 'socket.io'
|
||||
|
||||
@WebSocketGateway()
|
||||
export class GeolocationsGateway {
|
||||
@WebSocketServer()
|
||||
server: Server
|
||||
|
||||
@SubscribeMessage('last-location')
|
||||
handleLastLocation(client: Socket, payload: any) {
|
||||
return this.server.emit('last-location', payload)
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { GeolocationsService } from './geolocations.service'
|
||||
import { GeolocationsController } from './geolocations.controller'
|
||||
import { PrismaModule } from 'src/prisma/prisma.module'
|
||||
import { GeolocationsController } from './geolocations.controller'
|
||||
import { GeolocationsService } from './geolocations.service'
|
||||
import { GeolocationsGateway } from './geolocations.gateway'
|
||||
|
||||
@Module({
|
||||
controllers: [GeolocationsController],
|
||||
providers: [GeolocationsService],
|
||||
providers: [GeolocationsService, GeolocationsGateway],
|
||||
imports: [PrismaModule],
|
||||
})
|
||||
export class GeolocationsModule {}
|
||||
|
Reference in New Issue
Block a user