Skip to content

Commit 56836d5

Browse files
author
Peter Di Pasquale
committed
Changed subscriptions to always use uppercase keys except in case of undefined key
1 parent 7560bb4 commit 56836d5

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/realtime/MCWSStreamWorkerScript.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,16 @@
152152
reconnect() {
153153
let oldSocket = this.socket;
154154
const { url, subscribers, property } = this;
155-
155+
156+
// Map subscribers to an all uppercase object since MCWS is
157+
// not consistent.
158+
let upperCaseSubscribers = Object.fromEntries(
159+
Object.entries(subscribers).map(([key, value]) => [
160+
key === "undefined" ? key : key.toUpperCase(),
161+
value
162+
])
163+
);
164+
156165
// no subscribers or no topic close existing socket
157166
// suppress errors as they are not useful
158167
if (Object.keys(subscribers).length < 1 || !this.topic) {
@@ -194,8 +203,8 @@
194203
const data = JSON.parse(message.data);
195204

196205
data.forEach((datum) => {
197-
const key = datum[property].toUpperCase();
198-
if (subscribers[key] > 0) {
206+
const key = datum[property]?.toUpperCase();
207+
if (upperCaseSubscribers[key] > 0) {
199208
self.postMessage({
200209
url: url,
201210
key: key,

0 commit comments

Comments
 (0)