مهدی
4 سال پیش توسط مهدی مطرح شد
2 پاسخ

اتصال خصوصی در پوشر

سلام دوستان
من سعی میکنم با لاراول به یک کانال خصوصی شنود کنم که نیازمنده احراز هویت لاراول هست
اینکارو میکنم ولی نمیتونه وصل بشه
endPoint هم بدرستی ست کردم ولی جالبه وقتی broadcasting/auth رو در مرورگر اجرا میکنم هدایت میکنه به صفحه لاگین یا اگه لاگین باشه صفحه هوم رو بر میگردونه که ظاهرا فرمت درستی برای پوشر نیست... چیکار باید بکنم
به محض اینکه میرسه به خط اتصال به کانال خصوصی میخواد احراز هویت کنه ولی خطا میده
تنظمیات من :

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'sadkjlkjsdklfjslkdjfsdf',
    cluster: 'eu',
    encrypted: false,
    logToConsole: true,
    authEndpoint: 'http://localhost/pusher/public/broadcasting/auth',
});
    Echo.private('chats.{{ Auth::id() }}')
        .listen('NewMessageNotification', (e) => {
            alert(e.message.message);
        });
Broadcast::channel('chats.{id}', function ($user, $id) {
    return true;
});
    public function boot()
    {
        Broadcast::routes();
        Broadcast::routes(["middleware" => ["auth:sanctum"]]);

        require base_path('routes/channels.php');
    }

خطای زیر رو میده

