Skip to content

Namespace in channels #592

@alijmlzd

Description

@alijmlzd

I have different apps that all use a shared socketcluster server for PubSub.

I want to separate each app's channel names to prevent conflicts so I can have the same channel names for different apps.

I tried to prefix the channel name with the app ID on the subscribe middleware on the server - something like app1/my-channel, app2/my-channel - but not luck.

I know that I can just subscribe to app1/my-channel channel from the client but in this case, it is not suitable for me and I want to let clients just subscribe to my-channel and the server handle the namespacing based on my client app.

How can I do namespace channels to achieve this or any other solution?

Here is my code that not working:

agServer.setMiddleware(
    agServer.MIDDLEWARE_INBOUND,
    async (middlewareStream) => {
        for await (let action of middlewareStream) {
            if (action.type === action.SUBSCRIBE) {
                    action.channel = `${appId}/${action.channel}`;
                }
            }
            action.allow();
        }
    }
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions