Skip to content

Commit 0e33930

Browse files
committed
Cleanup logic related to publish intercept
1 parent e5bf9be commit 0e33930

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

serversocket.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,9 @@ AGServerSocket.prototype._processInboundPacket = async function (packet, message
760760
}
761761

762762
if (isPublish) {
763+
if (!packet.data) {
764+
packet.data = {};
765+
}
763766
packet.data.data = newData;
764767
await this._processInboundPublishPacket(packet);
765768
}

test/integration.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3265,10 +3265,11 @@ describe('Integration tests', function () {
32653265
clientB.disconnect();
32663266
clientC.disconnect();
32673267
});
3268+
32683269
it('Should allow to change message in middleware when client invokePublish', async function() {
3269-
const clientMessage = 'world';
3270-
const middlewareMessage = 'intercepted';
3271-
const middlewareFunction = async function (middlewareStream) {
3270+
let clientMessage = 'world';
3271+
let middlewareMessage = 'intercepted';
3272+
let middlewareFunction = async function (middlewareStream) {
32723273
for await (let action of middlewareStream) {
32733274
if (action.type === AGAction.PUBLISH_IN) {
32743275
action.allow({data: middlewareMessage});
@@ -3280,7 +3281,7 @@ describe('Integration tests', function () {
32803281

32813282
server.setMiddleware(server.MIDDLEWARE_INBOUND, middlewareFunction);
32823283

3283-
const client = socketClusterClient.create({
3284+
let client = socketClusterClient.create({
32843285
hostname: clientOptions.hostname,
32853286
port: PORT_NUMBER
32863287
});
@@ -3303,14 +3304,15 @@ describe('Integration tests', function () {
33033304
}
33043305

33053306
await wait(100);
3306-
3307+
33073308
assert.notEqual(clientMessage, middlewareMessage);
33083309
assert.equal(receivedMessages[0], middlewareMessage);
33093310
});
3311+
33103312
it('Should allow to change message in middleware when client transmitPublish', async function() {
3311-
const clientMessage = 'world';
3312-
const middlewareMessage = 'intercepted';
3313-
const middlewareFunction = async function (middlewareStream) {
3313+
let clientMessage = 'world';
3314+
let middlewareMessage = 'intercepted';
3315+
let middlewareFunction = async function (middlewareStream) {
33143316
for await (let action of middlewareStream) {
33153317
if (action.type === AGAction.PUBLISH_IN) {
33163318
action.allow({data: middlewareMessage});
@@ -3322,7 +3324,7 @@ describe('Integration tests', function () {
33223324

33233325
server.setMiddleware(server.MIDDLEWARE_INBOUND, middlewareFunction);
33243326

3325-
const client = socketClusterClient.create({
3327+
let client = socketClusterClient.create({
33263328
hostname: clientOptions.hostname,
33273329
port: PORT_NUMBER
33283330
});
@@ -3345,7 +3347,7 @@ describe('Integration tests', function () {
33453347
}
33463348

33473349
await wait(100);
3348-
3350+
33493351
assert.notEqual(clientMessage, middlewareMessage);
33503352
assert.equal(receivedMessages[0], middlewareMessage);
33513353
})

0 commit comments

Comments
 (0)