keyhole 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/keyhole.rb CHANGED
@@ -5,6 +5,7 @@ require File.dirname(__FILE__) + '/query_server'
5
5
  require 'em-websocket'
6
6
  require 'sinatra/base'
7
7
  require 'thin'
8
+ require 'em-mysqlplus'
8
9
 
9
10
 
10
11
  EventMachine.run{
@@ -13,13 +14,14 @@ EventMachine.run{
13
14
  # of multiple servers. Or, it can just be an http-based reporting tool.
14
15
  class Querier < Sinatra::Base
15
16
  get "/" do
16
- return "This is Keyhole, with #{$clients.length} clients connected"
17
+ return "This is Keyhole, with #{$clients.length} trackers and #{$webclients.length} webclients connected."
17
18
  end
18
19
  end
19
20
 
20
21
 
21
- $channel = EM::Channel.new
22
- $clients = {}
22
+ $channel = EM::Channel.new
23
+ $clients = {}
24
+ $webclients = {}
23
25
 
24
26
  EventMachine::start_server "0.0.0.0", 5000, SatParser
25
27
  EventMachine::start_server "0.0.0.0", 5500, QueryServer
@@ -28,11 +30,11 @@ EventMachine.run{
28
30
  EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug => true) do |ws|
29
31
  ws.onopen{
30
32
  sid = $channel.subscribe { |msg| ws.send msg }
31
- $clients[sid] = true
33
+ $webclients[sid] = true
32
34
  ws.onmessage{|msg| $channel.push "Ninja!" }
33
35
  ws.onclose{
34
36
  $channel.unsubscribe(sid)
35
- $clients.delete(sid)
37
+ $webclients.delete(sid)
36
38
  }
37
39
  }
38
40
  end
data/lib/query_server.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  # QueryServer responds to telnet-calls on its designated port, and responds
2
2
  # with things...
3
3
  class QueryServer < EventMachine::Connection
4
-
5
4
  def post_init
6
5
  send_data "#{$clients.length} clients connected"
6
+
7
+
7
8
  end
8
9
 
9
10
  def receive_data(data)
data/lib/sat_parser.rb CHANGED
@@ -1,12 +1,17 @@
1
1
  class SatParser < EventMachine::Connection
2
2
 
3
+ attr_accessor :db
4
+
3
5
  def post_init
4
- puts "GSAT connected"
6
+ $clients.push(self)
7
+ db = EventMachine::MySQL.new(:host => "localhost", :username => "root", :database => "keyhole_development")
8
+ $channel << "{event:'connect', 'type':'tracker'}"
5
9
  end
6
10
 
7
11
  def receive_data(data)
8
12
  puts "Data received..."
9
13
  puts data.inspect
14
+ db.query("insert into locations(latitude, longitude) value('ninja', 'neger');")
10
15
  $channel << data
11
16
  end
12
17
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keyhole
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - buffpojken