Edit
The following question is completely due to my misunderstanding.
omega:custom-protocol sets 16bit header in ddp message and the header cause “Discarding message with invalid JSON” error when a server receives messages as a client of other server.
I am using json protocol in omega:custom-protocol.
And I frequently get errors “Discarding message with invalid JSON” in parseDDP though its arguments are quite normal.
In order to debugging it, first I replaced DDPCommon.parseDDP with the same code as meteor core in a startup of my application.
import { DDPCommon } from 'meteor/ddp-common';
DDPCommon.parseDDP = function (stringMessage) {
try {
var msg = JSON.parse(stringMessage);
} catch (e) {
Meteor._debug("Discarding message with invalid JSON", stringMessage);
return null;
}
// DDP messages must be objects.
if (msg === null || typeof msg !== 'object') {
Meteor._debug("Discarding non-object DDP message", stringMessage);
return null;
}
// massage msg to get it into "abstract ddp" rather than "wire ddp" format.
// switch between "cleared" rep of unsetting fields and "undefined"
// rep of same
if (_.has(msg, 'cleared')) {
if (!_.has(msg, 'fields'))
msg.fields = {};
_.each(msg.cleared, function (clearKey) {
msg.fields[clearKey] = undefined;
});
delete msg.cleared;
}
_.each(['fields', 'params', 'result'], function (field) {
if (_.has(msg, field))
msg[field] = EJSON._adjustTypesFromJSONValue(msg[field]);
});
return msg;
};
Then the errors disappeared.
I suspect that JSON in the function refers to different one between meteor-core and the app in that JSON refers to the global variable in Node.js.
What is the JSON in DDPCommon.parseDDP? and how can I fix my problem?