Skip to content

Commit 12c1c1f

Browse files
committed
chore: lint and clean code
1 parent f278340 commit 12c1c1f

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

src/protocols/WebSocket.ts

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,11 @@ export default class WebSocketProtocol extends BaseProtocolRealtime {
243243
* @param {Object} payload
244244
*/
245245
send(request: RequestPayload, options: JSONObject = {}) {
246-
if (this.maxPayloadSize !== null && Buffer.byteLength(JSON.stringify(request), 'utf8') > this.maxPayloadSize) {
247-
248-
const error: any= new Error(
246+
if (
247+
this.maxPayloadSize !== null &&
248+
Buffer.byteLength(JSON.stringify(request), "utf8") > this.maxPayloadSize
249+
) {
250+
const error: any = new Error(
249251
`Payload size exceeded the maximum allowed by the server ${this.maxPayloadSize} bytes`
250252
);
251253

@@ -379,35 +381,34 @@ export default class WebSocketProtocol extends BaseProtocolRealtime {
379381
/**
380382
* Get the maximum payload size allowed by the server
381383
* Stores the value in `this.maxPayloadSize`
382-
**/
384+
**/
383385
async getMaxPayloadSize() {
384386
return new Promise((resolve, reject) => {
385-
const originalOnMessage = this.client.onmessage;
386-
this.client.onmessage = (payload) => {
387-
try {
388-
const data = JSON.parse(payload.data || payload);
389-
390-
// Check if the message corresponds to the `getMaxPayloadSize` response
391-
if (data.result && data.result.server && data.result.server.maxRequestSize) {
392-
this.maxPayloadSize = parseSize(data.result.server.maxRequestSize);
393-
394-
// Restore the original `onmessage` handler
395-
this.client.onmessage = originalOnMessage;
396-
resolve(this.maxPayloadSize);
397-
return;
398-
}
399-
400-
// If not related to `getMaxPayloadSize`, pass to the original handler
401-
if (originalOnMessage) {
402-
originalOnMessage(payload);
403-
}
404-
} catch (error) {
405-
reject(error);
406-
}
407-
};
387+
const originalOnMessage = this.client.onmessage;
388+
this.client.onmessage = (payload) => {
389+
try {
390+
const data = JSON.parse(payload.data || payload);
391+
392+
// Check if the message corresponds to the `getMaxPayloadSize` response
393+
if (
394+
data.result &&
395+
data.result.server &&
396+
data.result.server.maxRequestSize
397+
) {
398+
this.maxPayloadSize = parseSize(data.result.server.maxRequestSize);
399+
400+
// Restore the original `onmessage` handler
401+
this.client.onmessage = originalOnMessage;
402+
resolve(this.maxPayloadSize);
403+
return;
404+
}
405+
} catch (error) {
406+
reject(error);
407+
}
408+
};
408409

409-
// Send the request
410-
this.send({ controller: "server", action: "getConfig" });
410+
// Send the request
411+
this.send({ action: "getConfig", controller: "server" });
411412
});
412413
}
413414
}

0 commit comments

Comments
 (0)