在浏览器中独立连接Meteor DDP
Connecting to Meteor DDP standalone in browser?
是否可以在独立浏览器中通过DDP订阅Meteor的数据?
我找到了Meteor DDP包,上面写着这是可以做到的。
如何在独立的浏览器中使用它来接收例如收藏更新?
或者你知道其他适用于浏览器的DDP客户端吗?
例如https://github.com/mondora/ddp.js/,一个工作同构(browser&Node.js)DDP客户端库(我不是这个库的作者,还有一些其他类似功能的可用库)。
您可以轻松连接到任何DDP服务器并监听事件。Readme文件中有示例和API文档。还要看测试。
示例用法:
服务器代码:
Meteor.publish("myPublication", (param_0, param_1, param_2) {
/* ... */
});
客户代码:
const subscriptionId = ddp.sub("myPublication", [param_0, param_1, param_2]);
我推荐Asteroid,Meteor DDP的客户端包:https://github.com/mondora/asteroid
示例用法:
import {createClass} from "asteroid";
const Asteroid = createClass();
// Connect to a Meteor backend
const asteroid = new Asteroid({
endpoint: "ws://localhost:3000/ websocket"
});
// Use real-time collections
asteroid.subscribe("tasksPublication");
asteroid.ddp.on("added", ({collection, id, fields}) => {
console.log(`Element added to collection ${collection}`);
console.log(id);
console.log(fields);
});
// Login
asteroid.loginWithPassword({username, email, password});
// Call method and use promises
asteroid.call("newUser")
.then(result => {
console.log("Success");
console.log(result);
})
.catch(error => {
console.log("Error");
console.error(error);
});
相关文章:
- Meteor如何接收HTTP请求
- Meteor-将选定窗体中的对象添加到集合中
- Meteor上的启动页面
- Meteor方法在客户端返回null,在客户端运行的相同方法返回正确的值
- Meteor-添加用户自定义字段的方法不起作用
- Meteor忘记了密码的实现
- 链接所有<a>Meteor
- 在Meteor项目中安装并包含npm模块后出错
- Meteor JS中代码的重复使用部分
- Meteor Router数据函数被调用两次
- 基于localStorage的Meteor激活模板
- React+Meteor:this.ops返回未定义
- 如何将PHP get查询转换为Meteor's HTTP.get()
- 如何将javascript变量传递到Meteor Spacebars模板中
- 部署时使用npm包时发生Meteor错误
- 在浏览器中独立连接Meteor DDP
- Meteor WebSockets (via DDP?)
- Meteor不渲染css,并且在使用外部DDP Meteor实例时不断重新加载应用程序
- 如何通过DDP连接订阅到服务器端的其他Meteor服务器
- 如何在Meteor中关闭和打开DDP请求