Skip to content

Commit

Permalink
feat: status 'resolve'
Browse files Browse the repository at this point in the history
- Will relsove without awaiting server response
  • Loading branch information
frankpagan committed Oct 17, 2023
1 parent 6839c89 commit b6769eb
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@
self.serverStorage = false
else if (message.organizationBalance === false)
self.organizationBalance = false
console.log('Server Access Denied: ', { serverOrganization: self.serverOrganization, serverStorage: self.serverStorage, organizationBalance: self.organizationBalance })
}

if (message.method != 'connect' && typeof message == 'object') {
Expand Down Expand Up @@ -311,10 +310,8 @@
},


send(data) {
send(data = {}) {
return new Promise(async (resolve, reject) => {
if (!data)
data = {}
data.clientId = this.clientId;
data.frameId = this.frameId;

Expand Down Expand Up @@ -366,14 +363,12 @@
for (let socket of sockets) {
data.socketId = socket.id;

if (data.status === "resolved") {
data.status = "queued"
resolve();
}

if (socket.connected && this.serverOrganization && this.serverStorage && this.organizationBalance) {
if (data.status !== 'queued')
this.addListener(uid)
if (data.status === 'resolve')
resolve(data)
else if (data.status !== 'queued')
this.addListener(uid, resolve)

delete data.status
socket.send(JSON.stringify(data));
data.status = "sent"
Expand All @@ -382,7 +377,6 @@
resolve(data)
}


if (isBrowser) {
if (data.broadcastSender)
this.sendLocalMessage(data)
Expand All @@ -403,7 +397,7 @@
});
},

addListener(uid) {
addListener(uid, resolve) {
if (isBrowser) {
window.addEventListener(uid, function (event) {
// here we have access to request and new data
Expand Down

0 comments on commit b6769eb

Please sign in to comment.