Skip to content

Commit

Permalink
return the complete payload to listeners instead of the last fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Dec 21, 2017
1 parent b5ff66f commit b041be3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
9 changes: 7 additions & 2 deletions build/CoapClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,12 @@ class CoapClient {
// TODO: we might have to check if we got the correct fragment
request.partialResponse.payload = Buffer.concat([request.partialResponse.payload, coapMsg.payload]);
}
if (!blockOption.isLastBlock) {
if (blockOption.isLastBlock) {
// override the message payload with the assembled partial payload
// so the full payload gets returned to the listeners
coapMsg.payload = request.partialResponse.payload;
}
else {
CoapClient.requestNextBlock(request);
responseIsComplete = false;
}
Expand Down Expand Up @@ -659,7 +664,7 @@ class CoapClient {
// and continue working off the queue when it drops
request.on("concurrencyChanged", (req) => {
debug(`request 0x${message.messageId.toString(16)}: concurrency changed => ${req.concurrency}`);
if (request.concurrency === 0)
if (req.concurrency === 0)
CoapClient.workOffSendQueue();
});
}
Expand Down
8 changes: 6 additions & 2 deletions src/CoapClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,11 @@ export class CoapClient {
// TODO: we might have to check if we got the correct fragment
request.partialResponse.payload = Buffer.concat([request.partialResponse.payload, coapMsg.payload]);
}
if (!blockOption.isLastBlock) {
if (blockOption.isLastBlock) {
// override the message payload with the assembled partial payload
// so the full payload gets returned to the listeners
coapMsg.payload = request.partialResponse.payload;
} else {
CoapClient.requestNextBlock(request);
responseIsComplete = false;
}
Expand Down Expand Up @@ -830,7 +834,7 @@ export class CoapClient {
// and continue working off the queue when it drops
request.on("concurrencyChanged", (req: PendingRequest) => {
debug(`request 0x${message.messageId.toString(16)}: concurrency changed => ${req.concurrency}`);
if (request.concurrency === 0) CoapClient.workOffSendQueue();
if (req.concurrency === 0) CoapClient.workOffSendQueue();
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/Message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,12 @@ describe.only("blockwise tests =>", () => {

// limit response size
coap.setDefaultRequestOptions({
preferredBlockSize: 16,
preferredBlockSize: 64,
});

const resp = await coap.request(`${requestBase}15011/15012`, "get");
console.log("got complete payload:");
console.log(resp.payload.toString("utf8"));

coap.reset();
});
Expand Down

0 comments on commit b041be3

Please sign in to comment.