|
@@ -13,17 +13,25 @@ import { Server, Socket } from 'socket.io';
|
|
import Redis from 'ioredis';
|
|
import Redis from 'ioredis';
|
|
import { instrument } from '@socket.io/admin-ui';
|
|
import { instrument } from '@socket.io/admin-ui';
|
|
import * as bcrypt from 'bcrypt';
|
|
import * as bcrypt from 'bcrypt';
|
|
|
|
+import { RoomService } from '../room/room.service';
|
|
|
|
|
|
-@WebSocketGateway(8889, {
|
|
|
|
|
|
+console.log('SOCKET_PATH-0', process.env.SOCKET_PATH);
|
|
|
|
+@WebSocketGateway(Number(process.env.SOCKET_PORT), {
|
|
transports: ['websocket'],
|
|
transports: ['websocket'],
|
|
cors: '*',
|
|
cors: '*',
|
|
// namespace: "ws",
|
|
// namespace: "ws",
|
|
|
|
+ // path: '/ws-sync',
|
|
path: process.env.SOCKET_PATH,
|
|
path: process.env.SOCKET_PATH,
|
|
// parser: require('socket.io-msgpack-parser'),
|
|
// parser: require('socket.io-msgpack-parser'),
|
|
})
|
|
})
|
|
-export class ChatGateway
|
|
|
|
- implements OnGatewayInit, OnGatewayDisconnect, OnGatewayConnection {
|
|
|
|
- constructor(@InjectRedis() private readonly redis: Redis) { }
|
|
|
|
|
|
+export class SocketGateway
|
|
|
|
+ implements OnGatewayInit, OnGatewayDisconnect, OnGatewayConnection
|
|
|
|
+{
|
|
|
|
+ constructor(
|
|
|
|
+ @InjectRedis() private readonly redis: Redis,
|
|
|
|
+ private readonly roomService: RoomService,
|
|
|
|
+ ) {}
|
|
|
|
+
|
|
@WebSocketServer() server: Server;
|
|
@WebSocketServer() server: Server;
|
|
handleConnection(client: any, ...args: any[]) {
|
|
handleConnection(client: any, ...args: any[]) {
|
|
// console.log('handleConnection', client, args);
|
|
// console.log('handleConnection', client, args);
|
|
@@ -32,6 +40,7 @@ export class ChatGateway
|
|
// console.log('handleDisconnect', client);
|
|
// console.log('handleDisconnect', client);
|
|
}
|
|
}
|
|
afterInit(server: any) {
|
|
afterInit(server: any) {
|
|
|
|
+ console.log('SOCKET_PATH-1', process.env.SOCKET_PATH);
|
|
instrument(server, {
|
|
instrument(server, {
|
|
auth: {
|
|
auth: {
|
|
type: 'basic',
|
|
type: 'basic',
|
|
@@ -44,19 +53,10 @@ export class ChatGateway
|
|
|
|
|
|
@SubscribeMessage('join')
|
|
@SubscribeMessage('join')
|
|
async handleMessage(
|
|
async handleMessage(
|
|
- @MessageBody() message: any,
|
|
|
|
|
|
+ @MessageBody() message: UserInfoParams,
|
|
@ConnectedSocket() socket: Socket,
|
|
@ConnectedSocket() socket: Socket,
|
|
): Promise<void> {
|
|
): Promise<void> {
|
|
- console.log('join', message);
|
|
|
|
socket.join(message.roomId);
|
|
socket.join(message.roomId);
|
|
- const tt = await this.redis.get('test');
|
|
|
|
- console.log('redis', tt);
|
|
|
|
- this.server.to(message.roomId).emit('action', { type: 'user-join' });
|
|
|
|
-
|
|
|
|
- // socket.emit('join', { test: true });
|
|
|
|
- // socket.broadcast
|
|
|
|
- // .to(message.roomId)
|
|
|
|
- // .emit('action',
|
|
|
|
- // { type: 'user-join',{ test: true } });
|
|
|
|
|
|
+ await this.roomService.handleUserJoin(message);
|
|
}
|
|
}
|
|
}
|
|
}
|