secret_knock 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/secret_knock.rb +34 -4
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f563e31f57fd2e069234691672ca82d30ac7f408
|
4
|
+
data.tar.gz: eeef07610f8195bbf7e2dfaf6fbb9cf2bd2675dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2290017d47f7026c92c34491f888a858a694238d9158c1c81c1dc9e6359c28ad17abbea8a40cb1fc632bcfdf18a6f828beb41c5d53cfe529d2076e9e97fe7ff3
|
7
|
+
data.tar.gz: 84f1cf5bae8b3a22e960210c961795fe70f0508218996431315ff5348b6f79f97300107cb8b87b5e4b5e253c464d4ed7a270766b47b4d7f468cf2b2728bdc433
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/secret_knock.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
class SecretKnock
|
7
7
|
|
8
|
-
attr_reader :h, :message
|
8
|
+
attr_reader :h, :message, :listening
|
9
9
|
|
10
10
|
def initialize(verbose: true, external: nil)
|
11
11
|
|
@@ -42,12 +42,27 @@ class SecretKnock
|
|
42
42
|
@hb = h.invert
|
43
43
|
|
44
44
|
@short_delay, @long_delay = 0.35, 0.9 # seconds
|
45
|
+
@listening = false
|
45
46
|
|
46
47
|
end
|
47
48
|
|
48
49
|
def autoknock(s)
|
49
50
|
playback knockerize(s)
|
50
51
|
end
|
52
|
+
|
53
|
+
def detect(timeout: 2, repeat: true)
|
54
|
+
|
55
|
+
listen
|
56
|
+
|
57
|
+
Thread.new do
|
58
|
+
|
59
|
+
sleep 0.2 while @t + timeout > Time.now or @a.length <= 1
|
60
|
+
msg = decipher()
|
61
|
+
on_timeout msg
|
62
|
+
@external.message msg if @external
|
63
|
+
detect(timeout: timeout, repeat: repeat) if repeat
|
64
|
+
end
|
65
|
+
end
|
51
66
|
|
52
67
|
def knocked()
|
53
68
|
|
@@ -98,7 +113,9 @@ class SecretKnock
|
|
98
113
|
|
99
114
|
@t = Time.now
|
100
115
|
@i = 1
|
101
|
-
@a = [
|
116
|
+
@a = []
|
117
|
+
|
118
|
+
@listening = true
|
102
119
|
|
103
120
|
if block_given? then
|
104
121
|
yield self
|
@@ -113,6 +130,10 @@ class SecretKnock
|
|
113
130
|
sleep @long_delay + 0.1
|
114
131
|
|
115
132
|
end
|
133
|
+
|
134
|
+
def on_timeout(msg='')
|
135
|
+
# override this method if you wish
|
136
|
+
end
|
116
137
|
|
117
138
|
alias pause long_pause
|
118
139
|
|
@@ -137,10 +158,19 @@ class SecretKnock
|
|
137
158
|
|
138
159
|
def stop_listening()
|
139
160
|
|
140
|
-
@
|
161
|
+
@listening = false
|
162
|
+
@message = decipher()
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
private
|
167
|
+
|
168
|
+
def decipher()
|
169
|
+
|
170
|
+
@a.join.gsub(/(\d{2})(\d)/,'\1,\2').split(',')\
|
141
171
|
.inject([]) do |r, x|
|
142
172
|
(x != '42' ? r << @hb[x.to_i] : r[0..-2])
|
143
173
|
end.join
|
144
|
-
|
145
174
|
end
|
175
|
+
|
146
176
|
end
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|