Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

more setup and config

  • Loading branch information...
commit ab8283b6a15d2e7842ff378bbdbdd5547b0f84d9 1 parent 256734e
J Brien Dilts authored

Showing 24 changed files with 22 additions and 4,611 deletions. Show diff stats Hide diff stats

  1. +5 0 README
  2. +3 2 app/controllers/chat_rooms_controller.rb
  3. +1 1  app/helpers/chat_users_helper.rb
  4. +1 1  app/views/chat_rooms/new.html.erb
  5. +9 2 db/migrate/20081014160039_create_redmine_chat_plugin.rb
  6. BIN  engine_plugins/.DS_Store
  7. +0 21 engine_plugins/juggernaut/LICENSE
  8. +0 233 engine_plugins/juggernaut/README
  9. +0 19 engine_plugins/juggernaut/init.rb
  10. +0 203 engine_plugins/juggernaut/lib/juggernaut.rb
  11. +0 37 engine_plugins/juggernaut/lib/juggernaut_helper.rb
  12. BIN  engine_plugins/juggernaut/media/expressinstall.swf
  13. +0 3,549 engine_plugins/juggernaut/media/jquery.js
  14. +0 30 engine_plugins/juggernaut/media/jquerynaut.js
  15. +0 97 engine_plugins/juggernaut/media/json.js
  16. +0 79 engine_plugins/juggernaut/media/juggernaut.as
  17. +0 205 engine_plugins/juggernaut/media/juggernaut.js
  18. BIN  engine_plugins/juggernaut/media/juggernaut.swf
  19. +0 93 engine_plugins/juggernaut/media/juggernaut.yml
  20. +0 18 engine_plugins/juggernaut/media/juggernaut_hosts.yml
  21. 0  engine_plugins/juggernaut/media/log/juggernaut.log
  22. +0 5 engine_plugins/juggernaut/media/swfobject.js
  23. +0 13 engine_plugins/juggernaut/tasks/juggernaut.rake
  24. +3 3 init.rb
5 README
... ... @@ -1,3 +1,8 @@
1 1 Juggernaut Powered Chat Room for Redmine
2 2
  3 +INSTALLATION:
  4 +
  5 +sudo gem install juggernaut
  6 +./script/plugin install http://juggernaut.rubyforge.org/svn/trunk/juggernaut
  7 +
3 8 DETAILS: COMING SOON
5 app/controllers/chat_rooms_controller.rb
... ... @@ -1,6 +1,7 @@
1 1 class ChatRoomsController < ApplicationController
2   - before_filter :is_logged_in?
3   - # GET /chat_rooms
  2 + unloadable
  3 +
  4 + before_filter :require_login, :except => [:broadcast] # GET /chat_rooms
4 5 # GET /chat_rooms.xml
5 6 def index
6 7 @chat_rooms = ChatRoom.find(:all)
2  app/helpers/chat_users_helper.rb
... ... @@ -1,2 +1,2 @@
1   -module DevsHelper
  1 +module UsersHelper
2 2 end
2  app/views/chat_rooms/new.html.erb
... ... @@ -1,6 +1,6 @@
1 1 <h1>New chat_room</h1>
2 2
3   -<% form_for(@chat_room) do |f| %>
  3 +<% form_for(@chat_room, {:controller => 'chat_rooms'}) do |f| %>
4 4 <%= f.error_messages %>
5 5
6 6 <p>
11 db/migrate/20081014160039_create_redmine_chat_plugin.rb
... ... @@ -1,4 +1,4 @@
1   -class CreateRedmineDevChat < ActiveRecord::Migration
  1 +class CreateRedmineChatPlugin < ActiveRecord::Migration
2 2 def self.up
3 3 create_table "chat_users", :force => true do |t|
4 4 t.integer :user_id
@@ -16,10 +16,17 @@ def self.up
16 16 t.boolean :notice, :default => false
17 17 t.boolean :timestamp, :default => false
18 18 end
  19 +
  20 + create_table "chat_rooms", :force => true do |t|
  21 + t.string "name"
  22 + t.string "description"
  23 + t.timestamps
  24 + end
19 25 end
20 26
21 27 def self.down
22   - drop_table :chat_devs
  28 + drop_table :chat_users
23 29 drop_table :chat_messages
  30 + drop_table :chat_rooms