Pusher :  : ["Error: JSON returned from auth endpoint was invalid, yet status code was 200. Data was: \n<html lang=\"en\">\n    <head>\n        <meta charset=\"utf-8\">\n        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n        <meta name=\"csrf-token\" content=\"t3nAG1B1AyTUJ2ebkfLdH1qUpLGRmiftmtD1MbEq\">\n\n        <title>Laravel</title>\n\n        <!-- Fonts -->\n        <link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap\">\n\n        <!-- Styles -->\n        <link rel=\"stylesheet\" href=\"http://localhost/pusher/public/css/app.css\">\n\n        <style>[wire\\:loading], [wire\\:loading\\.delay] {display: none;}[wire\\:offline] {display: none;}[wire\\:dirty]:not(textarea):not(input):not(select) {display: none;}</style>\n\n        <!-- Scripts -->\n        <script src=\"https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.6.0/dist/alpine.js\" defer></script>\n    </head>\n    <body class=\"font-sans antialiased\">\n        <div class=\"min-h-screen bg-gray-100\">\n            <nav wire:id=\"pCZDXW0ogdJqU9P76FpT\" wire:initial-data=\"{&quot;fingerprint&quot;:{&quot;id&quot;:&quot;pCZDXW0ogdJqU9P76FpT&quot;,&quot;name&quot;:&quot;navigation-dropdown&quot;,&quot;locale&quot;:&quot;en&quot;},&quot;effects&quot;:{&quot;listeners&quot;:[&quot;refresh-navigation-dropdown&quot;]},&quot;serverMemo&quot;:{&quot;children&quot;:[],&quot;errors&quot;:[],&quot;htmlHash&quot;:&quot;66622e31&quot;,&quot;data&quot;:[],&quot;dataMeta&quot;:[],&quot;checksum&quot;:&quot;3642cb28e54b86dc691681e95904ee181517843c1d65383eecdb61eacf2785c1&quot;}}\" x-data=\"{ open: false }\" class=\"bg-white border-b border-gray-100\">\n    <!-- Primary Navigation Menu -->\n    <div class=\"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8\">\n        <div class=\"flex justify-between h-16\">\n            <div class=\"flex\">\n                <!-- Logo -->\n                <div class=\"flex-shrink-0 flex items-center\">\n                    <a href=\"http://localhost/pusher/public/dashboard\">\n                         <svg viewBox=\"0 0 48 48\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\" class=\"block h-9 w-auto\">\n  <path d=\"M11.395 44.428C4.557 40.198 0 32.632 0 24 0 10.745 10.745 0 24 0a23.891 23.891 0 0113.997 4.502c-.2 17.907-11.097 33.245-26.602 39.926z\" fill=\"#6875F5\"/>\n  <path d=\"M14.134 45.885A23.914 23.914 0 0024 48c13.255 0 24-10.745 24-24 0-3.516-.756-6.856-2.115-9.866-4.659 15.143-16.608 27.092-31.75 31.751z\" fill=\"#6875F5\"/>\n</svg>\n \n                    </a>\n                </div>\n\n                <!-- Navigation Links -->\n                <div class=\"hidden space-x-8 sm:-my-px sm:ml-10 sm:flex\">\n                     <a class=\"inline-flex items-center px-1 pt-1 border-b-2 border-indigo-400 text-sm font-medium leading-5 text-gray-900 focus:outline-none focus:border-indigo-700 transition duration-150 ease-in-out\" href=\"http://localhost/pusher/public/dashboard\">\n    Dashboard\n</a>\n \n                </div>\n            </div>\n\n            <!-- Settings Dropdown -->\n            <div class=\"hidden sm:flex sm:items-center sm:ml-6\">\n                 <div class=\"relative\" x-data=\"{ open: false }\" @click.away=\"open = false\" @close.stop=\"open = false\">\n    <div @click=\"open = ! open\">\n        <button class=\"flex text-sm border-2 border-transparent rounded-full focus:outline-none focus:border-gray-300 transition duration-150 ease-in-out\">\n                            <img class=\"h-8 w-8 rounded-full object-cover\" src=\"https://ui-avatars.com/api/?name=Mehdi+Hesami&amp;color=7F9CF5&amp;background=EBF4FF\" alt=\"Mehdi Hesami\" />\n                        </button>\n    </div>\n\n    <div x-show=\"open\"\n            x-transition:enter=\"transition ease-out duration-200\"\n            x-transition:enter-start=\"transform opacity-0 scale-95\"\n            x-transition:enter-end=\"transform opacity-100 scale-100\"\n            x-transition:leave=\"transition ease-in duration-75\"\n            x-transition:leave-start=\"transform opacity-100 scale-100\"\n            x-transition:leave-end=\"transform opacity-0 scale-95\"\n            class=\"absolute z-50 mt-2 w-48 rounded-md shadow-lg origin-top-right right-0\"\n            style=\"display: none;\"\n            @click=\"open = false\">\n        <div class=\"rounded-md shadow-xs py-1 bg-white\">\n            <!-- Account Management -->\n                        <div class=\"block px-4 py-2 text-xs text-gray-400\">\n                            Manage Account\n                        </div>\n\n                         <a class=\"block px-4 py-2 text-sm leading-5 text-gray-700 hover:bg-gray-100 focus:outline-none focus:bg-gray-100 transition duration-150 ease-in-out\" href=\"http://localhost/pusher/public/user/profile\">Profile</a>\n \n\n                                                     <a class=\"block px-4 py-2 text-sm leading-5 text-gray-700 hover:bg-gra

ثبت پرسش جدید
امیرحسین عنبری
تخصص : Web application developer
@amiranbari33 4 سال پیش مطرح شد
0

میگه authendpoin درست نیست


ag7
@ali.gohari7 3 سال پیش آپدیت شد
0

js

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: 'key',
    cluster: 'cluster',
    encrypted: true
});
Echo.private('name').listen('.name-event', function (e) {
        var a_text = e.text;
        alert(a_text)
});

channels.php

Broadcast::channel('name.{id}', function ($id) {
    if (auth()->user())
        if (auth()->user()->id== $id)
            return true;
    return false;
});

event

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class Name implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $id;
    public $text;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($id,$text)
    {
        $this->id = $id;
        $this->text = $text;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        //return new Channel('notifications.user.'.$this->code);
        return new PrivateChannel('name.'.$this->id);
    }

    public function broadcastAs()
    {
        return 'name-event';
    }
}

برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام