Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {"event":"App\Events\EventName","data":{"data":{"power":"10"}},"socket":null}
- <?php
- /*
- |--------------------------------------------------------------------------
- | Web Routes
- |--------------------------------------------------------------------------
- |
- | Here is where you can register web routes for your application. These
- | routes are loaded by the RouteServiceProvider within a group which
- | contains the "web" middleware group. Now create something great!
- |
- */
- // Route::get('/', function () {
- // return view('welcome');
- // });
- Route::get('/', function() {
- // this doesn't do anything other than to
- // tell you to go to /fire
- return "go to /fire";
- });
- Route::get('fire', function () {
- // this fires the event
- event(new AppEventsEventName());
- return "event fired";
- });
- Route::get('test', function () {
- // this checks for the event
- return view('test');
- });
- BROADCAST_DRIVER=redis
- CACHE_DRIVER=file
- SESSION_DRIVER=file
- QUEUE_DRIVER=sync
- REDIS_HOST=127.0.0.1
- REDIS_PASSWORD=null
- REDIS_PORT=6379
- PUSHER_APP_ID=
- PUSHER_APP_KEY=
- PUSHER_APP_SECRET=
- var app = require('express')();
- var http = require('http').Server(app);
- var io = require('socket.io')(http);
- var Redis = require('ioredis');
- var redis = new Redis();
- redis.subscribe('test-channel', function(err, count) {
- });
- redis.on('message', function(channel, message) {
- console.log('Message Recieved: ' + message);
- message = JSON.parse(message);
- io.emit(channel + ':' + message.event, message.data);
- });
- http.listen(3000, function(){
- console.log('Listening on Port 3000');
- });
- namespace AppEvents;
- use IlluminateBroadcastingChannel;
- use IlluminateQueueSerializesModels;
- use IlluminateContractsBroadcastingShouldBroadcast;
- class EventName implements ShouldBroadcast
- {
- use SerializesModels;
- /**
- * Create a new event instance.
- *
- * @return void
- */
- public $data;
- public function __construct()
- {
- $this->data = array(
- 'power'=> '10'
- );
- }
- public function broadcastOn()
- {
- return ['test-channel'];
- }
- }
- @extends('layouts.master')
- @section('content')
- <p id="power">0</p>
- @stop
- @section('footer')
- <script src="https://cdn.socket.io/socket.io-1.3.5.js"></script>
- <script>
- var socket = io('http://localhost:3000');
- // var socket = io('http://192.168.10.10:3000');
- socket.on("test-channel:App\Events\EventName", function(message){
- // increase the power everytime we load test route
- $('#power').text(parseInt($('#power').text()) + parseInt(message.data.power));
- $('#power').text("testeste");
- // $('#power').text(parseInt($('#power').text()) + parseInt(message.data.power));
- });
- </script>
- @stop
Add Comment
Please, Sign In to add comment