用于 Python 服务器端和 Javascript 客户端的开源远程/分布式/持久 JSON 对象库?
我希望能够让 Javascript 代码在浏览器中操作持久性 JSON 对象,并使其与服务器和其他客户端实时同步。
我已经在使用 MVC 分离。 我希望能够做这样的事情:
function sendMessageToUser(username, message){
messageID = window.model.userMessages[username].messages.length;
window.model.userMessages[username].messages[messageID] = message;
window.requestModelSync();
}
在这个例子中,window.model是一个JSON对象,它定期或按需同步,在碰撞时出错,所以“重”客户端代码可以处理这样的事件(它示例中未捕获,但如果在同步发生之前另一个用户同时向同一用户发送消息,则同步库可能会引发错误)。
模型更改时将调用视图代码,并实时为用户重新呈现消息。
是否有任何库可以做到这一点,并且有些简单且开源?
假设它不是那么安全,我想向它添加基于 cookie 的用户身份验证和键/值验证,假设它还不存在 - 同时仍然使用 JSON,不需要开始黑客攻击的模式或模型。
我已经看过 Robert Sayre 的sync.js,它可能是一个关键的构建块,但我希望看到更完整的东西,并且最好已经在使用中。 IE:COMET、避免冲突/解决策略、低带宽使用等已经实现。
如果它不存在,我很乐意与精通 Python 和 Javascript 的人员一起开发这样的插件。
我见过 http://persistencejs.org/plugin/sync - 它不是 JSON,它们结束定义自己的模型类。
我也不想使用像 Apache Wave 的 API 这样复杂的东西。原型设计的简单性是一个关键目标。
I'd like to be able to have Javascript code manipulate a persistent JSON object in the browser, and have it synchronise with the server, and other clients in real time.
I'm already using MVC separation.
I'd like to be able to do something like this:
function sendMessageToUser(username, message){
messageID = window.model.userMessages[username].messages.length;
window.model.userMessages[username].messages[messageID] = message;
window.requestModelSync();
}
in this example, window.model is a JSON object that is syncronised periodically or on demand, with errors upon collisions, so 'heavy' client code can handle such an event (it is not caught in the example, but if another user messaged the same user at the same time before syncs occurred, an error might be raised by the sync library).
The view code would be called upon a model change and would re-render the messages for the user - in real time.
Are there any libraries that do this already that are somewhat simple, and open-source?
Assuming it's not so secure, I'd like to add cookie based user authentication and key / value validation to it, assuming it doesn't exist already - while still using JSON, with no schema's or models required to start hacking.
I've seen Robert Sayre's sync.js which could be a key building block but I'd like to see something more fully formed, and preferably in use already. I.E: COMET, collision avoidance / resolution strategies, low bandwidth use etc already implemented.
If it doesn't exist I'd be happy to work on such a plugin with people skilled in Python and Javascript.
I've seen http://persistencejs.org/plugin/sync - it is not JSON, they end up defining their own model class.
I don't want to use something as complex as Apache Wave's API's either. Simplicity for prototyping is a key goal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Firebase 是解决您问题的最佳选择。
没有原生 Python 库,但有一个围绕 REST API 的 Python 包装器
请参阅:Firebase< /a>
Firebase 主页
Firebase is a good candidate for solving your problem.
There isn't a native Python library, but there is a Python wrapper around the REST API
See:Firebase
Firebase home page