Friday, 15 June 2012

symfony - Include Node.JS + Socket.IO in Symfony2 application -


I did a lot of research and it seems that I can not find the right solution, I believe in PHP, I Node I have also done some tutorials on JS and socket.IO and I am currently learning Symfony2 but I do not know how to achieve my goal You can merge both.

My goal is to set up a real-time notification for back-end users of my app. This app is an e-commerce website and I warn the administrator in the upper right corner of the panel by ordering a view notification I want the administration behind the scenes to give My server uses FreeBSD .

My plan is to use Node.JS and Socket.IO to achieve it. If I have a better plan, then I will talk about it. I want to hear in Otherwise, I will not find the appropriate resource telling me that I node How can I include JS and Socket.IO in a Symfony2 app. I use the musician to install the bundle, but I have not used NPM with Symfony2.

I have found, and to help me, but none of these can tell me how i node.js a symfony2 in the app .

If anyone can help me with the steps to complete this facility, I would be happy.

Thank you!

For those who are interested in the answer:

$ Su -

Node Install JS

$ cd / usr / ports / www / node

$ clean install

Install NPM

$ cd / usr / ports / www / npm

$ Install clean $

install socket.io

$ cd / path / to / your / project / Js / public / files

$ npm installed socket.io

code development

app.js

  requires var http = ('http'); Var FS = Requirement ('FS'); Var server = http.createServer (function (req, res) {fs.readFile ('./ index.html', 'utf-8', function (error, content) {res.writeHead (200, {"content-type ":" Text / html "}); res.end (content);});}); Var io = Required ('socket.io'). Listen (server); Io.sockets.on ('connection', function (socket) {socket.on ('newOrder', function) (socket.broadcast.emit ('message', 'Nouvelle commande');});}); Server.listen (4321);   

Front-end

  & lt; Script src = "{{asset ('http: // localhost: 4321 / Socket.io/socket.io.js')}}" & gt; & Lt; / Script & gt; & Lt; Script & gt; Jquery (function ($) {var socket = io.connect ('http: // localhost: 4321'); $ ('form'). ('Submit', function () {socket.emit ('newOrder' '1');});}); & Lt; / Script & gt;  

back-end

  & lt; Script & gt; JQuery (function ($) {var socket = io.connect ('http: // localhost: 4321'); socket.on ('message', function (message) {warning (message);});}); & Lt; / Script & gt;  

Launch Server

$ node app.js

All of these!


No comments:

Post a Comment