#Getting subscription error while using wix realtime api on Blocks Dashboard

9 messages · Page 1 of 1 (latest)

thin ibex
#

Backend sending realtime message:

const channel = { name: "uploadStatus", resourceId: instanceId };

    console.log("Backend sending to: ");
    console.log(channel);

    site.publish(channel, "Stay tuned for new recipes!")
        .then(() => {
            console.log("Published");
        }).catch((e) => {
            console.log("Error");
            console.log(e);
        });

And dashboard code to subscribe:

const channel = { name: "uploadStatus", resourceId: instance.instanceId };

    realtime
        .subscribe(channel, (message, channel) => {
            let payload = message.payload;
            console.log("Payload");
            console.log(payload);
            let channelName = channel.name;
            console.log("Channel", channel.name);
            if (message.publisher) {
                let publisherId = message.publisher.id;
                console.log(publisherId);
            }
        })
        .then((id) => {
            console.log("Subscription ID");
            console.log(id);
        });

Has anyone used realtime api npm package in blocks?

By the way I got this same error when using velo api as well so if anyone has used realtime in blocks using velo apis as well, do you know what can cause this error?

candid oxide
#

Hi @thin ibex
Can you try another import instead import {permissionsRouter} from 'wix-realtime-backend';.
And try to follow these documentations:
https://dev.wix.com/docs/develop-websites/articles/code-tutorials/wix-editor-elements/sending-messages-with-the-realtime-api
https://dev.wix.com/docs/velo/velo-only-apis/wix-realtime-backend/introductio

thin ibex
#

It still fails on both widget and dashboard page (using velo apis)

#

realtime-permissions.js

import { permissionsRouter } from "wix-realtime-backend";

permissionsRouter.default((channel, subscriber) => {
    return { read: true };
});

const uploadChannel = { name: "uploadStatus" };

permissionsRouter.add(uploadChannel, (channel, subscriber) => {
    return { read: true };
});

export function realtime_check_permission(channel, subscriber) {
    return permissionsRouter.check(channel, subscriber);
}
#

and the code I am using to subscribe on widget and dashboard page:

 const channel = { name: "uploadStatus", resourceId: instance.instanceId };

    subscribe(channel, (message, channel) => {
            let payload = message.payload;
            console.log("Payload");
            console.log(payload);
            let channelName = channel.name;
            console.log("Channel", channel.name);
            if (message.publisher) {
                let publisherId = message.publisher.id;
                console.log(publisherId);
            }
        })
        .then((id) => {
            console.log("Subscription ID");
            console.log(id);
        });
#

I have also opened a ticket: 1217432534 for documenting

candid oxide
#

Hi @thin ibex
One of our developers tried recreating this and he encountered the same issue.
It's not available in Blocks at the moment we opened a feature request and we will let you know when it will. 🙏

onyx fossil
thin ibex
#

@candid oxide will it not work with either Velo or NPM module? Becuase npm module does mention the API is intended to be used when coding in Blocks.