24 31 end
25 32 end
BIN  engine_plugins/.DS_Store
Binary file not shown
21 engine_plugins/juggernaut/LICENSE
... ... @@ -1,21 +0,0 @@
1   -Copyright (c) 2005 Alexander MacCaw
2   -
3   -Permission is hereby granted, free of charge, to any person obtaining
4   -a copy of this software and associated documentation files (the
5   -"Software"), to deal in the Software without restriction, including
6   -without limitation the rights to use, copy, modify, merge, publish,
7   -distribute, sublicense, and/or sell copies of the Software, and to
8   -permit persons to whom the Software is furnished to do so, subject to
9   -the following conditions:
10   -
11   -The above copyright notice and this permission notice shall be
12   -included in all copies or substantial portions of the Software.
13   -
14   -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15   -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16   -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17   -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18   -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19   -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20   -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21   -
233 engine_plugins/juggernaut/README
... ... @@ -1,233 +0,0 @@
1   -Juggernaut
2   -===========
3   -
4   -=CONTACT DETAILS
5   -
6   - Author: Alex MacCaw
7   - E-Mail Address: info@alexmaccaw.co.uk
8   - License: MIT
9   - Website: http://juggernaut.rubyforge.org
10   - Blog: http://www.eribium.org
11   -
12   -=DESCRIPTION
13   -
14   -The Juggernaut plugin for Ruby on Rails aims to revolutionize your Rails app by letting the server initiate a connection and push data to the client. In other words your app can have a real time connection to the server with the advantage of instant updates. Although the obvious use of this is for chat, the most exciting prospect for me is collaborative cms and wikis.
15   -
16   -What Happens:
17   -
18   - 1. Client A opens socket connection to the socket server
19   - 2. Client B makes Ajax call to Rails
20   - 3. Rails sends message to the socket server
21   - 4. Socket server broadcasts message to clients
22   -
23   -Juggernaut Features:
24   -
25   - * Allows a real time connection with a client - Rails can literally push javascript in real time to the client which is then evaluated.
26   - * Push server - written in Ruby.
27   - * Integrated, as a plugin, into Rails.
28   - * Subscribers can subscribe to multiple channels, and broadcasters can broadcast to multiple channels.
29   - * Subscribers can provide a 'unique_id' and broadcasters can send data to specific clients.
30   - * Add and remove channels at runtime
31   - * Uses Flash 8 - installed on more than 98% of computers.
32   - * Supports all the major browsers (uses ExternalInterface): Firefox 1+, IE 6+ and Safari 2+.
33   -
34   -Requirements:
35   -
36   - * Rails 2.0.2 or edge
37   - * json gem (gem install json)
38   - * EventMachine gem (gem install eventmachine)
39   - * juggernaut gem (gem install juggernaut)
40   -
41   -
42   -===============================================
43   -INSTALLATION
44   -===============================================
45   -
46   - 1. From your Rails Dir:
47   - script/plugin install http://juggernaut.rubyforge.org/svn/trunk/juggernaut
48   - 2. Make sure to include the appropriate JavaScripts in your views/layouts
49   - in the header of your views
50   - <%= javascript_include_tag 'prototype', :juggernaut %>
51   - 3. Add this to your view/layout head:
52   - <%= juggernaut %>
53   - 4. Make sure the juggernaut gem is installed (gem install juggernaut) and run:
54   - juggernaut -g juggernaut.yml
55   - juggernaut -c juggernaut.yml
56   - 5. Run script/server and visit the Jugged up page.
57   - 6. Then, to send data to juggernaut, execute this in the console:
58   - Juggernaut.send_to_all("alert('hi from juggernaut')")
59   -
60   -Usage
61   -
62   -To demonstrate Juggernaut I'll walk you through building a simple chat.
63   -
64   -Start the push server going by running:
65   -juggernaut -g juggernaut.yml
66   -juggernaut -c juggernaut.yml
67   -
68   -The chat controller:
69   -
70   -class ChatController < ApplicationController
71   - def index
72   - end
73   -
74   - def send_data
75   - render :juggernaut do |page|
76   - page.insert_html :top, 'chat_data', "<li>#{h params[:chat_input]}</li>"
77   - end
78   - render :nothing => true
79   - end
80   -end
81   -
82   -
83   -The index.html.erb
84   -
85   - <html>
86   - <head>
87   - <%= javascript_include_tag :defaults, :juggernaut %>
88   - <%= juggernaut %>
89   - </head>
90   - <body>
91   - <%= form_remote_tag(
92   - :url => { :action => :send_data },
93   - :complete => "$('chat_input').value = ''" ) %>
94   - <%= text_field_tag( 'chat_input', '', { :size => 20, :id => 'chat_input'} ) %>
95   - <%= submit_tag "Add" %>
96   - </form>
97   - <ul id="chat_data" style="list-style:none">
98   - </ul>
99   - </body>
100   - </html>
101   -
102   -Start the webserver going with:
103   -ruby script/server
104   -
105   -Try it and see what you think. If it doesn't work please visit the faq.
106   -
107   -Other ways of rendering to juggernaut:
108   -
109   -render :juggernaut do |page|
110   - page.alert('hi')
111   -end
112   -
113   -render_juggernaut(:action => 'whatever')
114   -
115   -===============================================
116   -More usage information, examples and support
117   -===============================================
118   -
119   -=== Channel Usage ===
120   -
121   -<%= juggernaut(:channels => ['one', 'two', 'three']) %>
122   -render :juggernaut => {:type => :send_to_channels, :channels => ['one']} do |page|
123   - page.alert('hi')
124   -end
125   -
126   -Client id usage:
127   -<%= juggernaut(:client_id => session[:user_id]) %>
128   -render :juggernaut => {:type => :send_to_clients, :client_ids => [1, 2, 3]} do |page|
129   - page.alert('hi')
130   -end
131   -
132   -Other juggernaut render options:
133   -OPTION_TYPE PARAMS
134   -:send_to_all
135   -:send_to_channels :channels
136   -:send_to_channel :channel
137   -:send_to_client :client_id
138   -:send_to_clients :client_ids
139   -:send_to_client_on_channel :client_id, :channel
140   -:send_to_clients_on_channel :client_ids, :channel
141   -:send_to_client_on_channels :client_id, :channels
142   -:send_to_clients_on_channels :client_ids, :channels
143   -
144   -You can also call these methods directly on the Juggernaut class:
145   -Juggernaut.send_to_clients('data', [1,2,3])
146   -
147   -For authentication options and callbacks see the juggernaut.yml configuration file.
148   -
149   -Usage and examples: http://ncavig.com/blog/
150   -Support and forums: http://groups.google.com/group/Juggernaut-for-Rails?hl=en
151   -
152   -=== Getting remote clients to connect ===
153   -
154   -Firstly you will need to configure juggernaut_hosts.yml in your Rails app to point to the proper IP of the push server (rather than 127.0.0.1).
155   -For example:
156   -:hosts:
157   - - :port: 5001
158   - :host: 129.168.0.2
159   - :environment: :production
160   -
161   -Ok, remote clients that visit pages on this server (once you restart it) will connect to the proper push server IP. BUT, if you're using IP based
162   -authentication (recommended) you'll find that the broadcast authentication fails.
163   -You'll need to add the Rails IP to juggernaut.yml, like so:
164   -
165   -:allowed_ips:
166   - - 127.0.0.1
167   - - 192.168.0.4 # IP of the Rails app
168   -
169   -===============================================
170   -Jquery
171   -===============================================
172   -
173   -To get Juggernaut working with Jquery (Prototype is used by default) follow the tutorial above with the following differences.
174   -
175   ->>Javascripts
176   -
177   - You must have jquery.js (version 1.2.6 tested) and the jquery-json plugin (http://www.jdempster.com/wp-content/uploads/2007/08/jquery.json.js) in the /javascripts directory.
178   -
179   - You need the jquerynaut.js file in the /javascripts/juggernaut directory (found in /lib in the media directory)
180   -
181   -
182   ->>The chat controller:
183   -
184   - class ChatController < ApplicationController
185   - def index
186   - end
187   -
188   - def send_data
189   - render :juggernaut do |page|
190   - page["#chat_data"].prepend "<li>#{h params[:chat_input]}</li>"
191   - end
192   - render :nothing => true
193   - end
194   -
195   - end
196   -
197   -
198   ->>The index.html.erb
199   -
200   - <html>
201   - <head>
202   - <%= javascript_include_tag 'jquery', 'json', 'juggernaut/juggernaut', 'juggernaut/jquerynaut', 'juggernaut/swfobject' %>
203   - <%= juggernaut %>
204   - </head>
205   - <body>
206   - <form action="/chat/send_data" method="get">
207   - <div style="margin:0;padding:0">
208   - <input id="chat_input" name="chat_input" size="20" type="text" value="" />
209   - <input name="commit" type="submit" value="Add" />
210   - </form>
211   -
212   - <script>
213   - $(document).ready(function(){
214   - $('form').submit(function(){
215   - $.get('/chat/send_data', { chat_input: $('#chat_input').val() } )
216   - return false;
217   - })
218   - })
219   - </script>
220   - <ul id="chat_data" style="list-style:none"></ul>
221   - </body>
222   - </html>
223   -
224   -
225   -
226   -===============================================
227   -Troubleshooting
228   -===============================================
229   -
230   -Check out the support forums on google groups:
231   -http://groups.google.com/group/Juggernaut-for-Rails
232   -
233   -
19 engine_plugins/juggernaut/init.rb
... ... @@ -1,19 +0,0 @@
1   -require 'juggernaut'
2   -require 'juggernaut_helper'
3   -
4   -# ActionView::Helpers::AssetTagHelper::register_javascript_include_default('juggernaut')
5   -# ActionView::Helpers::AssetTagHelper::register_javascript_include_default('swfobject')
6   -
7   -ActionView::Base.send(:include, Juggernaut::JuggernautHelper)
8   -
9   -ActionController::Base.class_eval do
10   - alias_method :render_without_juggernaut, :render
11   - include Juggernaut::RenderExtension
12   - alias_method :render, :render_with_juggernaut
13   -end
14   -
15   -ActionView::Base.class_eval do
16   - alias_method :render_without_juggernaut, :render
17   - include Juggernaut::RenderExtension
18   - alias_method :render, :render_with_juggernaut
19   -end
203 engine_plugins/juggernaut/lib/juggernaut.rb
... ... @@ -1,203 +0,0 @@
1   -require "yaml"
2   -require "socket"
3   -
4   -module Juggernaut
5   - CONFIG = YAML::load(ERB.new(IO.read("#{RAILS_ROOT}/config/juggernaut_hosts.yml")).result).freeze
6   - CR = "\0"
7   -
8   - class << self
9   -
10   - def send_to_all(data)
11   - fc = {
12   - :command => :broadcast,
13   - :body => data,
14   - :type => :to_channels,
15   - :channels => []
16   - }
17   - send_data(fc)
18   - end
19   -
20   - def send_to_channels(data, channels)
21   - fc = {
22   - :command => :broadcast,
23   - :body => data,
24   - :type => :to_channels,
25   - :channels => channels
26   - }
27   - send_data(fc)
28   - end
29   - alias send_to_channel send_to_channels
30   -
31   - def send_to_clients(data, client_ids)
32   - fc = {
33   - :command => :broadcast,
34   - :body => data,
35   - :type => :to_clients,
36   - :client_ids => client_ids
37   - }
38   - send_data(fc)
39   - end
40   - alias send_to_client send_to_clients
41   -
42   - def send_to_clients_on_channels(data, client_ids, channels)
43   - fc = {
44   - :command => :broadcast,
45   - :body => data,
46   - :type => :to_clients,
47   - :client_ids => client_ids,
48   - :channels => channels
49   - }
50   - send_data(fc)
51   - end
52   - alias send_to_client_on_channel send_to_clients_on_channels
53   - alias send_to_client_on_channel send_to_clients_on_channels
54   -
55   - def remove_channels_from_clients(client_ids, channels)
56   - fc = {
57   - :command => :query,
58   - :type => :remove_channels_from_client,
59   - :client_ids => client_ids,
60   - :channels => channels
61   - }
62   - send_data(fc)
63   - end
64   - alias remove_channel_from_client remove_channels_from_clients
65   - alias remove_channels_from_client remove_channels_from_clients
66   -
67   - def remove_all_channels(channels)
68   - fc = {
69   - :command => :query,
70   - :type => :remove_all_channels,
71   - :channels => channels
72   - }
73   - send_data(fc)
74   - end
75   -
76   - def show_clients
77   - fc = {
78   - :command => :query,
79   - :type => :show_clients
80   - }
81   - send_data(fc, true).flatten
82   - end
83   -
84   - def show_client(client_id)
85   - fc = {
86   - :command => :query,
87   - :type => :show_client,
88   - :client_id => client_id
89   - }
90   - send_data(fc, true).flatten[0]
91   - end
92   -
93   - def show_clients_for_channels(channels)
94   - fc = {
95   - :command => :query,
96   - :type => :show_clients_for_channels,
97   - :channels => channels
98   - }
99   - send_data(fc, true).flatten
100   - end
101   - alias show_clients_for_channel show_clients_for_channels
102   -
103   - def send_data(hash, response = false)
104   - hash[:channels] = hash[:channels].to_a if hash[:channels]
105   - hash[:client_ids] = hash[:client_ids].to_a if hash[:client_ids]
106   -
107   - res = []
108   - hosts.each do |address|
109   - begin
110   - hash[:secret_key] = address[:secret_key] if address[:secret_key]
111   -
112   - @socket = TCPSocket.new(address[:host], address[:port])
113   - # the \0 is to mirror flash
114   - @socket.print(hash.to_json + CR)
115   - @socket.flush
116   - res << @socket.readline(CR) if response
117   - ensure
118   - @socket.close if @socket and !@socket.closed?
119   - end
120   - end
121   - res.collect {|r| ActiveSupport::JSON.decode(r.chomp!(CR)) } if response
122   - end
123   -
124   - private
125   -
126   - def hosts
127   - CONFIG[:hosts].select {|h|
128   - !h[:environment] or h[:environment].to_s == ENV['RAILS_ENV']
129   - }
130   - end
131   -
132   - end
133   -
134   - module RenderExtension
135   - def self.included(base)
136   - base.send :include, InstanceMethods
137   - end
138   -
139   - module InstanceMethods
140   - # We can't protect these as ActionMailer complains
141   - # protected
142   -
143   - def render_with_juggernaut(options = nil, old_local_assigns={}, &block)
144   - if options == :juggernaut or (options.is_a?(Hash) and options[:juggernaut])
145   - add_variables_to_assigns
146   - @template.send! :evaluate_assigns
147   -
148   - generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@template, &block)
149   - render_for_juggernaut(generator.to_s, options.is_a?(Hash) ? options[:juggernaut] : nil)
150   - else
151   - render_without_juggernaut(options, old_local_assigns, &block)
152   - end
153   - end
154   -
155   - def render_juggernaut(*args)
156   - juggernaut_options = args.last.is_a?(Hash) ? args.pop : {}
157   - render_for_juggernaut(render_to_string(*args), juggernaut_options)
158   - end
159   -
160   - def render_for_juggernaut(data, options = {})
161   - if !options or !options.is_a?(Hash)
162   - return Juggernaut.send_to_all(data)
163   - end
164   -
165   - case options[:type]
166   - when :send_to_all
167   - Juggernaut.send_to_all(data)
168   - when :send_to_channels:
169   - juggernaut_needs options, :channels
170   - Juggernaut.send_to_channels(data, options[:channels])
171   - when :send_to_channel:
172   - juggernaut_needs options, :channel
173   - Juggernaut.send_to_channel(data, options[:channel])
174   - when :send_to_client:
175   - juggernaut_needs options, :client_id
176   - Juggernaut.send_to_client(data, options[:client_id])
177   - when :send_to_clients:
178   - juggernaut_needs options, :client_ids
179   - Juggernaut.send_to_clients(data, options[:client_ids])
180   - when :send_to_client_on_channel:
181   - juggernaut_needs options, :client_id, :channels
182   - Juggernaut.send_to_clients_on_channel(data, options[:client_id], options[:channels])
183   - when :send_to_clients_on_channel:
184   - juggernaut_needs options, :client_ids, :channel
185   - Juggernaut.send_to_clients_on_channel(data, options[:client_ids], options[:channel])
186   - when :send_to_client_on_channels:
187   - juggernaut_needs options, :client_ids, :channel
188   - Juggernaut.send_to_clients_on_channel(data, options[:client_id], options[:channels])
189   - when :send_to_clients_on_channels:
190   - juggernaut_needs options, :client_ids, :channel
191   - Juggernaut.send_to_clients_on_channel(data, options[:client_ids], options[:channels])
192   - end
193   - end
194   -
195   - def juggernaut_needs(options, *args)
196   - args.each do |a|
197   - raise "You must specify #{a}" unless options[a]
198   - end
199   - end
200   -
201   - end
202   - end
203   -end
37 engine_plugins/juggernaut/lib/juggernaut_helper.rb
... ... @@ -1,37 +0,0 @@
1   -module Juggernaut # :nodoc:
2   - module JuggernautHelper
3   -
4   - def juggernaut(options = {})
5   - hosts = Juggernaut::CONFIG[:hosts].select {|h| !h[:environment] or h[:environment] == ENV['RAILS_ENV'].to_sym }
6   - random_host = hosts[rand(hosts.length)]
7   - options = {
8   - :host => (random_host[:public_host] || random_host[:host]),
9   - :port => (random_host[:public_port] || random_host[:port]),
10   - :width => '0px',
11   - :height => '0px',
12   - :session_id => session.session_id,
13   - :swf_address => "/juggernaut/juggernaut.swf",
14   - :ei_swf_address => "/juggernaut/expressinstall.swf",
15   - :flash_version => 8,
16   - :flash_color => "#fff",
17   - :swf_name => "juggernaut_flash",
18   - :bridge_name => "juggernaut",
19   - :debug => (RAILS_ENV == 'development'),
20   - :reconnect_attempts => 3,
21   - :reconnect_intervals => 3
22   - }.merge(options)
23   - javascript_tag "new Juggernaut(#{options.to_json});"
24   - end
25   -
26   - def expand_javascript_sources(sources, recursive = false)
27   - if sources.include?(:juggernaut)
28   - sources = sources[0..(sources.index(:juggernaut))] +
29   - ['juggernaut/swfobject', 'juggernaut/juggernaut'] +
30   - sources[(sources.index(:juggernaut) + 1)..sources.length]
31   - sources.delete(:juggernaut)
32   - end
33   - super(sources)
34   - end
35   -
36   - end
37   -end
BIN  engine_plugins/juggernaut/media/expressinstall.swf
Binary file not shown
3,549 engine_plugins/juggernaut/media/jquery.js
0 additions, 3,549 deletions not shown
30 engine_plugins/juggernaut/media/jquerynaut.js
... ... @@ -1,30 +0,0 @@
1   -// Simply overwrites prototype specific functions
2   -// with jquery specific versions
3   -
4   -Juggernaut.fn.fire_event = function(fx_name) {
5   - $(document).trigger("juggernaut:" + fx_name);
6   - }
7   -
8   -Juggernaut.fn.bindToWindow = function() {
9   - $(window).bind("load", this, function(e) {
10   - juggernaut = e.data;
11   - e.data.appendFlashObject()
12   - });
13   - }
14   -
15   -Juggernaut.toJSON = function(hash) {
16   - return $.toJSON(hash) ;
17   - }
18   -
19   -Juggernaut.parseJSON = function(string) {
20   - return $.parseJSON(string);
21   - }
22   -
23   -Juggernaut.fn.swf = function(){
24   - return $('#' + this.options.swf_name)[0];
25   - }
26   -
27   -Juggernaut.fn.appendElement = function() {
28   - this.element = $('<div id=juggernaut>');
29   - $("body").append(this.element);
30   - }
97 engine_plugins/juggernaut/media/json.js
... ... @@ -1,97 +0,0 @@
1   -(function ($) {
2   - var m = {
3   - '\b': '\\b',
4   - '\t': '\\t',
5   - '\n': '\\n',
6   - '\f': '\\f',
7   - '\r': '\\r',
8   - '"' : '\\"',
9   - '\\': '\\\\'
10   - },
11   - s = {
12   - 'array': function (x) {
13   - var a = ['['], b, f, i, l = x.length, v;
14   - for (i = 0; i < l; i += 1) {
15   - v = x[i];
16   - f = s[typeof v];
17   - if (f) {
18   - v = f(v);
19   - if (typeof v == 'string') {
20   - if (b) {
21   - a[a.length] = ',';
22   - }
23   - a[a.length] = v;
24   - b = true;
25   - }
26   - }
27   - }
28   - a[a.length] = ']';
29   - return a.join('');
30   - },
31   - 'boolean': function (x) {
32   - return String(x);
33   - },
34   - 'null': function (x) {
35   - return "null";
36   - },
37   - 'number': function (x) {
38   - return isFinite(x) ? String(x) : 'null';
39   - },
40   - 'object': function (x) {
41   - if (x) {
42   - if (x instanceof Array) {
43   - return s.array(x);
44   - }
45   - var a = ['{'], b, f, i, v;
46   - for (i in x) {
47   - v = x[i];
48   - f = s[typeof v];
49   - if (f) {
50   - v = f(v);
51   - if (typeof v == 'string') {
52   - if (b) {
53   - a[a.length] = ',';
54   - }
55   - a.push(s.string(i), ':', v);
56   - b = true;
57   - }
58   - }
59   - }
60   - a[a.length] = '}';
61   - return a.join('');
62   - }
63   - return 'null';
64   - },
65   - 'string': function (x) {
66   - if (/["\\\x00-\x1f]/.test(x)) {
67   - x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
68   - var c = m[b];
69   - if (c) {
70   - return c;
71   - }
72   - c = b.charCodeAt();
73   - return '\\u00' +
74   - Math.floor(c / 16).toString(16) +
75   - (c % 16).toString(16);
76   - });
77   - }
78   - return '"' + x + '"';
79   - }
80   - };
81   -
82   - $.toJSON = function(v) {
83   - var f = isNaN(v) ? s[typeof v] : s['number'];
84   - if (f) return f(v);
85   - };
86   -
87   - $.parseJSON = function(v, safe) {
88   - if (safe === undefined) safe = $.parseJSON.safe;
89   - if (safe && !/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(v))
90   - return undefined;
91   - return eval('('+v+')');
92   - };
93   -
94   - $.parseJSON.safe = false;
95   -
96   -})(jQuery);
97   -
79 engine_plugins/juggernaut/media/juggernaut.as
... ... @@ -1,79 +0,0 @@
1   -/*
2   -Copyright (c) 2007 Alexander MacCaw
3   -
4   -Permission is hereby granted, free of charge, to any person obtaining
5   -a copy of this software and associated documentation files (the
6   -"Software"), to deal in the Software without restriction, including
7   -without limitation the rights to use, copy, modify, merge, publish,
8   -distribute, sublicense, and/or sell copies of the Software, and to
9   -permit persons to whom the Software is furnished to do so, subject to
10   -the following conditions:
11   -
12   -The above copyright notice and this permission notice shall be
13   -included in all copies or substantial portions of the Software.
14   -
15   -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16   -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17   -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18   -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19   -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20   -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21   -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22   -*/
23   -
24   -/*
25   - Compile using MTACS (http://www.mtasc.org/)
26   - mtasc -version 8 -header 1:1:1 -main -swf juggernaut.swf juggernaut.as
27   -*/
28   -
29   -import flash.external.ExternalInterface;
30   -
31   -class SocketServer {
32   -
33   - static var socket : XMLSocket;
34   -
35   - static function connect(host:String, port:Number) {
36   - // The following line was causing crashes on Leopard
37   - // System.security.loadPolicyFile('xmlsocket://' + host + ':' + port);
38   -
39   - socket = new XMLSocket();
40   - socket.onData = onData;
41   - socket.onConnect = onConnect;
42   - socket.onClose = onDisconnect;
43   - socket.connect(host, port);
44   - }
45   -
46   - static function disconnect(){
47   - socket.close();
48   - }
49   -
50   - static function onConnect(success:Boolean) {
51   - if(success){
52   - ExternalInterface.call("juggernaut.connected");
53   - } else {
54   - ExternalInterface.call("juggernaut.errorConnecting");
55   - }
56   - }
57   -
58   - static function sendData(data:String){
59   - socket.send(unescape(data));
60   - }
61   -
62   - static function onDisconnect() {
63   - ExternalInterface.call("juggernaut.disconnected");
64   - }
65   -
66   - static function onData(data:String) {
67   - ExternalInterface.call("juggernaut.receiveData", escape(data));
68   - }
69   -
70   - static function main() {
71   - ExternalInterface.addCallback("connect", null, connect);
72   - ExternalInterface.addCallback("sendData", null, sendData);
73   - ExternalInterface.addCallback("disconnect", null, disconnect);
74   -
75   - ExternalInterface.call("juggernaut.initialized");
76   - }
77   -
78   -}
79   -
205 engine_plugins/juggernaut/media/juggernaut.js
... ... @@ -1,205 +0,0 @@
1   -/*
2   -Copyright (c) 2008 Alexander MacCaw
3   -
4   -Permission is hereby granted, free of charge, to any person obtaining
5   -a copy of this software and associated documentation files (the
6   -"Software"), to deal in the Software without restriction, including
7   -without limitation the rights to use, copy, modify, merge, publish,
8   -distribute, sublicense, and/or sell copies of the Software, and to
9   -permit persons to whom the Software is furnished to do so, subject to
10   -the following conditions:
11   -
12   -The above copyright notice and this permission notice shall be
13   -included in all copies or substantial portions of the Software.
14   -
15   -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16   -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17   -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18   -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19   -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20   -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21   -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22   -*/
23   -
24   -function Juggernaut(options) {
25   - this.is_connected = false,
26   - this.attempting_to_reconnect = false
27   - this.ever_been_connected = false
28   - this.hasFirebug = "console" in window && "firebug" in window.console
29   - this.options = options
30   - this.bindToWindow();
31   - }
32   -
33   -Juggernaut.fn = Juggernaut.prototype
34   -
35   -Juggernaut.fn.logger = function(msg) {
36   - if (this.options.debug) {
37   - msg = "Juggernaut: " + msg + " on " + this.options.host + ':' + this.options.port;
38   - this.hasFirebug ? console.log(msg) : alert(msg);
39   - }
40   - }
41   -
42   -Juggernaut.fn.initialized = function(){
43   - this.fire_event('initialized');
44   - this.connect();
45   - }
46   -
47   -Juggernaut.fn.broadcast = function(body, type, client_ids, channels){
48   - var msg = {command: 'broadcast', body: body, type: (type||'to_channels')}
49   - if(channels) msg['channels'] = channels;
50   - if(client_ids) msg['client_ids'] = client_ids;
51   - this.sendData(Juggernaut.toJSON(msg));
52   - }
53   -
54   -Juggernaut.fn.sendData = function(data){
55   - this.swf().sendData(escape(data));
56   - }
57   -
58   -Juggernaut.fn.connect = function(){
59   - if(!this.is_connected){
60   - this.fire_event('connect');
61   - this.swf().connect(this.options.host, this.options.port);
62   - }
63   - }
64   -
65   -Juggernaut.fn.disconnect = function(){
66   - if(this.is_connected) {
67   - this.swf().disconnect();
68   - this.is_connected = false;
69   - }
70   - }
71   -
72   -Juggernaut.fn.handshake = function() {
73   - var handshake = {};
74   - handshake['command'] = 'subscribe';
75   - if(this.options.session_id) handshake['session_id'] = this.options.session_id;
76   - if(this.options.client_id) handshake['client_id'] = this.options.client_id;
77   - if(this.options.channels) handshake['channels'] = this.options.channels;
78   - if(this.currentMsgId) {
79   - handshake['last_msg_id'] = this.currentMsgId;
80   - handshake['signature'] = this.currentSignature;
81   - }
82   -
83   - return handshake;
84   - }
85   -
86   -Juggernaut.fn.connected = function(e) {
87   - var json = Juggernaut.toJSON(this.handshake())
88   - this.sendData(json);
89   - this.ever_been_connected = true;
90   - this.is_connected = true;
91   - setTimeout(function(){
92   - if(this.is_connected) this.attempting_to_reconnect = false;
93   - }.bind(this), 1 * 1000);
94   - this.logger('Connected');
95   - this.fire_event('connected');
96   - }
97   -
98   -// OVERRIDE FOR CHAT STYLE APPS - POSSIBLE MALICIOUS CONTENT CAN BE EVALED
99   -Juggernaut.fn.receiveData = function(e) {
100   - var msg = Juggernaut.parseJSON(unescape(e.toString()));
101   - this.currentMsgId = msg.id;
102   - this.currentSignature = msg.signature;
103   - this.logger("Received data:\n" + msg.body + "\n");
104   - eval(msg.body);
105   - }
106   -
107   -var juggernaut;
108   -
109   -/*** START PROTOTYPE SPECIFIC - OVERRIDE FOR OTHER FRAMEWORKS ***/
110   -Juggernaut.fn.fire_event = function(fx_name) {
111   - $(document).fire("juggernaut:" + fx_name);
112   - }
113   -
114   -Juggernaut.fn.bindToWindow = function() {
115   -
116   - Event.observe(window, 'load', function() {
117   - juggernaut = this;
118   - this.appendFlashObject()
119   - }.bind(this));
120   -
121   - }
122   -
123   -Juggernaut.toJSON = function(hash) {
124   - return Object.toJSON(hash);
125   - }
126   -
127   -Juggernaut.parseJSON = function(string) {
128   - return string.evalJSON();
129   - }
130   -
131   -Juggernaut.fn.swf = function(){
132   - return $(this.options.swf_name);
133   - }
134   -
135   -Juggernaut.fn.appendElement = function() {
136   - this.element = new Element('div', { id: 'juggernaut' });
137   - $(document.body).insert({ bottom: this.element });
138   - }
139   -
140   -/*** END PROTOTYPE SPECIFIC ***/
141   -
142   -Juggernaut.fn.appendFlashObject = function(){
143   - if(this.swf()) {
144   - throw("Juggernaut error. 'swf_name' must be unique per juggernaut instance.");
145   - }
146   - Juggernaut.fn.appendElement();
147   - swfobject.embedSWF(
148   - this.options.swf_address,
149   - 'juggernaut',
150   - this.options.width,
151   - this.options.height,
152   - String(this.options.flash_version),
153   - this.options.ei_swf_address,
154   - {'bridgeName': this.options.bridge_name},
155   - {},
156   - {'id': this.options.swf_name, 'name': this.options.swf_name}
157   - );
158   - }
159   -
160   -
161   -Juggernaut.fn.refreshFlashObject = function(){
162   - this.swf().remove();
163   - this.appendFlashObject();
164   - }
165   -
166   -Juggernaut.fn.errorConnecting = function(e) {
167   - this.is_connected = false;
168   - if(!this.attempting_to_reconnect) {
169   - this.logger('There has been an error connecting');
170   - this.fire_event('errorConnecting');
171   - this.reconnect();
172   - }
173   - }
174   -
175   -Juggernaut.fn.disconnected = function(e) {
176   - this.is_connected = false;
177   - if(!this.attempting_to_reconnect) {
178   - this.logger('Connection has been lost');
179   - this.fire_event('disconnected');
180   - this.reconnect();
181   - }
182   - }
183   -
184   -Juggernaut.fn.reconnect = function(){
185   - if(this.options.reconnect_attempts){
186   - this.attempting_to_reconnect = true;
187   - this.fire_event('reconnect');
188   - this.logger('Will attempt to reconnect ' + this.options.reconnect_attempts + ' times,\
189   -the first in ' + (this.options.reconnect_intervals || 3) + ' seconds');
190   - for(var i=0; i < this.options.reconnect_attempts; i++){
191   - setTimeout(function(){
192   - if(!this.is_connected){
193   - this.logger('Attempting reconnect');
194   - if(!this.ever_been_connected){
195   - this.refreshFlashObject();
196   - } else {
197   - this.connect();
198   - }
199   - }
200   - }.bind(this), (this.options.reconnect_intervals || 3) * 1000 * (i + 1))
201   - }
202   - }
203   - }
204   -
205   -
BIN  engine_plugins/juggernaut/media/juggernaut.swf
Binary file not shown
93 engine_plugins/juggernaut/media/juggernaut.yml
... ... @@ -1,93 +0,0 @@
1   - # ======================
2   - # Juggernaut Options
3   - # ======================
4   -
5   - # === Subscription authentication ===
6   - # Leave all subscription options uncommented to allow anyone to subscribe.
7   -
8   - # If specified, subscription_url is called everytime a client subscribes.
9   - # Parameters passed are: session_id, client_id and an array of channels.
10   - #
11   - # The server should check that the session_id matches up to the client_id
12   - # and that the client is allowed to access the specified channels.
13   - #
14   - # If a status code other than 200 is encountered, the subscription_request fails
15   - # and the client is disconnected.
16   - #
17   - # :subscription_url: http://localhost:3000/sessions/juggernaut_subscription
18   -
19   - # === Broadcast and query authentication ===
20   - # Leave all broadcast/query options uncommented to allow anyone to broadcast/query.
21   - #
22   - # Broadcast authentication in a production environment is very importantant since broadcasters
23   - # can execute JavaScript on subscribed clients, leaving you vulnerable to cross site scripting
24   - # attacks if broadcasters aren't authenticated.
25   -
26   - # 1) Via IP address
27   - #
28   - # If specified, if a client has an ip that is specified in allowed_ips, than it is automatically
29   - # authenticated, even if a secret_key isn't provided.
30   - #
31   - # This is the recommended method for broadcast authentication.
32   - #
33   - :allowed_ips:
34   - - 127.0.0.1
35   - # - 192.168.0.1
36   -
37   - # 2) Via HTTP request
38   - #
39   - # If specified, if a client attempts a broadcast/query, without a secret_key or using an IP
40   - # no included in allowed_ips, then broadcast_query_login_url will be called.
41   - # Parameters passed, if given, are: session_id, client_id, channels and type.
42   - #
43   - # The server should check that the session_id matches up to the client id, and the client
44   - # is allowed to perform that particular type of broadcast/query.
45   - #
46   - # If a status code other than 200 is encountered, the broadcast_query_login_url fails
47   - # and the client is disconnected.
48   - #
49   - # :broadcast_query_login_url: http://localhost:3000/sessions/juggernaut_broadcast
50   -
51   - # 3) Via shared secret key
52   - #
53   - # This secret key must be sent with any query/broadcast commands.
54   - # It must be the same as the one in the Rails config file.
55   - #
56   - # You shouldn't authenticate broadcasts from subscribed clients using this method
57   - # since the secret_key will be easily visible in the page (and not so secret any more)!
58   - #
59   - # :secret_key: 8a01f4941eac46fcb36354c62487ef04d113cdbe
60   -
61   - # == Subscription Logout ==
62   -
63   - # If specified, logout_connection_url is called everytime a specific connection from a subscribed client disconnects.
64   - # Parameters passed are session_id, client_id and an array of channels specific to that connection.
65   - #
66   - # :logout_connection_url: http://localhost:3000/sessions/juggernaut_connection_logout
67   -
68   - # Logout url is called when all connections from a subscribed client are closed.
69   - # Parameters passed are session_id and client_id.
70   - #
71   - # :logout_url: http://localhost:3000/sessions/juggernaut_logout
72   -
73   - # === Miscellaneous ===
74   -
75   - # timeout defaults to 10. A timeout is the time between when a client closes a connection
76   - # and a logout_request or logout_connection_request is made. The reason for this is that a client
77   - # may only temporarily be disconnected, and may attempt a reconnect very soon.
78   - #
79   - # :timeout: 10
80   -
81   - # store_messages defaults to false. If this option is true, messages send to connections will be stored.
82   - # This is useful since a client can then receive broadcasted message that it has missed (perhaps it was disconnected).
83   - #
84   - # :store_messages: false
85   -
86   - # === Server ===
87   -
88   - # Host defaults to "0.0.0.0". You shouldn't need to change this.
89   - # :host: 0.0.0.0
90   -
91   - # Port is mandatory
92   - :port: 5001
93   -
18 engine_plugins/juggernaut/media/juggernaut_hosts.yml
... ... @@ -1,18 +0,0 @@
1   -# You should list any juggernaut hosts here.
2   -# You need only specify the secret key if you're using that type of authentication (see juggernaut.yml)
3   -#
4   -# Name: Mapping:
5   -# :port internal push server's port
6   -# :host internal push server's host/ip
7   -# :public_host public push server's host/ip (accessible from external clients)