pusher / pusher-http-php

PHP library for interacting with the Pusher Channels HTTP API
https://pusher.com/docs/server_api_guide
1.42k stars 309 forks source link

Trigger a single event on multiple encrypted channels #334

Closed andrew-bibby closed 2 years ago

andrew-bibby commented 2 years ago

I am using Laravel to broadcast to multiple channels at once, and now want to use e2e. Previously I would trigger one event broadcast to many different channels in one job by returning an array of private channels.

Would you be willing to consider a PR to allow events to be triggered on multiple encrypted channels? I have read the rationale in the readme however could it be possible to check that the specified channels are not a mixture of encrypted/unencrypted channels and if so just throw an exception?

Something like:


  if ($has_encrypted_channel) {
    if (PusherCrypto::has_mixed_channels($channels)) {
        throw new PusherException('You cannot trigger to multiple channels of different encryption type');
    } else {
        try {
            $data_encoded = $this->crypto->encrypt_payload(
                $channels[0],
                $already_encoded ? $data : json_encode($data, JSON_THROW_ON_ERROR)
            );
        } catch (\JsonException $e) {
            throw new PusherException('Data encoding error.');
        }
    }
} else {
    try {
        $data_encoded = $already_encoded ? $data : json_encode($data, JSON_THROW_ON_ERROR);
    } catch (\JsonException $e) {
        throw new PusherException('Data encoding error.');
    }
}

Alternatively it could be handled when validating the channels and throw in a different location?

Thanks. 👍

benjamin-tang-pusher commented 2 years ago

Hi, have you tested this in your own application, and is it able to trigger to multiple encrypted channels?

andrew-bibby commented 2 years ago

Yes I have created PR #337

benjamin-tang-pusher commented 2 years ago

https://github.com/pusher/pusher-http-php/pull/337 merged.