Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

implement websockets for real-time collaboration

  • Loading branch information...
commit 84db7bb116abac9a1b5e9a278b919cfa0a4f874b 1 parent 965c985
Fernando Di Bartolo authored
29 app/assets/javascripts/stories.js
@@ -2,6 +2,7 @@ $(function(){
2 2 set_story_divs_width();
3 3 set_drag_and_drop_feature();
4 4 move_stories_to_corresponding_status_column();
  5 + set_web_socket_channel();
5 6 });
6 7
7 8 function set_story_divs_width(){
@@ -46,6 +47,8 @@ function set_drag_and_drop_feature(){
46 47 $(this).css("background-color", color);
47 48 $(ui.draggable).css({ zIndex: get_max_z_index() });
48 49 set_status($(ui.draggable).closest(".story"), new_status);
  50 + //setTimeout(publish_status_refresh, 2000);
  51 + publish_status_refresh($(ui.draggable).closest(".story"), new_status);
49 52 }
50 53 });
51 54 }
@@ -69,6 +72,21 @@ function set_status(div_story, new_status) {
69 72 });
70 73 }
71 74
  75 +function publish_status_refresh(div_story, new_status) {
  76 + var story_id = $(div_story).attr("id").split('_')[1];
  77 +
  78 + var faye = new Faye.Client('http://0.0.0.0:9292/faye');
  79 + var publication = faye.publish('/refresh', { story_id: story_id, status: new_status });
  80 +
  81 + /*publication.callback(function() {
  82 + alert('Message received by server!');
  83 + });
  84 +
  85 + publication.errback(function(error) {
  86 + alert('There was a problem: ' + error.message);
  87 + });*/
  88 +}
  89 +
72 90 function move_stories_to_corresponding_status_column(){
73 91 inprogress_color = "#F5F6CE";
74 92 done_color = "#CEF6D8";
@@ -86,4 +104,15 @@ function move_stories_to_corresponding_status_column(){
86 104 $(this).css("left", status_col_width * 2);
87 105 }
88 106 });
  107 +}
  108 +
  109 +function set_web_socket_channel() {
  110 + var faye = new Faye.Client('http://0.0.0.0:9292/faye');
  111 + var sub = faye.subscribe('/refresh', function(data){
  112 + //alert(data.story_id + ' - ' + data.status);
  113 + $("[id=story_" + data.story_id + "]").find("input[id=story_status]").val(data.status);
  114 + move_stories_to_corresponding_status_column();
  115 + });
  116 + /*sub.callback(function(){ alert("callback"); });
  117 + sub.errback(function(error){ alert(error.message); });*/
89 118 }
2  app/views/layouts/application.html.erb
@@ -3,7 +3,7 @@
3 3 <head>
4 4 <title>ScrumBoard</title>
5 5 <%= stylesheet_link_tag "application", :media => "all" %>
6   - <%= javascript_include_tag "application" %>
  6 + <%= javascript_include_tag "application", "http://0.0.0.0:9292/faye.js" %>
7 7 <%= csrf_meta_tags %>
8 8 </head>
9 9 <body>
5 faye.ru
... ... @@ -0,0 +1,5 @@
  1 +require 'faye'
  2 +
  3 +Faye::WebSocket.load_adapter('thin')
  4 +faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 30)
  5 +run faye_server

0 comments on commit 84db7bb

Please sign in to comment.
Something went wrong with that request. Please try again.