Skip to content

Commit 9a85ba1

Browse files
committed
fix: wrap messages in a object with a type and a payload to solve the JSON RPC spec not supporting primitives in params
1 parent d1907bb commit 9a85ba1

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

src/MessageBus.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,18 @@ export default class MessageBus {
7575
* @template [T=unknown]
7676
* @param {string} channel
7777
* @param {string} topic
78-
* @param {T} [payload]
78+
* @param {T} payload
7979
* @returns {Event<T>} Returns the {@link Event} object passed to subscribers.
8080
*/
8181
publish(channel, topic, payload) {
8282
const event = new Event(channel, topic, payload);
8383
this.ee.emit(event.toKey(), event);
8484
this.sink.push(event);
8585
if (this.bridge) {
86-
/** @type {T | T[]} */
87-
let params = payload;
88-
89-
if (typeof payload !== 'undefined') {
90-
// JSON RPC 2.0 requires that params is either an object or an array. Wrap primitives in an an array.
91-
const isPrimitive =
92-
typeof params === 'string' ||
93-
typeof params === 'boolean' ||
94-
typeof params === 'number';
95-
if (isPrimitive) {
96-
params = [payload];
97-
}
98-
}
9986

10087
this.bridge.notification({
10188
method: `${channel}/${topic}`,
102-
params,
89+
params:{"type":typeof payload, payload},
10390
});
10491
}
10592
return event;
@@ -140,7 +127,7 @@ export default class MessageBus {
140127
message
141128
);
142129

143-
const event = new Event(channel, topic, request.params);
130+
const event = new Event(channel, topic, request.params.payload);
144131
this.sink.push(event);
145132
listener(event);
146133
};

0 commit comments

Comments
 (0)