I've put together a simple demo that integrates Polytalk with Meteor. The app allows you to retrieve, create and delete posts from a Ruby Polytalk server that is exposing a simple Post ActiveRecord model.
The app utilizes Meteor's latency compensation and keeps the database updated on both the Meteor app and the Ruby server. We do this by loading in all the posts from the server into a Meteor collection that we keep updated every time you create or delete a post.
For the most part the code will look familiar to anyone who's played around with a Meteor app before. We have 3 methods on the server that we expose to the client that will load posts, save a post and remove a post. The one tricky part is in the loadPosts method that synchronizes the Meteor collection with the posts from the Ruby server.
# Load posts from Polytalk
loadPosts = ->
# Remove all posts from collection
Posts.remove({})
postsRequest =
class: 'Post'
method: 'find'
arguments:
type: ':all'
options:
order: 'id DESC'
limit: 10
client.call postsRequest, (response) ->
posts = response.map (post) -> post.post
for post in posts
Fiber ->
Posts.insert({dbid: post.id, title: post.title, body: post.body, time: Date.now()})
.run()
return true
Once we receive the posts from the server we need to insert the posts into the collection in a Fiber so it doesn't lock up other parts of the application.
Run the demo
The git repository has the app and the ruby server included. To get it running you will need to cd into the ruby_server directory and run bundle to download the gems. Once downloaded while in the ruby_server directory run ruby server.rb to start the Polytalk server. This will setup the database and expose the Post model to the client.
Once the Ruby server is running you can cd back to the root of the project and run the Meteor app with meteor. You should now be able to visit the app in your browser and start adding and removing posts.
That's it, let me know if you have any questions or suggestions below in the comments.