我是nodeJS和faye/websockets的新手。
用webix创建了一个数据表,我想对它进行实时更新。
现在正试着和Faye在一起,但不太确定在Faye给我发了一个请求后我该怎么做,看起来像这样:
[{"channel":"/meta/handshake","version":"1.0","supportedConnectionTypes":["websocket","eventsource","long-polling","cross-origin-long-polling","callback-polling"],"id":"1"}]
并得到一个响应:
[{"id":"1","channel":"/meta/handshake","successful":true,"version":"1.0","supportedConnectionTypes":["long-polling","cross-origin-long-polling","callback-polling","websocket","eventsource","in-process"],"clientId":"8bkeysctea7ucerz9h3tyjz0n52s5os","advice":{"reconnect":"retry","interval":0,"timeout":45000}}]
在服务器(NodeJS)我有以下代码:
var http = require("http"),
faye = require("faye");
var server = http.createServer(function (request, response) {
//Here i have some code for the CRUD operations for the webix Datatable
}),
bayeux = new faye.NodeAdapter({ mount: '/faye', timeout: 45 });
bayeux.attach(server);
server.listen(1212, function () {
console.log("rn" + new Date() + "n -->> HTTP Server listens to Port 1212 <<--rn ");
});
客户端(JS):
webix.proxy.faye.client = new Faye.Client("//localhost:1212/faye");
webix.proxy.faye.clientId = webix.uid(); // unique client id
webix.proxy.faye.client.connect();
HTML:
<script type="text/javascript" src="//localhost:1212/faye/client.js"></script>
(从webix的例子+ faye的例子几乎所有的东西)
也许有人可以解释我下一步该做什么,或者给我一个链接,我可以阅读更多关于Websockets以及如何使用它们。
感谢您的宝贵时间。
在客户端和服务器端配置faye之后,您可以将其用作任何组件的数据源
{
view: "datatable",
url: "faye->/data",
save: "faye->/data"
}
注意faye仅用于在客户端之间同步数据,它不会将数据加载或保存到实际数据库