You may find this tutorial useful. I haven't had time to dig into the subject myself yet, cheers!
Real Time, Web Sockets & Laravel?
I really enjoyed the Pusher video a week or 2 ago, but I'm wondering what else there is we can use for more real time applications. I'd really like to learn how to integrate web sockets into my applications. Maybe using something like Ratchet?
This is an interesting tutorial: https://medium.com/laravel-4/laravel-4-real-time-chat-eaa550829538
I started playing with Ratchet for a small script I was doing so javascript could communicate with php that would do the calculations. But I decided to give up and just do everything with javascript to avoid problems I was having (more with the flow I wanted to achieve than with configuring and using Ratchet, which this tutorial was great teaching me on how to use it). If I recall correctly one of the things that got in my nerves was that I used a javascript library (sorry, can't remember the name), which had little docs for v1 and all the nice things for v2, while Ratchet worked only with v1.
An easy way (not optime, I have just play with it, If there some one who has really use it and can help or give us some basics (loop, security... react php, ratchet) to try something with sockets Intall brainsocket and brainsocket js:
http://brainsocket.brainboxmedia.ca/ https://github.com/BrainBoxLabs/brain-socket https://github.com/BrainBoxLabs/brain-socket-js
(http://userscape.com/laracon/2014/jeremymikola.html )
Example: notify who is reading the same post. My question and what I don't know yet is how to improve not to have so many conection open, or is it very bad...I mean, X (1000) people reading, X opened connections. May be another way and better to use SSE?
a view:
{{ HTML::script('js/BS/brain-socket.min.js') }}
<script type="text/javascript">
$(document).ready(function(){
window.app = {};
app.BrainSocket = new BrainSocket(
new WebSocket('ws://localhost:8080'),
new BrainSocketPubSub()
);
app.BrainSocket.Event.listen('post-<?php echo $artikulu->id ?>',function(msg)
{
console.log(msg);
var me = {{ Auth::user()->id }} ;
if(msg.client.data.user_id != me )
$('#widget-content-1').append('<div class="ohar-mezua alert-success">'+msg.client.data.message+'</div>');
});
//$('#chat-message').on('click',function(e) {
setTimeout(function() {
app.BrainSocket.message('post-<?php echo $pos->id ?>',
{
'user_id':'{{ Auth::user()->id}}',
'message':'{{ Auth::user()->alias}} is reading this post'
}
);
},3000);
in a controller function (show($id) )
public function show($id)
{
$post = $this->postRepo->find($id);
Event::listen('artikulu-'.$id,function($client_data){
return BrainSocket::message('artikulu-'.$id,array('user_id'=>100,'message'=>'A message from a generic event fired in Laravel!'));
});
return View::make()->with(compact('post'));
}
I don't know why, but I can't get the message() sent by the server. So that should be fixed, otherwise, I suppose any one can change the JS and send any message...And in my case I don't want to do a chat room...laughs.
I'd love to see a few lessons on working with WebSockets... Perhaps even WebSockets, AngularJS, and Laravel for the backend logic.
Plus point in using Pusher is that you can easily integrate with most of the code languages/libraries. Like AngularJS.
Hey @jeffreyway how about a video using this package http://brainsocket.brainboxmedia.ca/ for lets say... facebook "like" real time notifications?
@hfalucas that would be pretty awesome if he did. I never knew that you could use Laravel with Websockets effectively. In most Laravel applications we "use the right tool for the right job", which normally involves either Python+Twisted/Tornado, or NodeJS to handle the web sockets, with a Redis queue linking the two applications together.
I was thinking about implementing something with Node.js then came across with that package @someguy123. Never used it before so I don't know if it's good or not, hopefuly will have time to play arround with it this weekend :)
+1 for that tutorial @hfalucas Nice find.
@hfalucas I think brain-socket doesn't support FIRING EVENTS from server! https://github.com/BrainBoxLabs/brain-socket/issues/1
+1 for a real time chat lesson by jeff :) Would be cool to use a self hosted chat server.
Socket.io and Laravel 4.2 video or series would be great :)
Pusher is nice but I try to avoid vendor bloat. Would be nice to have a video on socket.io + laravel.
BrainSocket looks really cool but I don't think it has support for Laravel 5 right now, so I wouldn't want to depend on it too much for new projects.
You can find a tutorial on SocketIO with Redis and Laravel 5 here . It work very nice but i think would be better to use the php-emitter. Probably another tutorial will come soon.
Watch out with using Ratchet and Autobahn. Ratchet supports WAMP v1 and Autobahn.js (latest) is supporting WAMP v2.
socket.io and laravel play really nice together. I created small social network using these technologies: http://larasocial.info The code is on github. Let me know if you have questions.
@msalom28 it is not possible to sign in - Your profile picture is required... even when I choose picture
+1000 for a real time chat lesson
@ddeath I am able to login with no problems. Try to login with one of the sample accounts.
For anyone that wasn't aware.. Jeffrey has started a Web Sockets series :) ..
https://laracasts.com/series/real-time-laravel-with-socket-io/episodes/1
And there is a further large discussion here about sockets and laravel etc
I've been using Ratchet for my Laravel Chat App, it's easy to install and easy to configure to your likings. I recommend Ratchet.
http://brainsocket.brainboxmedia.ca/ https://github.com/BrainBoxLabs/brain-socket https://github.com/BrainBoxLabs/brain-socket-js
seems promising but it is for Laravel 4.
Please or to participate in this conversation.