@7isys/loopback-component-realtime 中文文档教程
LoopBack Component Real-Time
一个 LoopBack Framework 组件,它通过 WebSockets 提供发布事件。
该模块将取代 LoopBack Component PubSub 并实现新的 FireLoop 模块。
Installation
$ npm install --save @mean-expert/{loopback-sdk-builder,loopback-component-realtime}
Setup Back End Module
更新 server/component-config.json
如下:
{
"loopback-component-explorer": {
"mountPath": "/explorer"
},
"@mean-expert/loopback-component-realtime": {
"debug": true,
"auth": true,
"driver": {
"name": "socket.io"
}
}
}
更新 server/model-config.json
如下:
{
"mixins": [
"loopback/common/mixins",
"loopback/server/mixins",
"../common/mixins",
"./mixins",
"../node_modules/@mean-expert/loopback-component-realtime/dist/mixins"
]
}
Enable Model to use FireLoop API
从版本 1.0.0-rc.8
您需要指定要在哪些模型中启用要发送的 FireLoop 事件。
说明:为了启用服务器和休息触发事件,引入了一个新的 mixin,这将触发来自 REST 调用或来自 NodeJS Api(例如 Model.create())的事件。
注意:由于 LoopBack 限制,服务器触发的事件仅可用于根模型方法 (Model.create()),但不适用于关系方法,这些将继续仅从 FireLoop 子引用中执行前端
{
"mixins": {
"FireLoop": true
}
}
Update Server
将应用程序从 LoopBack 传播到 FireLoop,因此只需通过编辑 app.start
方法更新文件 server/server.js
即可完成关注:
app.start = function() {
// start the web server
var server = app.listen(function() {
app.emit('started', server);
var baseUrl = app.get('url').replace(/\/$/, '');
console.log('Web server listening at: %s', baseUrl);
if (app.get('loopback-component-explorer')) {
var explorerPath = app.get('loopback-component-explorer').mountPath;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
}
});
return server;
};
PRESENTING FIRELOOP.IO (NEW)
Generate FireLoop Angular 2 Client
Angular 2 应用程序的 FireLoop 客户端是在生成 LoopBack SDK 时内置的。 阅读以下说明以便自动生成您的软件开发工具包。
LoopBack Component Real-Time
A LoopBack Framework Component that provides publish events over WebSockets.
This module will supersedes the LoopBack Component PubSub and implements the new FireLoop Module.
Installation
$ npm install --save @mean-expert/{loopback-sdk-builder,loopback-component-realtime}
Setup Back End Module
Update the server/component-config.json
as follows:
{
"loopback-component-explorer": {
"mountPath": "/explorer"
},
"@mean-expert/loopback-component-realtime": {
"debug": true,
"auth": true,
"driver": {
"name": "socket.io"
}
}
}
Update the server/model-config.json
as follows:
{
"mixins": [
"loopback/common/mixins",
"loopback/server/mixins",
"../common/mixins",
"./mixins",
"../node_modules/@mean-expert/loopback-component-realtime/dist/mixins"
]
}
Enable Model to use FireLoop API
From version 1.0.0-rc.8
you need to specify in which models you want to enable FireLoop events to be sent.
Explanation: In an attempt to enable server and rest triggered events a new mixin has been introduced, this will trigger events either from REST calls or from the NodeJS Api e.g. Model.create().
NOTE: Due a LoopBack limitation the server triggered events are only available for root model methods (Model.create()), but it won't work for relationship methods, these will continue being executed only from FireLoop Child References in the Front-End
{
"mixins": {
"FireLoop": true
}
}
Update Server
To propagate the App from LoopBack to FireLoop, so to finalize just update the file server/server.js
by editing the app.start
method as follow:
app.start = function() {
// start the web server
var server = app.listen(function() {
app.emit('started', server);
var baseUrl = app.get('url').replace(/\/$/, '');
console.log('Web server listening at: %s', baseUrl);
if (app.get('loopback-component-explorer')) {
var explorerPath = app.get('loopback-component-explorer').mountPath;
console.log('Browse your REST API at %s%s', baseUrl, explorerPath);
}
});
return server;
};
PRESENTING FIRELOOP.IO (NEW)
Generate FireLoop Angular 2 Client
FireLoop Client for Angular 2 Applications are built in when generating your LoopBack SDK. Read the Following Instructions in order to automatically generate your software development kit.