You have to use the Node.js package in combination with the Laravel package. #Installation npm install wiconnect
#How to use Copy the index.js from the example folder to your main application and adapt it.
##Necessary steps:
-
Set the path to the npm module
var weinspire = require("wiconnect");
-
Adapt the CONFIG-Array
CONFIG = []; CONFIG.wsprefix = "/sockjs"; CONFIG.wsport = 3000; CONFIG.dnode_listen_port = 5004; CONFIG.dnode_send_port = 5005;
-
Create a http-Server
var httpServer = http.createServer(); httpServer.listen(CONFIG.wsport,'0.0.0.0');
-
Start the package
var serverinterface = weinspire(httpServer);
-
Replace and set the tables, which should accessable via publishSubscriptionns.
serverinterface.ddpServer.publishSubscription("posts",function(){ var obj = {}; obj.table = "posts"; return obj; });
NOTICE: Take care of security issues
-
Connect DDP with dNode-functions
serverinterface.dnode.on("getUserSession",serverinterface.ddpServer.setUserSession); serverinterface.dnode.on("getData",serverinterface.ddpServer.dataSetChanged);
#Client: You will get a client with the laravel package. You can send packages to the Node.js-Server with javascript-commands.
- Subscribe to a subscription published on the server
var handle = connection.subscribe("table")
- Cancel a subscription
handle.stop();
- Send a broadcast
connection.subscribeBroadcast("channel",dadaobj);
- Subscribe to a broadcast-channel
connection.subscribeBroadcast("channel");
- Cancel broadcast-subscription
handle.stop();
- Receive messages
connection.on('chats', function(doc, messagetype){});
- Receive broadcasts
connection.on('broadcast', function(message){});