Transmission plus immédiate via websockets

This commit is contained in:
2024-12-17 01:06:23 +01:00
parent 29c0a234d1
commit 0433e4695e
12 changed files with 448 additions and 12 deletions

View 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()
})
})

View 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)
}
}

View File

@ -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 {}