-
Notifications
You must be signed in to change notification settings - Fork 12
/
app.controller.ts
50 lines (42 loc) · 1.4 KB
/
app.controller.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Get, Controller } from '@nestjs/common';
import { WebSocketGateway, SubscribeMessage, WebSocketServer } from '@nestjs/websockets';
import { HunliDiscussService, HunliFuyueService } from './hunli_discuss.service';
@WebSocketGateway({ port: 1314 })
export class AppGeteway {
@WebSocketServer() server;
constructor(private hunli: HunliDiscussService, private fuyue: HunliFuyueService) {
}
@SubscribeMessage('hunli.discuss')
async handelHunliDiscuss(sender, data) {
const list = await this.hunli.findAll();
sender.emit('hunli.discuss', list);
}
@SubscribeMessage('hunli.discuss.add')
async handelHunliDiscussAdd(sender, data) {
const item = await this.hunli.addOne(data);
const list = await this.hunli.findAll();
sender.broadcast.emit('hunli.discuss.add', data);
sender.emit('hunli.discuss.add', data);
}
@SubscribeMessage('hunli.fuyue')
async handelHunliFuyue(sender, data) {
const list = await this.fuyue.findAll();
sender.emit('hunli.fuyue', list);
}
@SubscribeMessage('hunli.fuyue.add')
async handelHunliFuyueAdd(sender, data) {
const item = await this.fuyue.addOne(data);
if (item) {
const list = await this.fuyue.findAll();
sender.broadcast.emit('hunli.fuyue.add', data);
sender.emit('hunli.fuyue.add', data);
}
}
}
@Controller()
export class AppController {
@Get()
root(): string {
return 'Hello World!';
}
}