mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 18:29:15 +03:00
feat: sending message time
This commit is contained in:
parent
971a4b8c21
commit
3e16fe6a19
@ -12,6 +12,7 @@ import OnlineController from 'App/Controllers/Ws/OnlineController';
|
|||||||
*/
|
*/
|
||||||
import AuthMiddleware from 'App/Middleware/Ws/Auth';
|
import AuthMiddleware from 'App/Middleware/Ws/Auth';
|
||||||
import RedisSessionStore from 'App/Store/SessionStore';
|
import RedisSessionStore from 'App/Store/SessionStore';
|
||||||
|
import { DateTime } from 'luxon';
|
||||||
|
|
||||||
export interface ServerToClientEvents {
|
export interface ServerToClientEvents {
|
||||||
/**
|
/**
|
||||||
@ -22,9 +23,9 @@ export interface ServerToClientEvents {
|
|||||||
'user:online': (data: [string, { userId: string; userName: string }][]) => void;
|
'user:online': (data: [string, { userId: string; userName: string }][]) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message
|
* Chat
|
||||||
*/
|
*/
|
||||||
'message:private': (data: { content: string; from: string; to: string }) => void;
|
'chat:message': (data: { content: string; time: string; from: string; to: string }) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ClientToServerEvents {
|
export interface ClientToServerEvents {
|
||||||
@ -35,9 +36,9 @@ export interface ClientToServerEvents {
|
|||||||
'user:status': () => void;
|
'user:status': () => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message
|
* Chat
|
||||||
*/
|
*/
|
||||||
'message:private': (data: { content: string; to: string }) => void;
|
'chat:message': (data: { content: string; to: string }) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InterServerEvents {}
|
export interface InterServerEvents {}
|
||||||
@ -102,9 +103,9 @@ class WsService {
|
|||||||
*/
|
*/
|
||||||
socket.emit('user:session', { sessionId: socket.data.sessionId, userId: socket.data.userId });
|
socket.emit('user:session', { sessionId: socket.data.sessionId, userId: socket.data.userId });
|
||||||
|
|
||||||
socket.on('message:private', ({ content, to }) => {
|
socket.on('chat:message', ({ content, to }) => {
|
||||||
if (isExistSocketData) {
|
if (isExistSocketData) {
|
||||||
this.io.to(to).emit('message:private', { content, from: userId, to });
|
this.io.to(to).emit('chat:message', { content, from: userId, to, time: DateTime.now().toISO() });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user