ux icon indicating copy to clipboard operation
ux copied to clipboard

Topic name hashed/encoded

Open seb-jean opened this issue 3 years ago • 1 comments

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 :)

seb-jean avatar Aug 19 '22 20:08 seb-jean

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!

weaverryan avatar Aug 23 '22 13:08 weaverryan

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().

seb-jean avatar Aug 29 '22 15:08 seb-jean

I suppose we could allow services to be fetched here - could you open a dedicated issue or PR?

weaverryan avatar Aug 31 '22 12:08 weaverryan

Close for #446

seb-jean avatar Aug 31 '22 13:08 seb-jean