I need to use different Pusher account for a specific part of my web app, so I tried to override the config using the following:
public function send(Request $request)
{
$general_pusher = config('broadcasting.connections.pusher');
$message = Message::create([
'from' => auth()->id(),
'to' => $request->contact_id,
'text' => $request->text
]);
\Config::set('broadcasting.connections.pusher', config('cfg.internal_chat_pusher'));
logger(config('broadcasting.connections.pusher'));
broadcast(new NewMessage($message));
\Config::set('broadcasting.connections.pusher', config('cfg.internal_chat_pusher'));
return response()->json($message);
}
then, I tried to test using a random value for which Laravel should raise an error, but no error and the messages get sent and received, but using the original/old pusher config values.
as you can see I used the logger
instruction which give me the following:
[2020-09-19 14:06:09] local.DEBUG: array (
'driver' => 'pusher',
'key' => '1',
'secret' => '1',
'app_id' => '1',
'options' =>
array (
'cluster' => '1',
'useTLS' => true,
),
)
but, even though the logger
command output the values that should give the error, I get no error, and messages get sent and received perfectly.
how to use different pusher account for a specific event?
Update:
I tried to edit the brodcasting.php as follow:
'connections' => [
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => true,
],
],
'redis' => [
'driver' => 'redis',
'connection' => 'default',
],
'log' => [
'driver' => 'log',
],
'null' => [
'driver' => 'null',
],
'internal_chat_pusher' => [
'driver' => 'pusher',
'key' => env('INTERNAL_CHAT_PUSHER_APP_KEY'),
'secret' => env('INTERNAL_CHAT_PUSHER_APP_SECRET'),
'app_id' => env('INTERNAL_CHAT_PUSHER_APP_ID'),
'options' => [
'cluster' => env('INTERNAL_CHAT_PUSHER_APP_CLUSTER', 'ap2'),
'useTLS' => true,
]
],
],
];
then in the send function inside the controller:
public function send(Request $request)
{
$message = Message::create([
'from' => auth()->id(),
'to' => $request->contact_id,
'text' => $request->text
]);
Broadcast::driver('internal_chat_pusher');
broadcast(new NewMessage($message));
return response()->json($message);
}
}
but still, the messages are sent using the original/old account configs.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire