第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

是否可以在 laravel echo 中向通道發(fā)送數(shù)據(jù)?

是否可以在 laravel echo 中向通道發(fā)送數(shù)據(jù)?

PHP
守候你守候我 2023-09-22 16:39:30
我有兩個單獨的 laravel 項目,并安裝在其中一個項目laravel-echo和另一個項目上laravel-echo-server。我將這個項目連接在一起并將數(shù)據(jù)從服務器傳輸?shù)娇蛻舳?,但我無法將數(shù)據(jù)從客戶端發(fā)送到服務器。服務器中的事件:class TestEvent implements ShouldBroadcast{    use Dispatchable, InteractsWithSockets, SerializesModels;    public $prices;    /**     * Create a new event instance.     *     * @param int[] $prices     */    public function __construct($prices = ['a' => 11000, 'b' => 420])    {        $this->prices = $prices;    }    /**     * Get the channels the event should broadcast on.     *     * @return \Illuminate\Broadcasting\Channel|array     */    public function broadcastOn()    {        return new PresenceChannel('bla-bla');    }    public function broadcastAs()    {        return 'financial.prices';    }}服務器中的路線:Route::get('/fire', function () {    $prices = [        'a' => rand(11000, 120000),        'b' => rand(450, 5000)    ];    event(new \App\Events\TestEvent($prices));    return 'done';});客戶:import Echo from 'laravel-echo';window.io = require('socket.io-client');window.Echo = new Echo({    broadcaster: 'socket.io',    host: window.location.hostname + ':6001',    logToConsole: true});window.Echo.logToConsole = true;window.Echo.join('bla-bla')    .here((data) => {        console.log('asdasd');    })    .joining((data) => {        console.log('asdasd');    })    .leaving((data) => {        console.log('asdasd');    });我怎樣才能做到這一點?如果有人能給我建議,我將不勝感激!??
查看完整描述

3 回答

?
梵蒂岡之花

TA貢獻1900條經(jīng)驗 獲得超5個贊

連接到套接字服務器后需要使用emit:


window.io = require('socket.io-client');

const socket = io('https://localhost:8080');


socket.on('connect', () => {

    socket.emit('your_channel_to_emit', {your_data});

});


查看完整回答
反對 回復 2023-09-22
?
慕的地6264312

TA貢獻1817條經(jīng)驗 獲得超6個贊

將其添加到您的事件 (App\EventName):


public function broadcastWith()

{

    return [

        'data' => "your data",

        'moredata' => "more data",

    ];

}

并在 JS 中像這樣訪問您的數(shù)據(jù):


Echo.channel('channel-name')

    .listen('EventName', (event) => {

        console.log(event.data);

        console.log(event.moredata);

        console.log(event['moredata']);

    }


查看完整回答
反對 回復 2023-09-22
?
開心每一天1111

TA貢獻1836條經(jīng)驗 獲得超13個贊

默認情況下,Echo 將使用/broadcasting/auth端點來授權通道訪問。如果您的客戶端不在同一主機上,您將必須自定義推送器的 authEndpoint。authEndpoint您可以通過將配置選項傳遞給您的 Echo 實例來指定您自己的授權端點:


window.Echo = new Echo({

    broadcaster: 'pusher',

    key: 'your-pusher-channels-key',

    authEndpoint: '/custom/endpoint/auth', //customize here.

});


查看完整回答
反對 回復 2023-09-22
  • 3 回答
  • 0 關注
  • 130 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號