Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hapiness/core",
"version": "1.3.1",
"version": "1.3.2",
"description": "Project to have a HapiJS (https://hapijs.com/) based framework to create easier NodeJS back-end with some awesome features",
"main": "commonjs/index.js",
"types": "index.d.ts",
Expand Down
11 changes: 11 additions & 0 deletions src/extensions/socket-server/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export class Socket {

private data$ = new Subject<Message>();

private store: { [key: string]: any } = {};

constructor(
private _request: request,
private _connection: connection,
Expand Down Expand Up @@ -128,6 +130,15 @@ export class Socket {
return this;
}

setData(key: string, value: any): Socket {
this.store[key] = value;
return this;
}

getData(key: string): any {
return this.store[key];
}

private getJSON(data: string) {
try {
return JSON.parse(data);
Expand Down
2 changes: 2 additions & 0 deletions test/integration/socket-server-rooms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class SocketServerRoomIntegration {
socket => {
unit.array(this.server.instance().getSockets())
.hasLength(1);
socket.setData('test', 123);
socket
.join('room1')
.join('room2');
Expand All @@ -34,6 +35,7 @@ export class SocketServerRoomIntegration {
socket.on('tata', data => {});
socket.on('*', data => {
unit.string(data.utf8Data).is('received');
unit.value(socket.getData('test')).is(123);
socket.close();
this
.server
Expand Down