ux
ux copied to clipboard
Topic name hashed/encoded
Hi,
When using the turbo_stream_listen(<topic_name>) function, it would be nice if the topic was hashed/encoded.
The same applies to:
$hub->publish(new Update(
<topic_name>,
$this->renderView('chat/message.stream.html.twig', ['message' => $data['message']])
));
The same applies to:
// src/Entity/Book.php
namespace App\Entity;
use Symfony\UX\Turbo\Attribute\Broadcast;
#[Broadcast(topics: ['@="<topic_name>", 'books'], template: 'book_list.stream.html.twig', private: true)]
class Book
{
// ...
}
For example, I used the following code:
<div id="songs" {{ turbo_stream_listen('songs_by_artist_' ~ app.user.id) }}></div>
This generated:
<div id="songs" data-controller="symfony--ux-turbo-mercure--turbo-stream" data-symfony--ux-turbo-mercure--turbo-stream-topic-value="songs_by_artist_21" data-symfony--ux-turbo-mercure--turbo-stream-hub-value="http://127.0.0.1:59632/.well-known/mercure"></div>
I find it a shame to have songs_by_artist_21 and not a string for instance : ZmViZDE3OWE3Zjk4MDM2NTBmZDI1N2FiYWUwMjFmYmY4OTAzNzJkNjA5NTA1OGQ3NWI2NGRlYTkzNjYwODliYg==
I would like your feedback :)
Hi!
This may be something that is needed in some cases... where your channel names need to be obscured for some reason. But I think it's outside the scope if the package. Is there any spot where creating and using your own hashed topic name is not currently feasible due to some limitations in the library?
Cheers!
Is there any spot where creating and using your own hashed topic name is not currently feasible due to some limitations in the library?
Yes, for instance:
#[Broadcast(topics: ['@=service("App\\Service\\Generator").generate("songs_by_artist_" ~ entity.getId())'])]
Using a service does not work. Finally I got the error:
The function "service" does not exist around position 1 for expression container('App\\Service\\Generator').generate().
I suppose we could allow services to be fetched here - could you open a dedicated issue or PR?
Close for #446