Skip to content

Commit

Permalink
fix: replaced socketInfo with socket.config
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Sep 27, 2022
1 parent 549ea18 commit 0e2b047
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,12 @@ class SocketServer extends EventEmitter{

async onMessage(req, socket, message) {
try {
let socketInfo = socket.config;
this.recordTransfer('in', message, socket.config.orgId)

// ToDo remove
if (message instanceof Buffer) {
this.emit('importFile2DB', socket, message, socketInfo);
console.log('importFile2DB', socket, message, socketInfo);
this.emit('importFile2DB', socket, message);
console.log('importFile2DB', socket, message);
return;
}

Expand All @@ -158,21 +157,21 @@ class SocketServer extends EventEmitter{
if (this.permissionInstance) {
let passStatus = await this.permissionInstance.check(requestData.module, requestData.data, req, user_id)
if (!passStatus) {
this.send(socket, 'permissionError', requestData.data, socketInfo.orgId, socketInfo)
this.send(socket, 'permissionError', requestData.data)
return;
}
}

//. checking async status....
if (requestData.data.async == true) {
console.log('async true')
const uuid = CoCreateUUID.generate(), asyncMessage = this.asyncMessages.get(socketInfo.key);
socketInfo.asyncId = uuid;
const uuid = CoCreateUUID.generate(), asyncMessage = this.asyncMessages.get(socket.config.key);
socket.config.asyncId = uuid;
if (asyncMessage) {
asyncMessage.defineMessage(uuid);
}
}
this.emit(requestData.module, socket, requestData.data, socketInfo);
this.emit(requestData.module, socket, requestData.data);
}

} catch(e) {
Expand All @@ -182,8 +181,7 @@ class SocketServer extends EventEmitter{

broadcast(socket, namespace, rooms, messageName, data) {
const self = this;
let socketInfo = socket.config;
const asyncId = this.getAsyncId(socketInfo)
const asyncId = socket.config.asyncId
let room_key = `/${this.prefix}/${namespace}`;
const responseData =JSON.stringify({
module: messageName,
Expand All @@ -192,7 +190,7 @@ class SocketServer extends EventEmitter{

let isAsync = false;
let asyncData = [];
if (asyncId && socketInfo && socketInfo.key) {
if (asyncId && socket.config && socket.config.key) {
isAsync = true;
}

Expand Down Expand Up @@ -236,39 +234,29 @@ class SocketServer extends EventEmitter{

//. set async processing
if (isAsync) {
this.asyncMessages.get(socketInfo.key).setMessage(asyncId, asyncData)
this.asyncMessages.get(socket.config.key).setMessage(asyncId, asyncData)
}

}

send(socket, messageName, data){
let socketInfo = socket.config;
const asyncId = this.getAsyncId(socketInfo)
const asyncId = socket.config.asyncId
let responseData = JSON.stringify({
module: messageName,
data
});

if (asyncId && socketInfo && socketInfo.key) {
this.asyncMessages.get(socketInfo.key).setMessage(asyncId, [{socket, message: responseData}]);
if (asyncId && socket.config && socket.config.key) {
this.asyncMessages.get(socket.config.key).setMessage(asyncId, [{socket, message: responseData}]);
} else {
socket.send(responseData);
}

if (socketInfo && socketInfo.orgId)
this.recordTransfer('out', responseData, socketInfo.orgId)
if (socket.config && socket.config.orgId)
this.recordTransfer('out', responseData, socket.config.orgId)

}

getAsyncId(socketInfo) {
if (!socketInfo) return null;

if (socketInfo.asyncId) {
return socketInfo.asyncId;
}
return null
}

sendBinary(socket, data, orgId) {
socket.send(data, {binary: true});
this.recordTransfer('out', data, orgId)
Expand Down

0 comments on commit 0e2b047

Please sign in to comment.