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

Pusher documentation for version 3 #450

Open
krajcikondra opened this issue Oct 25, 2021 · 2 comments
Open

Pusher documentation for version 3 #450

krajcikondra opened this issue Oct 25, 2021 · 2 comments

Comments

@krajcikondra
Copy link

krajcikondra commented Oct 25, 2021

Hi,

I want to send message to my websocket Topic from controller. I found documentation for version 2 but for version 3 is missing.

Have I use symfony/messenger for version 3 instead pushers?

Is there some example of using? I am newbiew in symfony and websockets and some example will help me.

Thanks

This is my ChatTopic where I need implement ReceiiverInterface

<?php

namespace App\Websocket\Topic;

use Gos\Bundle\WebSocketBundle\Client\ClientManipulatorInterface;
use Gos\Bundle\WebSocketBundle\Router\WampRequest;
use Ratchet\ConnectionInterface;
use Ratchet\Wamp\Topic;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface;
use Symfony\Component\Serializer\Serializer;

final class ChatTopic extends BaseTopic implements ReceiverInterface
{

	private Serializer $serializer;

	public function __construct(
		ClientManipulatorInterface $clientManipulator,
		Serializer $serializer
	) {
		parent::__construct($clientManipulator);
		$this->serializer = $serializer;
	}

	public function onSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request): void
	{
		$topic->broadcast([
			'msg' => $connection->resourceId.' has joined '.$topic->getId(),
			'msgType' => 'subscribeUser',
		]);
	}

	public function onUnSubscribe(ConnectionInterface $connection, Topic $topic, WampRequest $request): void
	{
		$topic->broadcast([
			'msg' => $connection->resourceId.' has left '.$topic->getId(),
			'msgType' => 'unsubscribeUser',
		]);
	}

	public function onPublish(
		ConnectionInterface $connection,
		Topic $topic,
		WampRequest $request,
        $event,
		array $exclude,
		array $eligible
	): void {
		$message = $this->getTextMessage($event);
		$receiverSessionId = $this->getSessionId($topic, (string) $event['receiverIdentifier']); // @phpstan-ignore-line
		$this->logger->log('info', 'sessionId = ' . $connection->WAMP->sessionId); // @phpstan-ignore-line

		$topic->broadcast([
			'msg' => $message,
			'msgType' => 'userMessage',
		],
			[],
			[$receiverSessionId]
		);
	}

	public function getName(): string
	{
		return 'chat.topic';
	}

	public function get(): iterable
	{
		// here I need $topic and broadcast message from envelope to websocket clients
	}

	public function ack(Envelope $envelope): void
	{
		// TODO: Implement ack() method.
	}

	public function reject(Envelope $envelope): void
	{
		// TODO: Implement reject() method.
	}
}

@ViktorieTrungerova
Copy link

Same problem :(

I tried use older version but is not compatible with symfony 5.

It is possible use deprecated WampPusher class? I haven`t registered WampPusher as service. When I register WampPusher as service I get error that WampPusher need WampRouter which is not registered as service. WampRouter has depencency of type RouterInterface .....

How can I register all necessary services? Am I doing something bad?

Unfortunatelly in docs missing example

@LucasWerner437
Copy link

Same problem, here. I opened another issue :

https://github.com/GeniusesOfSymfony/WebSocketBundle/issues/463

I'm posting this here in case someone has an answer.

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

No branches or pull requests

3 participants