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

Access WAMP Topics inside WampServerInterface #310

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

CupOfTea696
Copy link

Access all WAMP Topics inside the WampServerInterface by optionally using the TopicAccess Trait.

@cboden
Copy link
Member

cboden commented May 26, 2015

Can you provide a use case for this?

@CupOfTea696
Copy link
Author

When pushing messages, access to the topics would allow to push them to specific clients (when you set for example the session ID on the topics) like so:

    /**
     * Handle Push messages
     *
     * @param string $message
     * @return void
     * @throws \CupOfTea\TwoStream\Exception\InvalidRecipientException
     */
    public function push($message){
        $message = json_decode($message, true);
        $topic = array_get($this->getTopics(), $message['topic']);
        $data = $message['data'];
        $recipient = array_get($message, 'recipient');

        if (!$topic)
            return;

        if ($recipient == 'all') {
            $topic->broadcast($data);
        } else {
            foreach ((array) $recipient as $recipient) {
                // TODO: if translateUserToSessionId ||
                if (WsSession::isValidId($recipient)) {
                    foreach ($topic->getIterator() as $client) {
                        if ($client->session == $recipient)
                            $client->event($topic->getId(), $data);
                    }
                } else {
                    throw new InvalidRecipientException($recipient);
                }
            }
        }
    }

This piece of code comes directly from my WebSocket package for Laravel, called TwoStream

@CupOfTea696
Copy link
Author

@cboden any news on this?

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.

None yet

2 participants