Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Laravel5.5 Broadcastingを使ってみた話

Laravel5.5 Broadcastingを使ってみた話

Akiyoshi Tanaka

November 15, 2017
Tweet

More Decks by Akiyoshi Tanaka

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ # ໊લ ాதষت / Akiyoshi TANAKA / @akkun_choi #

    ॴଐ גࣜձࣾBTree / ୅දऔక໾ / ΤϯδχΞ # ܦྺ PHP(ZF) -> Rails -> node.js -> Laravel(ॳ৺ऀ)
  2. ઃఆํ๏ - ϥΠϒϥϦΛΠϯετʔϧ - BroadcastServiceProviderΛ௥Ճ - Pusherઃఆ - .env -

    config/broadcasting.php - resources/assets/js/bootstrap.js $ npm install --save laravel-echo pusher-js $ composer require pusher/pusher-php-server "~2.6"
  3. ϒϩʔυΩϟετ͢Δ - ShouldBroadcastΛ࣮૷͢ΔΠϕϯτΛ࡞੒ - νϟϯωϧ͕2छྨ͋Δ - PrivateChannel - PresenceChannel (=

    PrivateChannel + α) - event() or broadcast() ͰૹΔ broadcast(new UserUpdated($user))->toOthers(); 4IPVME#SPBEDBTUΠϕϯτ
  4. ϒϩʔυΩϟετΛड͚औΔ - laravel-echo const channel = window.Echo.join('channel-name') .here((users) => {

    console.log('I'm here'); }) .joining((user) => { console.log('joining user', user); }) .leaving((user) => { console.log('leaving user', user); }) .listen('UserUpdated', (e) => { participants.update(e.user); })
  5. ཹҙ఺1: ೝূ - ೝূ͸ඞཁ - /broadcasting/auth ʹΞΫηε͢Δ - Auth::user() ͰϢʔβʔ͕औಘͰ͖Δඞཁ͕͋Δ

    - ͦͷͨΊʹɺࣄલʹAuth::login()͕ඞཁ - PublicChannel͸͋Γ·ͤΜ - Pusherʹ͸͋Δ͚ͲɺLaravelʹ͸ͳ͍
  6. ཹҙ఺3: ૹ৴஗͍ - ։ൃ༻ϏϧτΠϯαʔό - ϓϩηε1ͭͳͷͰɺେྔͷϦΫΤετ͸ࡹ͚ͳ͍ - ຊ൪͸WEBαʔόʔΛஔ͘͜ͱͰղܾ - Pusher

    - ૹ৴ͯ͠഑৴͞ΕΔ·Ͱ1ඵఔ౓͔͔͍ͬͯΔ - ཁҼ: ௨৴ճ਺૿, HTTPS, keep aliveແ͠, αʔόʔ͕γϯΨϙʔϧ - ղܾࡦ: pusher΁ͷૹ৴ํ๏Λ޻෉͢Δʁ
  7. ։ൃϝϯόʔืूʂ - Laravel - node.js - socket.io - Vue /

    React / angular - ۀ຿ҕୗɺϦϞʔτ։ൃ