Comparing version 0.1.0 to 0.1.1
@@ -19,4 +19,6 @@ "use strict"; | ||
clusterManager.registerEventHandler(Room_1.RoomListHandler); | ||
clusterManager.registerEventHandler(Room_1.RoomMessageHandler); | ||
clusterManager.registerEventHandler(Client_1.ClientConnectHandler); | ||
clusterManager.registerEventHandler(Client_1.ClientDisconnectHandler); | ||
clusterManager.registerEventHandler(Client_1.ClientInfoHandler); | ||
clusterManager.registerEventHandler(Client_1.ClientMessageHandler); | ||
@@ -23,0 +25,0 @@ clusterManager.registerEventHandler(Client_1.ClientMergeInfoHandler); |
@@ -7,3 +7,3 @@ import { BaseCommandProcessor } from './BaseCommandProcessor'; | ||
export interface RoomCommandResponse { | ||
type: 'ROOM'; | ||
type: 'ROOM_JOIN' | 'ROOM_EXIT' | 'ROOM_INFO'; | ||
data: any; | ||
@@ -10,0 +10,0 @@ } |
@@ -14,5 +14,11 @@ "use strict"; | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const clientInfo = yield this.manager.broadcast(new W_A_1.ClientInfoRequestEvent({ clientId: client.id }), A_W_1.ClientInfoResponseEvent); | ||
const response = { | ||
type: 'ROOM', | ||
data: {}, | ||
type: 'ROOM_JOIN', | ||
data: clientInfo | ||
? { | ||
clientId: clientInfo.data.id, | ||
info: clientInfo.data.info, | ||
} | ||
: {}, | ||
}; | ||
@@ -23,3 +29,3 @@ this.manager.broadcast(new W_A_1.JoinRoomEvent({ | ||
})); | ||
client.sendMessage(response); | ||
this.manager.broadcast(new W_A_1.RoomMessageEvent({ roomId: msg.roomId, msg: response })); | ||
}); | ||
@@ -32,3 +38,3 @@ } | ||
super(...arguments); | ||
this.tester = 'ROOM'; | ||
this.tester = 'ROOM_EXIT'; | ||
} | ||
@@ -38,4 +44,6 @@ onMessage(client, msg = {}) { | ||
const response = { | ||
type: 'ROOM', | ||
data: {}, | ||
type: 'ROOM_EXIT', | ||
data: { | ||
clientId: client.id, | ||
}, | ||
}; | ||
@@ -54,11 +62,15 @@ this.manager.broadcast(new W_A_1.ExitRoomEvent({ | ||
super(...arguments); | ||
this.tester = 'ROOM'; | ||
this.tester = 'ROOM_INFO'; | ||
} | ||
onMessage(client, msg = {}) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const info = yield this.manager.broadcast(new W_A_1.RoomInfoRequestEvent({ | ||
roomId: msg.roomId, | ||
}), A_W_1.RoomInfoResponseEvent); | ||
if (info) { | ||
info.data.clients = info.data.clients.map(c => ({ id: c.id, info: c.info })); | ||
} | ||
const response = { | ||
type: 'ROOM', | ||
data: yield this.manager.broadcast(new W_A_1.RoomInfoRequestEvent({ | ||
roomId: msg.roomId, | ||
}), A_W_1.RoomInfoResponseEvent), | ||
type: 'ROOM_INFO', | ||
data: info, | ||
}; | ||
@@ -65,0 +77,0 @@ client.sendMessage(response); |
@@ -34,2 +34,5 @@ "use strict"; | ||
this.broadcast(new W_A_1.ClientConnectEvent({ id: client.id })); | ||
const pingTimer = setInterval(() => { | ||
ws.ping(); | ||
}, 30 * 1000); | ||
ws.onmessage = evt => { | ||
@@ -65,2 +68,3 @@ if (evt.type === 'message') { | ||
this.logger.info('[client] onclose', client.id); | ||
clearInterval(pingTimer); | ||
this.clients.delete(client.id); | ||
@@ -67,0 +71,0 @@ this.onSendTo.emit(new W_A_1.ClientDisconnectEvent({ id: client.id })); |
@@ -5,1 +5,2 @@ export * from './Connect'; | ||
export * from './Message'; | ||
export * from './Info'; |
@@ -8,1 +8,2 @@ "use strict"; | ||
tslib_1.__exportStar(require("./Message"), exports); | ||
tslib_1.__exportStar(require("./Info"), exports); |
@@ -5,1 +5,2 @@ export * from './Exit'; | ||
export * from './List'; | ||
export * from './Message'; |
@@ -8,1 +8,2 @@ "use strict"; | ||
tslib_1.__exportStar(require("./List"), exports); | ||
tslib_1.__exportStar(require("./Message"), exports); |
@@ -22,6 +22,3 @@ "use strict"; | ||
clients: [...room.clients.values()].map(c => { | ||
return { | ||
id: c.id, | ||
info: c.ext.info, | ||
}; | ||
return c; | ||
}), | ||
@@ -28,0 +25,0 @@ }, evt.id); |
import { BaseEvent } from '../common/BaseEvent'; | ||
import { IRoomInfo } from './interface'; | ||
import { IRoomInfo, IClientInfo } from './interface'; | ||
export declare class ClientInfoResponseEvent extends BaseEvent<IClientInfo> { | ||
} | ||
export declare class RoomInfoResponseEvent extends BaseEvent<IRoomInfo> { | ||
@@ -4,0 +6,0 @@ } |
@@ -5,2 +5,5 @@ "use strict"; | ||
const BaseEvent_1 = require("../common/BaseEvent"); | ||
class ClientInfoResponseEvent extends BaseEvent_1.BaseEvent { | ||
} | ||
exports.ClientInfoResponseEvent = ClientInfoResponseEvent; | ||
class RoomInfoResponseEvent extends BaseEvent_1.BaseEvent { | ||
@@ -7,0 +10,0 @@ } |
@@ -38,2 +38,7 @@ import { BaseEvent } from '../common/BaseEvent'; | ||
} | ||
/** 客户端信息 */ | ||
export declare class ClientInfoRequestEvent extends BaseEvent<{ | ||
clientId: string; | ||
}> { | ||
} | ||
/** 更新客户端信息 */ | ||
@@ -40,0 +45,0 @@ export declare class MergeClientInfoEvent extends BaseEvent<{ |
@@ -33,2 +33,6 @@ "use strict"; | ||
exports.RoomInfoRequestEvent = RoomInfoRequestEvent; | ||
/** 客户端信息 */ | ||
class ClientInfoRequestEvent extends BaseEvent_1.BaseEvent { | ||
} | ||
exports.ClientInfoRequestEvent = ClientInfoRequestEvent; | ||
/** 更新客户端信息 */ | ||
@@ -35,0 +39,0 @@ class MergeClientInfoEvent extends BaseEvent_1.BaseEvent { |
{ | ||
"name": "egg-ez-ws", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "easy websocket for egg.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56667
80
1426