magic_mirror 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/changelog +16 -1
- data/lib/magic_mirror/command_cache.rb +5 -0
- data/lib/magic_mirror/mirror.rb +37 -12
- data/lib/magic_mirror/sinatra_silver.rb +6 -0
- data/lib/magic_mirror/version.rb +1 -1
- data/talk.md +57 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99ae6ed2cd45562d4fe35027396c9fb97c71e35a
|
4
|
+
data.tar.gz: 9a94943f0ec1d9c6e59534a1653cef1aa5584dfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b44cbc8caa075fd22f931bea1ca149b99c0bd2b8a95d5e7577998b71c714a5dde15ffa7fa7e3394a6259cd68949b5418e5a71e97c9a68fc2c5382e74de394298
|
7
|
+
data.tar.gz: 5b8b356d1117ef8d273a2c54d9747e079cad042afa0eda612d82643aef108e14c547a879174285bc86d1ff5430d1c427342150a80333aae0053a0c90c3aa0f08
|
data/changelog
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
TODO: List off what features you'll be including at some point in the
|
3
3
|
future.
|
4
4
|
|
5
|
+
- Test against port in use problem.
|
6
|
+
|
7
|
+
- How do you tell the host gem to just 'listen for commands' and idle there?
|
8
|
+
(so the reverse usage of trtl)
|
9
|
+
possible do a .join() on the sinatra thread?
|
10
|
+
|
11
|
+
- limitation: Can only have one rendering display at a time *per computer*
|
12
|
+
> Solution: Clean up the output and make ports random
|
13
|
+
|
5
14
|
- Bug: If faye server goes offline for a second, and misses commands, then comes back online,
|
6
15
|
the command_cache variable will be out of sync with that of the server
|
7
16
|
> Solutions: Javascript Function periodically checks in to see the
|
@@ -22,9 +31,15 @@ Currently:
|
|
22
31
|
|
23
32
|
Finished:
|
24
33
|
|
34
|
+
** 0.1.1 **
|
35
|
+
|
36
|
+
- Added command_cache#reset
|
37
|
+
- Silenced booting of servers and added own boot message
|
38
|
+
|
39
|
+
|
25
40
|
** 0.1.0 **
|
26
41
|
|
27
|
-
- Changed API to Minimizing magic_mirror commands needed on the host gem
|
42
|
+
- Changed API to Minimizing magic_mirror commands needed on the host gem
|
28
43
|
|
29
44
|
** 0.0.2 **
|
30
45
|
- got websockets online
|
data/lib/magic_mirror/mirror.rb
CHANGED
@@ -6,33 +6,58 @@ module MagicMirror
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def init_servers!
|
9
|
-
|
9
|
+
Thin::Logging.silent = true
|
10
|
+
print "\nActivating the Magic Mirror."
|
11
|
+
|
12
|
+
@threads = []
|
13
|
+
|
10
14
|
# start sinatra
|
11
|
-
threads << start_sinatra
|
12
|
-
threads << start_faye
|
15
|
+
@threads << start_sinatra
|
16
|
+
@threads << start_faye
|
13
17
|
|
18
|
+
puts "\nThe Magic Mirror is Activated. Navigate to http://127.0.0.1:4567"
|
14
19
|
self
|
15
20
|
end
|
16
21
|
|
17
22
|
def start_sinatra
|
23
|
+
queue = Queue.new # allows waiting for sinatra boot
|
24
|
+
$stderr_backup = $stderr.dup
|
25
|
+
$stderr.reopen("/dev/null", "w")
|
26
|
+
|
18
27
|
Thread.new {
|
19
|
-
SinatraSilver::App.run!
|
28
|
+
SinatraSilver::App.run! do |server|
|
29
|
+
queue.push("started") # tells caller thread to continue
|
30
|
+
end
|
20
31
|
}
|
32
|
+
|
33
|
+
queue.pop # blocks until sinatra is booted
|
34
|
+
print "."
|
35
|
+
|
36
|
+
$stderr = $stderr_backup.dup
|
21
37
|
end
|
22
38
|
|
23
39
|
def start_faye
|
40
|
+
queue = Queue.new # allows waiting for sinatra boot
|
24
41
|
|
25
42
|
Thread.new {
|
26
43
|
bayeux = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)
|
27
44
|
bayeux.listen(FAYE_PORT)
|
28
|
-
run
|
45
|
+
bayeux.run!
|
46
|
+
#run bayeux
|
29
47
|
}
|
30
48
|
|
31
|
-
#
|
49
|
+
#queue.pop # blocks until server is booted
|
50
|
+
wait_until_faye_is_up
|
51
|
+
print "."
|
52
|
+
|
32
53
|
end
|
33
54
|
|
34
|
-
def
|
55
|
+
def command_cache
|
56
|
+
MagicMirror.command_cache
|
57
|
+
end
|
35
58
|
|
59
|
+
def command_cache=(value)
|
60
|
+
MagicMirror.command_cache = value
|
36
61
|
end
|
37
62
|
|
38
63
|
# sends messages through faye server to web interface
|
@@ -45,22 +70,22 @@ module MagicMirror
|
|
45
70
|
begin
|
46
71
|
Net::HTTP.post_form(uri, :message => message.to_json)
|
47
72
|
rescue
|
48
|
-
puts "failed to send message to faye server and thus webclient"
|
73
|
+
$stderr.puts "failed to send message to faye server and thus webclient"
|
49
74
|
end
|
50
75
|
|
51
76
|
end
|
52
77
|
|
53
78
|
def wait_until_faye_is_up
|
79
|
+
require 'net/http'
|
54
80
|
while(true) do
|
55
81
|
begin
|
56
|
-
uri = URI.parse("http://localhost:#{FAYE_PORT}/
|
57
|
-
# Shortcut
|
82
|
+
uri = URI.parse("http://localhost:#{FAYE_PORT}/")
|
58
83
|
response = Net::HTTP.get_response(uri)
|
59
84
|
rescue
|
60
85
|
|
61
86
|
end
|
62
|
-
|
63
|
-
|
87
|
+
break if response and response.code == "404" and response.body == "Sure you're not looking for /faye ?"
|
88
|
+
sleep 0.1
|
64
89
|
end
|
65
90
|
end
|
66
91
|
|
@@ -7,6 +7,12 @@ module SinatraSilver
|
|
7
7
|
# set :views, MagicMirror.sinatra_root
|
8
8
|
set :views, Proc.new { File.join(MagicMirror.sinatra_root, "lib", "views") }
|
9
9
|
#set :public_folder, Proc.new { File.join(MagicMirror.sinatra_root, "lib", "views") }
|
10
|
+
#set :logging, false
|
11
|
+
set :logging, false
|
12
|
+
|
13
|
+
configure do
|
14
|
+
disable :logging
|
15
|
+
end
|
10
16
|
|
11
17
|
get '/' do
|
12
18
|
@command_cache = MagicMirror.command_cache.to_json
|
data/lib/magic_mirror/version.rb
CHANGED
data/talk.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
## S1.0 What is magic_mirror?
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
## S1.1 rails vs traditional programming
|
7
|
+
|
8
|
+
Everyone here has probably heard of rails before.
|
9
|
+
Well Rails, Sinatra, Python's django... Flask...
|
10
|
+
These are all ways of building GUI applications for
|
11
|
+
* Multiple Users
|
12
|
+
and in an
|
13
|
+
* MVC design pattern
|
14
|
+
|
15
|
+
Now that I know rails, I'm happy with MVC.
|
16
|
+
It helps us keep our code organized and clean.
|
17
|
+
Though in some use cases, it slows us down.
|
18
|
+
Say, if you wanted your app to print the version number when /version is accessed.
|
19
|
+
That should only take 4 lines of code, one after another, right?
|
20
|
+
But with MVC, we need to change 4 different files.
|
21
|
+
So MVC is good for some things.
|
22
|
+
But MVC isn't good for *all* things, I don't think that's a controversial statement.
|
23
|
+
|
24
|
+
So what if we just want to add a GUI to our existing command line app?
|
25
|
+
Obviously our CLI apps aren't designed in the MVC pattern,
|
26
|
+
so we can't just start copy/pasting things into a rails app.
|
27
|
+
And maybe we don't even want to put it on the web,
|
28
|
+
we want to use the app exclusively from our own machine.
|
29
|
+
|
30
|
+
That's where magic_mirror comes in.
|
31
|
+
We simply add it as a dependency, and call MagicMirror.new() and pass in a root
|
32
|
+
directory from which to serve our index view.
|
33
|
+
|
34
|
+
Of course we have to draw up an html file to serve as our GUI,
|
35
|
+
but once that's done, you now have a GUI for your once gooey-less application.
|
36
|
+
|
37
|
+
So in principle, this is a pretty cool gem...
|
38
|
+
|
39
|
+
|
40
|
+
## S2 What is magic_mirror... Specifically?
|
41
|
+
|
42
|
+
So by now you're probably wondering what comprises this interesting gem.
|
43
|
+
Well magic_mirror is:
|
44
|
+
* A sinatra html/ web server (on thin)
|
45
|
+
* A Faye websocket server (on thin)
|
46
|
+
* A class variable that caches all commands sent through the websocket server
|
47
|
+
(The mirror if you will)
|
48
|
+
|
49
|
+
## S3 How do you add magic_mirror to a project?
|
50
|
+
|
51
|
+
To use magic_mirror, simply require the gem as a dependency and add a line
|
52
|
+
`@mirror = MagicMirror.new(options)`
|
53
|
+
As options, you must specify where your html assets live.
|
54
|
+
Then you can do `@mirror.init_servers!` to boot the web/ websocket servers.
|
55
|
+
|
56
|
+
|
57
|
+
## Lets do a hello world
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magic_mirror
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TheNotary
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/views/index.erb
|
160
160
|
- magic_mirror.gemspec
|
161
161
|
- rspec
|
162
|
+
- talk.md
|
162
163
|
homepage: https://github.com/TheNotary/magic_mirror
|
163
164
|
licenses:
|
164
165
|
- MIT
|