Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add topic filter for event WebSocket #4550

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

florian-h05
Copy link
Contributor

@florian-h05 florian-h05 commented Jan 9, 2025

Closes #4549.
Closes #3764.

The topic filter can be configured by sending a WS message like in following examples:

Only send all ItemCommandEvents:

{
  "type": "WebSocketEvent",
  "topic": "openhab/websocket/filter/topic",
  "payload": "[\"openhab/items/*/command\"]",
  "source": "ui-c2ead538aa"
}

Only send all ItemCommandEvents, except for the test Item:

{
  "type": "WebSocketEvent",
  "topic": "openhab/websocket/filter/topic",
  "payload": "[\"openhab/items/*/command\", \"!openhab/items/test/command\"]",
  "source": "ui-c2ead538aa"
}

Send all events, except ItemCommandEvents:

{
  "type": "WebSocketEvent",
  "topic": "openhab/websocket/filter/topic",
  "payload": "[\"!openhab/items/*/command\"]",
  "source": "ui-c2ead538aa"
}

Signed-off-by: Florian Hotze <[email protected]>
@florian-h05 florian-h05 marked this pull request as ready for review January 9, 2025 19:05
@florian-h05 florian-h05 requested a review from a team as a code owner January 9, 2025 19:05
florian-h05 added a commit to florian-h05/openhab-webui that referenced this pull request Jan 9, 2025
@florian-h05
Copy link
Contributor Author

@ghys We are getting close to have the event WS support everything we need in the UI 🚀

@spacemanspiff2007
Copy link
Contributor

Would it be possible to provide a negative and positive filter here, too?
E.g. a filter that passes certain topics and a filter that rejects them?

@florian-h05
Copy link
Contributor Author

Added just a few seconds ago 👍
See the PR description for how to use that.

Signed-off-by: Florian Hotze <[email protected]>
@spacemanspiff2007
Copy link
Contributor

Is the topic not a regular expression? Is it something openhab specific?

@florian-h05
Copy link
Contributor Author

Topics can be defined as string with the * wildcard, see SSE events.
Internally, the topic expressions are converted to RegEx, during this conversion I can check whether the topic is to include or to ! exclude.

@spacemanspiff2007
Copy link
Contributor

spacemanspiff2007 commented Jan 10, 2025

If you look at the /items endpoint some time ago there was a switch away from the openhab specific wildcard implementation to a regular expression.
Do you think it would make sense to use a normal regular expression here, too?

grafik

@florian-h05
Copy link
Contributor Author

Do you think it would make sense to use a normal regular expression here, too?

I don‘t think that the additional regex features would be a benefit here, I think the wildcard is enough.

@spacemanspiff2007
Copy link
Contributor

I don‘t think that the additional regex features would be a benefit here, I think the wildcard is enough.

But why use an custom openhab wildcard implementation which then gets internally converted into regex instead of just allowing a regex from the start instead?
This seems overly complicated and unnecessarily restrictive.

@florian-h05
Copy link
Contributor Author

It makes the filters easier to use from clients though, as you can simply specify the topic with wildcards and don't need to take care of the RegEx.
The SSE event subscription is there since at least 2019 and since then no one ever asked for RegEx support for the topic filter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Event WebSocket: Add topic filter Support topic filters in the WebSocket API
2 participants