1 year ago

#313137

test-img

Mobarok Hossen

Pusher\\ApiErrorException(code: 0) error in Chat system

After Message save broadcasting occurs this issue:

local.ERROR: {"userId":3,"exception":"[object] (Pusher\ApiErrorException(code: 0): at C:\xampp\htdocs\fm\script\vendor\pusher\pusher-php-server\src\Pusher.php:533) [stacktrace] #0 C:\xampp\htdocs\fm\script\vendor
nahid\talk\src\Live\Webcast.php(51): Pusher\Pusher->trigger(Array, 'talk-send-messa...', Array)

nahid\talk\src\Live\Broadcast.php(85): Nahid\Talk\Live\Broadcast->dispatch(Object(Nahid\Talk\Live\Webcast)) #22 C:\xampp\htdocs\fm\script\vendor
nahid\talk\src\Talk.php(106): Nahid\Talk\Live\Broadcast->transmission(Object(Nahid\Talk\Messages\Message)) #23 C:\xampp\htdocs\fm\script\vendor
nahid\talk\src\Talk.php(268): Nahid\Talk\Talk->makeMessage(2, Object(Nahid\Talk\Messages\Message))

Pages:

Webcast.php

 class Webcast implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    /*
   * Message Model Instance
   *
   * @var object
   * */
    protected $message;

    /*
     * Broadcast class instance
     *
     * @var object
     * */
    protected $broadcast;

    /**
     * Set message collections to the properties.
     */
    public function __construct($message)
    {
        $this->message = $message;
    }

    /*
     * Execute the job and broadcast to the pusher channels
     *
     * @param \Nahid\Talk\Live\Broadcast $broadcast
     * @return void
     */
    public function handle(Broadcast $broadcast)
    {
        $this->broadcast = $broadcast;
        $senderIdKey = $this->broadcast->getConfig('user.ownerKey') ? $this->broadcast->getConfig('user.ownerKey') : 'id';
        $toUser = ($this->message['sender'][ $senderIdKey] == $this->message['conversation']['user_one']) ? $this->message['conversation']['user_two'] : $this->message['conversation']['user_one'];

        $channelForUser = $this->broadcast->getConfig('broadcast.app_name').'-user-'.$toUser;
        $channelForConversation = $this->broadcast->getConfig('broadcast.app_name').'-conversation-'.$this->message['conversation_id'];

//        try {

            $this->broadcast->pusher->trigger([sha1($channelForUser), sha1($channelForConversation)], 'talk-send-message', $this->message);
//        } catch (ApiErrorException $e) {
//            throw new BroadcastException(
//                sprintf('Pusher error: %s.', $e->getMessage())
//            );
//        }
    }
}

Broadcast.php

class Broadcast
{
    use DispatchesJobs;

    /*
     * Constant for talk config prefix
     *
     * @const string
     * */
    const CONFIG_PATH = 'talk';

    /*
   * Set all configs from talk configurations
   *
   * @var array
   * */
    protected $config;


    /*
   * Pusher instance
   *
   * @var object
   * */
    public $pusher;

    /**
     * Connect pusher and get all credentials from config.
     *
     * @param \Illuminate\Contracts\Config\Repository $config
     */
    public function __construct(Repository $config)
    {
        $this->config = $config;
        $this->pusher = $this->connectPusher();
    }

    /**
     * Make pusher connection.
     *
     * @param array $options
     *
     * @return object | bool
     */
    protected function connectPusher($options = [])
    {
        if ($this->getConfig('broadcast.enable')) {
            $appId = $this->getConfig('broadcast.pusher.app_id');
            $appKey = $this->getConfig('broadcast.pusher.app_key');
            $appSecret = $this->getConfig('broadcast.pusher.app_secret');
            $appOptions = $this->getConfig('broadcast.pusher.options');

            $newOptions = array_merge($appOptions, $options);
            $pusher = new Pusher($appKey, $appSecret, $appId, $newOptions);

            return $pusher;
        }

        return false;
    }

    /**
     * Dispatch the job to the queue.
     *
     * @param \Nahid\Talk\Messages\Message $message
     */
    public function transmission(Message $message)
    {
        if (!$this->pusher) {
            return false;
        }

        $sender = $message->sender->toArray();
        $messageArray = $message->toArray();
        $messageArray['sender'] = $sender;
        $this->dispatch(new Webcast($messageArray));
    }

    /**
     * get specific config from talk configurations.
     *
     * @param  string
     *
     * @return string|array|int
     */
    public function getConfig($name)
    {
        return $this->config->get(self::CONFIG_PATH.'.'.$name);
    }
}

ajax

laravel

chat

pusher

eventtrigger

0 Answers

Your Answer

Accepted video resources