├── lib └── jschat │ ├── http │ ├── tmp │ │ └── restart.txt │ ├── public │ │ ├── iOS-57.png │ │ ├── iOS-72.png │ │ ├── favicon.ico │ │ ├── iOS-114.png │ │ ├── stylesheets │ │ │ ├── ipad.css │ │ │ ├── iphone.css │ │ │ └── screen.css │ │ ├── images │ │ │ ├── jschat.gif │ │ │ ├── shadow.png │ │ │ └── emoticons │ │ │ │ ├── arr.gif │ │ │ │ ├── btw.gif │ │ │ │ ├── clap.gif │ │ │ │ ├── cool.gif │ │ │ │ ├── dry.gif │ │ │ │ ├── eek.gif │ │ │ │ ├── flex.gif │ │ │ │ ├── huh.gif │ │ │ │ ├── lol.gif │ │ │ │ ├── mad.gif │ │ │ │ ├── oh.gif │ │ │ │ ├── ohmy.gif │ │ │ │ ├── pimp.gif │ │ │ │ ├── rock.gif │ │ │ │ ├── rofl.gif │ │ │ │ ├── sad.gif │ │ │ │ ├── w00t.gif │ │ │ │ ├── wink.gif │ │ │ │ ├── angry.gif │ │ │ │ ├── blink.gif │ │ │ │ ├── blush.gif │ │ │ │ ├── drool.gif │ │ │ │ ├── drunk.gif │ │ │ │ ├── happy.gif │ │ │ │ ├── holmes.gif │ │ │ │ ├── laugh.gif │ │ │ │ ├── mellow.gif │ │ │ │ ├── noclue.gif │ │ │ │ ├── panic.gif │ │ │ │ ├── ph34r.gif │ │ │ │ ├── punch.gif │ │ │ │ ├── shifty.gif │ │ │ │ ├── shock.gif │ │ │ │ ├── shrug.gif │ │ │ │ ├── sleep.gif │ │ │ │ ├── smile.gif │ │ │ │ ├── sweat.gif │ │ │ │ ├── thumbs.gif │ │ │ │ ├── tongue.gif │ │ │ │ ├── unsure.gif │ │ │ │ ├── wacko.gif │ │ │ │ ├── yucky.gif │ │ │ │ ├── brucelee.gif │ │ │ │ ├── chuckle.gif │ │ │ │ ├── realmad.gif │ │ │ │ ├── rolleyes.gif │ │ │ │ ├── scratch.gif │ │ │ │ ├── sleeping.gif │ │ │ │ ├── suicide.gif │ │ │ │ ├── whistling.gif │ │ │ │ └── worship.gif │ │ └── javascripts │ │ │ ├── app │ │ │ ├── models │ │ │ │ ├── user.js │ │ │ │ └── cookie.js │ │ │ ├── protocol │ │ │ │ ├── chat_request.js │ │ │ │ ├── change.js │ │ │ │ └── display.js │ │ │ ├── helpers │ │ │ │ ├── page_helper.js │ │ │ │ ├── emote_helper.js │ │ │ │ ├── form_helpers.js │ │ │ │ ├── link_helper.js │ │ │ │ └── text_helper.js │ │ │ ├── controllers │ │ │ │ ├── signon_controller.js │ │ │ │ └── chat_controller.js │ │ │ ├── lib │ │ │ │ └── split.js │ │ │ └── ui │ │ │ │ ├── commands.js │ │ │ │ └── tab_completion.js │ │ │ ├── init.js │ │ │ └── all.js │ ├── config.ru │ ├── views │ │ ├── twitter.erb │ │ ├── form.erb │ │ ├── message_form.erb │ │ ├── iphone_message_form.erb │ │ ├── index.erb │ │ ├── layout.erb │ │ ├── ipad.erb │ │ └── iphone.erb │ ├── helpers │ │ └── url_for.rb │ └── jschat.rb │ ├── storage │ ├── init.rb │ ├── null.rb │ └── mongo.rb │ ├── init.rb │ ├── flood_protection.rb │ ├── errors.rb │ ├── server_options.rb │ ├── server.rb │ └── client.rb ├── .gitignore ├── bin ├── jschat-client ├── jschat-server └── jschat-web ├── test ├── stateless_test.rb ├── test_helper.rb └── server_test.rb ├── jschat.gemspec ├── MIT-LICENSE ├── Rakefile └── README.textile /lib/jschat/http/tmp/restart.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | .DS_Store 4 | http/tmp 5 | -------------------------------------------------------------------------------- /lib/jschat/http/public/iOS-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/iOS-57.png -------------------------------------------------------------------------------- /lib/jschat/http/public/iOS-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/iOS-72.png -------------------------------------------------------------------------------- /lib/jschat/http/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/favicon.ico -------------------------------------------------------------------------------- /lib/jschat/http/public/iOS-114.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/iOS-114.png -------------------------------------------------------------------------------- /lib/jschat/http/public/stylesheets/ipad.css: -------------------------------------------------------------------------------- 1 | body { font-size: 120% } 2 | #message, #send_button { font-size: 130% } 3 | -------------------------------------------------------------------------------- /lib/jschat/http/public/images/jschat.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/jschat.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/shadow.png -------------------------------------------------------------------------------- /bin/jschat-client: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib')) 4 | 5 | require 'jschat/client' 6 | -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/arr.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/arr.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/btw.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/btw.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/clap.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/clap.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/cool.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/cool.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/dry.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/dry.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/eek.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/eek.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/flex.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/flex.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/huh.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/huh.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/lol.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/lol.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/mad.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/mad.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/oh.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/oh.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/ohmy.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/ohmy.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/pimp.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/pimp.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/rock.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/rock.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/rofl.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/rofl.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/sad.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/sad.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/w00t.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/w00t.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/wink.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/wink.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/angry.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/angry.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/blink.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/blink.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/blush.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/blush.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/drool.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/drool.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/drunk.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/drunk.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/happy.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/happy.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/holmes.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/holmes.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/laugh.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/laugh.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/mellow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/mellow.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/noclue.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/noclue.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/panic.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/panic.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/ph34r.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/ph34r.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/punch.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/punch.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/shifty.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/shifty.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/shock.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/shock.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/shrug.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/shrug.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/sleep.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/sleep.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/smile.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/smile.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/sweat.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/sweat.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/thumbs.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/thumbs.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/tongue.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/tongue.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/unsure.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/unsure.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/wacko.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/wacko.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/yucky.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/yucky.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/brucelee.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/brucelee.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/chuckle.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/chuckle.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/realmad.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/realmad.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/rolleyes.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/rolleyes.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/scratch.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/scratch.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/sleeping.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/sleeping.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/suicide.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/suicide.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/whistling.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/whistling.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/images/emoticons/worship.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexyoung/jschat/HEAD/lib/jschat/http/public/images/emoticons/worship.gif -------------------------------------------------------------------------------- /lib/jschat/http/public/stylesheets/iphone.css: -------------------------------------------------------------------------------- 1 | body { font-size: 200% } 2 | input { font-size: 150% } 3 | #info { display: none } 4 | .header .rooms { top: 6px; } 5 | .header .rooms li { padding-bottom: 4px; height: 1.25em; font-size: 120% } 6 | -------------------------------------------------------------------------------- /lib/jschat/http/config.ru: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'sinatra' 3 | 4 | set :environment, :production 5 | 6 | # You could log like this: 7 | # log = File.new(File.join(File.dirname(__FILE__), 'sinatra.log'), 'a') 8 | # $stdout.reopen(log) 9 | # $stderr.reopen(log) 10 | 11 | require 'jschat.rb' 12 | run Sinatra::Application 13 | -------------------------------------------------------------------------------- /lib/jschat/http/views/twitter.erb: -------------------------------------------------------------------------------- 1 |
JsChat will save your rooms and keep your presence online until you click Quit.
4 |This will persist even if you login on another computer.
5 | 6 | 7 | -------------------------------------------------------------------------------- /lib/jschat/http/views/form.erb: -------------------------------------------------------------------------------- 1 |JsChat is an open source chat system that uses a simple protocol based on JSON.
4 |To download the code and an irssi-like console client, visit GitHub.
5 |Read more on the JsChat Blog.
6 |:path_only, which will generate an absolute path within
7 | # the current domain (the default), or :full, which will
8 | # include the site name and port number. (The latter is typically
9 | # necessary for links in RSS feeds.) Example usage:
10 | #
11 | # url_for "/" # Returns "/myapp/"
12 | # url_for "/foo" # Returns "/myapp/foo"
13 | # url_for "/foo", :full # Returns "http://example.com/myapp/foo"
14 | #--
15 | # See README.rdoc for a list of some of the people who helped me clean
16 | # up earlier versions of this code.
17 | def url_for url_fragment, mode=:path_only
18 | case mode
19 | when :path_only
20 | base = request.script_name
21 | when :full
22 | scheme = request.scheme
23 | if (scheme == 'http' && request.port == 80 ||
24 | scheme == 'https' && request.port == 443)
25 | port = ""
26 | else
27 | port = ":#{request.port}"
28 | end
29 | base = "#{scheme}://#{request.host}#{port}#{request.script_name}"
30 | else
31 | raise TypeError, "Unknown url_for mode #{mode}"
32 | end
33 | "#{base}#{url_fragment}"
34 | end
35 | end
36 |
37 | helpers UrlForHelper
38 | end
39 |
--------------------------------------------------------------------------------
/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | require 'test/unit'
2 | require 'rubygems'
3 | require 'eventmachine'
4 | gem 'json', '>= 1.1.9'
5 | require 'json'
6 | $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7 | require File.join(File.dirname(__FILE__), '..', 'lib', 'jschat', 'server.rb')
8 |
9 | ServerConfig['max_message_length'] = 500
10 |
11 | class JsChat::Room
12 | def self.reset
13 | @@rooms = nil
14 | end
15 | end
16 |
17 | module JsChatHelpers
18 | def identify_as(name, channel = nil)
19 | if @cookie
20 | result = @jschat.receive_line({ 'identify' => name, :cookie => @cookie }.to_json)
21 | result = @jschat.receive_line({ 'join' => channel, :cookie => @cookie }.to_json) if channel
22 | else
23 | result = @jschat.receive_line({ 'identify' => name }.to_json)
24 | result = @jschat.receive_line({ 'join' => channel }.to_json) if channel
25 | end
26 | result
27 | end
28 |
29 | def send_to_jschat(h, parse = true)
30 | response = @jschat.receive_line(h.to_json)
31 | parse ? JSON.parse(response) : response
32 | end
33 | end
34 |
35 | class JsChatMock
36 | include JsChat
37 |
38 | def get_remote_ip
39 | ''
40 | end
41 |
42 | def send_data(data)
43 | data
44 | end
45 |
46 | def reset
47 | @@users = nil
48 | @user = nil
49 | Room.reset
50 | end
51 |
52 | # Helper for testing
53 | def add_user(name, room_name)
54 | room = Room.find_or_create room_name
55 | user = User.new self
56 | user.name = name
57 | user.rooms << room
58 | @@users << user
59 | room.users << user
60 | end
61 | end
62 |
63 | JsChat::Storage.enabled = false
64 | JsChat::Storage.driver = JsChat::Storage::NullDriver
65 |
66 |
--------------------------------------------------------------------------------
/lib/jschat/storage/mongo.rb:
--------------------------------------------------------------------------------
1 | begin
2 | require 'mongo'
3 | rescue LoadError
4 | end
5 |
6 | module JsChat::Storage
7 | module MongoDriver
8 | def self.connect!
9 | @db = Mongo::Connection.new(ServerConfig['db_host'], ServerConfig['db_port'], :slave_ok => true).db(ServerConfig['db_name'])
10 | if ServerConfig['db_username'] and ServerConfig['db_password']
11 | if @db.authenticate(ServerConfig['db_username'], ServerConfig['db_password'])
12 | true
13 | else
14 | raise 'Bad Mongo username or password'
15 | end
16 | else
17 | true
18 | end
19 | end
20 |
21 | def self.log(message, room)
22 | message['room'] = room
23 | @db['events'].insert(message)
24 | end
25 |
26 | def self.lastlog(number, room)
27 | @db['events'].find({ :room => room }, { :limit => number, :sort => ['time', Mongo::DESCENDING] }).to_a.reverse
28 | end
29 |
30 | def self.search(query, room, limit)
31 | query = /\b#{query}\b/i
32 | @db['events'].find({ 'message.message' => query, 'room' => room },
33 | { :limit => limit, :sort => ['time', Mongo::DESCENDING] }
34 | ).to_a.reverse
35 | end
36 |
37 | # TODO: use twitter oauth for the key
38 | def self.find_user(options)
39 | @db['users'].find_one(options)
40 | end
41 |
42 | def self.save_user(user)
43 | @db['users'].save user
44 | end
45 |
46 | def self.delete_user(user)
47 | @db['users'].remove user
48 | end
49 |
50 | def self.available?
51 | return unless Object.const_defined?(:Mongo)
52 | connect!
53 | rescue
54 | p $!
55 | puts 'Failed to connect to mongo'
56 | false
57 | end
58 | end
59 | end
60 |
--------------------------------------------------------------------------------
/lib/jschat/http/views/ipad.erb:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 | gem install jschat22 | 23 | Then run
jschat-server and jschat-client to try out the console client locally.
24 |
25 | To try out the web client, run jschat-web and visit "http://localhost:4567":http://localhost:4567.
26 |
27 | h3. Ruby Library Requirements
28 |
29 | These gems are required by JsChat:
30 |
31 | * eventmachine
32 | * ncurses (for the client)
33 | * json
34 |
35 | h3. Usage
36 |
37 | * Run the server with ./server.rb
38 | * Connect a client with ./client.rb
39 |
40 | The web app must be run alongside the server. The web app must be started in production mode:
41 |
42 | http/jschat.rb -e production
43 |
44 | The web app currently has no database dependencies, it's a wrapper that links cookies to JsChat server proxies. You can run it on port 80 by configuring Rack or an Apache proxy. I have Apache set up this way on "jschat.org":http://jschat.org.
45 |
46 | h3. Configuration Files
47 |
48 | These are the default locations of the configuration files. You can override them with --config=PATH:
49 |
50 | * Client: ~/.jschat/config.json
51 | * Server: /etc/jschat/config.json
52 |
53 | The web app will use the same configuration file as the server so it can find out where the server is.
54 |
55 | The file format is JSON, like this:
56 |
57 |
58 | { "port": 3001 }
59 |
60 |
61 | h3. Server Configuration Options
62 |
63 |
64 | {
65 | "port": integer,
66 | "ip": "string: IP address to bind to",
67 | "tmp_files": "string: path to tmp files (including PID file)"
68 | }
69 |
70 |
71 | h3. Client Commands
72 |
73 | * Change name or identify: /nick name
74 | * Join a room: /join #room
75 | * Join a room (alias): /j #room
76 |
77 | h3. Protocol Design
78 |
79 | The protocol is designed to be as close to executable JSON as possible, so clients and servers are simple to implement.
80 |
81 | Look at client.rb JsChat::Protocol to see what I mean.
82 |
83 | h3. Hey, this is like Campfire!
84 |
85 | I love Campfire and I didn't intend for JsChat to compete with it. JsChat is just a fun project, it doesn't offer Campfire's business-friendly interface, file hosting, transcripts and Basecamp integration.
86 |
87 | h3. Credits
88 |
89 | JsChat was created by "Alex Young":http://alexyoung.org for "Helicoid":http://helicoid.net. A growing group of friends are helping out:
90 |
91 | * "nickmartini":http://github.com/nickmartini
92 | * "gabrielg":http://github.com/gabrielg
93 | * "Simon Starr":http://github.com/sstarr
94 | * Kevin Ford
95 | * "sekrett":http://github.com/sekrett
96 |
97 | If you'd like to contribute, send "alexyoung":http://github.com/alexyoung a message on GitHub.
98 |
--------------------------------------------------------------------------------
/lib/jschat/http/public/stylesheets/screen.css:
--------------------------------------------------------------------------------
1 | body { margin: 0 auto; padding: 0; font-family: 'Lucida Grande', arial, helvetica, sans-serif; color: #111; text-align: center; }
2 | html, body { background: #f0f0f0; }
3 |
4 | h1, h2, h3, h4 { margin: 0; padding: 0; }
5 |
6 | h1 { text-align: left; margin-left: 20px }
7 |
8 | .header { position: absolute; top: 0; height: 59px; left: 0; width: 100%; z-index: 10; background-color: #ffc; clear: both; }
9 | .header img { border: none; margin: 5px 0 0 0 }
10 | .header h1 { width: 200px; float: left }
11 | .header .navigation { float: right; list-style-type: none; margin: 18px 0 0 0; padding: 0 }
12 | .header .navigation li { float: left; margin: 0 20px 0 0; padding: 0 }
13 | .header .navigation li a { text-decoration: none; color: #fff; background-color: #777; padding: 1px 3px }
14 | .header .navigation li a:hover { background-color: #fff; color: #555 }
15 | .header .navigation li#quit-nav a { background-color: #990000 }
16 | .header .navigation li#quit-nav a:hover { color: #990000; background-color: #fff }
17 | .header-shadow { width: 100%; height: 6px; position: absolute; top: 59px; left: 0; background-image: url('/images/shadow.png'); background-repeat: repeat-x }
18 |
19 | .header .rooms { position: absolute; left: 200px; top: 35px; list-style-type: none; margin: 0; padding: 0 }
20 | .header .rooms li { float: left; margin: 0 1px 0 0; padding: 2px 6px 3px 6px; background-color: #f0f0f0; border: 1px solid #aaa; border-bottom: #fff; font-size: 90%; height: 18px }
21 | .header .rooms li.selected { background-color: #fff; border: 1px solid #ccc; border-bottom: #fff }
22 | .header .rooms li a { color: #777; text-decoration: none }
23 | .header .rooms li a.new { color: #990000; font-weight: bold; }
24 | .header .rooms li a:hover { color: #000 }
25 | .header .rooms li.selected a { color: #444 }
26 |
27 | .page { margin-top: 60px }
28 |
29 | #messages { width: 500px; height: 300px; margin: 0 20px 10px 20px; padding: 0; overflow: auto; background-color: #fff; float: left; text-align: left; display: inline; }
30 | #messages { list-style-type: none; overflow: auto }
31 | #messages li { padding: 0.25em 0; border-bottom: 1px solid #f0f0f0; float: left; width: 100%; line-height: 1.5em }
32 | #messages span.user { margin: 0; text-align: left; font-weight: bold; display: inline; float: left }
33 | #messages .active { color: #000099 }
34 | #messages .mentioned { color: #cccc00 }
35 | #messages span.time { text-align: left; margin: 0 10px; display: block; float: left; color: #ccc !important; font-style: normal !important }
36 | #messages span.message { display: inline; padding: 0 0 0 10px }
37 | #messages .help { color: #990000 }
38 | #messages .help span.command { width: 12em; display: block; float: left; font-weight: bold }
39 | #messages li.server { color: #999; font-style: italic }
40 | #messages li.error { color: #990000; font-style: italic; font-weight: bold }
41 | #messages li.server span.time,
42 | #messages li.error span.time { color: #999 }
43 | img.inline-image { border: 1px solid #ccc; padding: 2px }
44 | img.inline-image {
45 | max-width: 200px;
46 | width: expression(this.width > 200 ? 200: true);
47 | }
48 |
49 | #input { clear: both; text-align: left; margin: 0 0 0 20px; padding: 0; }
50 | form { margin: 0; padding: 0; }
51 | #message { width: 100% }
52 | #message:focus { background-color: #ffc }
53 |
54 | #info { text-align: left; margin: 0 0 0 20px }
55 | #room-name { padding: 10px 0; font-size: 125% }
56 |
57 | ul#names { margin: 0; padding: 0; list-style-type: none; height: 200px; overflow: auto; }
58 | ul#names li { margin: 0; padding: 0.25em 0; }
59 | ul#names li.idle { color: #777 }
60 |
61 | .footer { border-top: 1px solid #ccc; padding: 8px 0 0 0; font-size: 80%; font-style: italic; color: #444; margin: 40px 0 0 0 }
62 |
63 | /* Front page */
64 | #sign-on { padding: 10px 0; margin: 10px auto; background-color: #fff; border: 1px solid #ccc; clear: both; text-align: center }
65 | #sign-on input[type="text"] { width: 12em }
66 | #sign-on input:focus { background-color: #ffc }
67 | .content { text-align: left; margin: 0 20px; padding: 5px 0 }
68 | .content em { padding: 1px 2px; font-style: normal; background-color: #ffc; color: #880000 }
69 | .content h2 { margin-top: 20px }
70 |
71 | #feedback .error { padding: 10px; border: 2px solid #990000; background-color: #fff; margin: 10px 0 }
72 | #loading { background-color: #990000; color: #fff; font-weight: bold; padding: 3px; margin: 0 auto; position: absolute; z-index: 1020; top: 0; right: 10px; border-top: none }
73 | .angry { color: #990000 }
74 | .big_message { background-color: #fff; border: 1px solid #ccc; padding: 10px; }
75 | .big_message h2, .big_message p { margin: 0; padding 0 }
76 | .big_message h2 { margin-bottom: 10px }
77 |
--------------------------------------------------------------------------------
/lib/jschat/http/public/javascripts/app/protocol/display.js:
--------------------------------------------------------------------------------
1 | var Display = {
2 | scrolled: false,
3 |
4 | add_message: function(text, className, time) {
5 | var time_html = '\#{time}'.interpolate({ time: TextHelper.dateText(time) });
6 | $('messages').insert({ bottom: '