public function socketAuth($channel, $socketId, $customData = null)
    {
        if (preg_match('/^[-a-z0-9_=@,.;]+$/i', $channel) !== 1) {
            throw new BroadcastException('Invalid channel name ' .$channel);
        }

        if (preg_match('/^(?:\/[a-z0-9]+#)?[a-z0-9]+$/i', $socketId) !== 1) {
            throw new BroadcastException('Invalid socket ID ' .$socketId);
        }

        if (! is_null($customData)) {
            $signature = hash_hmac('sha256', $socketId .':' .$channel .':' .$customData, $this->secretKey, false);
        } else {
            $signature = hash_hmac('sha256', $socketId .':' .$channel, $this->secretKey, false);
        }

        $signature = array('auth' => $signature);

        // Add the custom data if it has been supplied.
        if (! is_null($customData)) {
            $signature['payload'] = $customData;
        }

        return json_encode($signature);
    }