buttplugrb 1.0.0 → 1.1.2
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.
- checksums.yaml +4 -4
- data/Rakefile +29 -2
- data/lib/buttplugrb.rb +107 -41
- data/lib/buttplugrb/VERSION +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2140196b9069aa198ba78fb631e4e55fc1516083
|
4
|
+
data.tar.gz: d553e4ae2610b35679e87460dcc9dbfaf851b816
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 955d2c2f5966edf8dbab3659eb4f6d8728087025189767987b0169ee7aeac3ba316cc7bd7abdd1446109b92f0cf8b628a74a5db3ceddc190c364ce1d62d5c6ae
|
7
|
+
data.tar.gz: 0c375682d60e93f4eb84f386e0118868546b251fa7d9e75034a8fbc749447feeda53a8105dff1b842e85a1c65db9efd8bf405eaa3170d1281632b00167260399
|
data/Rakefile
CHANGED
@@ -1,2 +1,29 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
|
1
|
+
#require "bundler/gem_tasks"
|
2
|
+
desc "Our Default Task"
|
3
|
+
task :default do
|
4
|
+
Rake::Task[:buildDevVersion].invoke
|
5
|
+
end
|
6
|
+
desc "Build the gem, and install it (primairly for testing)"
|
7
|
+
task :buildDevVersion do
|
8
|
+
sh %{gem uninstall buttplugrb}
|
9
|
+
sh %{gem build buttplugrb.gemspec}
|
10
|
+
sh %{gem install buttplugrb*.gem}
|
11
|
+
sh %{rm buttplugrb*.gem}
|
12
|
+
end
|
13
|
+
task :getCurrentRelease do
|
14
|
+
sh %{gem uninstall buttplugrb}
|
15
|
+
sh %{gem install buttplugrb}
|
16
|
+
end
|
17
|
+
task :console do
|
18
|
+
sh %{ruby bin/console}
|
19
|
+
end
|
20
|
+
task :buildDevandRun do
|
21
|
+
Rake::Task[:buildDevVersion].invoke
|
22
|
+
Rake::Task[:console].invoke
|
23
|
+
end
|
24
|
+
task :buildReleaseVersionAndPush do
|
25
|
+
sh %{gem uninstall buttplugrb}
|
26
|
+
sh %{gem build buttplugrb.gemspec}
|
27
|
+
sh %{gem push buttplugrb*.gem}
|
28
|
+
sh %{rm buttplugrb*.gem}
|
29
|
+
end
|
data/lib/buttplugrb.rb
CHANGED
@@ -6,6 +6,18 @@ require 'json'
|
|
6
6
|
Our Module for containg the functions and classes relating to the Buttplugrb gem
|
7
7
|
=end
|
8
8
|
module Buttplug
|
9
|
+
=begin rdoc
|
10
|
+
The module holding all of our various log levels that our client can set our server to
|
11
|
+
=end
|
12
|
+
module LogLevel
|
13
|
+
Off = 0
|
14
|
+
Fatal = 1
|
15
|
+
Error = 2
|
16
|
+
Warn = 3
|
17
|
+
Info = 4
|
18
|
+
Debug = 5
|
19
|
+
Trace = 6
|
20
|
+
end
|
9
21
|
=begin rdoc
|
10
22
|
Our Client for a buttplug.io server
|
11
23
|
=end
|
@@ -19,57 +31,30 @@ Arguments:
|
|
19
31
|
Returns:
|
20
32
|
* A shiney new buttplug client ready for some action
|
21
33
|
=end
|
22
|
-
def initialize(serverLocation)
|
34
|
+
def initialize(serverLocation, clientName="buttplugrb")
|
35
|
+
@messageID=1
|
23
36
|
@location=serverLocation
|
24
37
|
#Ok Explanation time!
|
25
38
|
# * @EventQueue - The events we are triggering on the server, Expected to be an array, with the first element being the message Id, and the second being the message itself!
|
26
39
|
@eventQueue=EM::Queue.new
|
27
|
-
@
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
tickLoop=EM.tick_loop do #Should improve response times~
|
32
|
-
eventQueue.pop{|msg|
|
33
|
-
ws.send msg[1]
|
34
|
-
messageWatch[msg[0]]=msg
|
35
|
-
p [Time.now, :message_send, msg[1]]
|
36
|
-
}
|
37
|
-
end
|
38
|
-
ws.on :open do |event|
|
39
|
-
p [Time.now, :open]
|
40
|
-
ws.send '[{"RequestServerInfo": {"Id": 1, "ClientName": "roboMegumin", "MessageVersion": 1}}]'
|
41
|
-
end
|
42
|
-
ws.on :message do |event|
|
43
|
-
message=JSON::parse(event.data)[0]
|
44
|
-
message.each{|key,value|
|
45
|
-
#We don't really care about the key just yet ... We are going to just care about finding our ID
|
46
|
-
if(messageWatch.keys.include?(value["Id"]))
|
47
|
-
messageWatch[value["Id"]]<<{key => value}#And now we care about our key!
|
48
|
-
puts messageWatch[value["Id"]].object_id
|
49
|
-
messageWatch.delete(value["Id"])
|
50
|
-
p [Time.now, :message_recieved, [{key => value}]]
|
51
|
-
next
|
52
|
-
elsif(key=="ServerInfo")
|
53
|
-
p [Time.now, :server_info, value]
|
54
|
-
end
|
55
|
-
}
|
56
|
-
end
|
57
|
-
ws.on :close do |event|
|
58
|
-
p [Time.now, :close, event.code, event.reason]
|
59
|
-
ws = nil
|
60
|
-
end
|
61
|
-
EM.add_periodic_timer(0.5){
|
62
|
-
ws.send "[{\"Ping\": {\"Id\": #{generateID()}}}]"
|
63
|
-
}
|
64
|
-
}}
|
40
|
+
@logLevel=Buttplug::LogLevel::Off
|
41
|
+
@scanning=false
|
42
|
+
@currentDevices=[];
|
43
|
+
startEventMachine()
|
65
44
|
@eventMachine.run
|
66
45
|
end
|
46
|
+
def setLogLevel(logLevel)
|
47
|
+
@logLevel=logLevel
|
48
|
+
end
|
67
49
|
=begin rdoc
|
68
50
|
Tells our server to start scanning for new devices
|
69
51
|
=end
|
70
52
|
def startScanning()
|
71
53
|
id=generateID()
|
72
|
-
|
54
|
+
response=sendMessage([id,"[{\"StartScanning\":{\"Id\":#{id}}}]"])
|
55
|
+
if(response[0].keys.include? "Error")
|
56
|
+
#TODO: Add Error Handling code
|
57
|
+
end
|
73
58
|
end
|
74
59
|
=begin rdoc
|
75
60
|
Tells our server to stop scanning for new devices
|
@@ -78,6 +63,9 @@ Tells our server to stop scanning for new devices
|
|
78
63
|
id=generateID()
|
79
64
|
@eventQueue.push([id,"[{\"StopScanning\":{\"Id\":#{id}}}]"])
|
80
65
|
end
|
66
|
+
def isScanning?()
|
67
|
+
return @scanning
|
68
|
+
end
|
81
69
|
=begin rdoc
|
82
70
|
Lists all devices available to the server
|
83
71
|
|
@@ -128,8 +116,86 @@ Returns:
|
|
128
116
|
* a number between 2 and 4294967295
|
129
117
|
=end
|
130
118
|
def generateID()
|
131
|
-
|
119
|
+
@messageID+=1
|
120
|
+
return @messageID
|
121
|
+
end
|
122
|
+
def currentDevices()
|
123
|
+
return @currentDevices
|
124
|
+
end
|
125
|
+
def deviceSusbscribe(id,&code)
|
126
|
+
#TODO: Add Code here to allow a class like Buttplug::Device to subscribe to events, annnnd realize that the device has disconnected when that does happen (like the hush has a tendeancy to do ... )
|
127
|
+
end
|
128
|
+
protected
|
129
|
+
def startEventMachine()
|
130
|
+
@eventMachine=Thread.new{EM.run{
|
131
|
+
eventQueue=@eventQueue
|
132
|
+
messageWatch={}
|
133
|
+
logLevel=@logLevel
|
134
|
+
scanning=@scanning
|
135
|
+
currentDevices=@currentDevices
|
136
|
+
ws = Faye::WebSocket::Client.new(@location)
|
137
|
+
tickLoop=EM.tick_loop do #Should improve response times~
|
138
|
+
eventQueue.pop{|msg|
|
139
|
+
ws.send msg[1]
|
140
|
+
messageWatch[msg[0]]=msg
|
141
|
+
p [Time.now, :message_send, msg[1]]
|
142
|
+
}
|
143
|
+
end
|
144
|
+
ws.on :open do |event|
|
145
|
+
p [Time.now, :open]
|
146
|
+
ws.send "[{\"RequestServerInfo\": {\"Id\": 1, \"ClientName\": \"#{clientName}\", \"MessageVersion\": 1}}]"
|
147
|
+
#TODO: Add MaxPingTime Code
|
148
|
+
end
|
149
|
+
ws.on :message do |event|
|
150
|
+
#Ok, first of all let's grab
|
151
|
+
message=JSON::parse(event.data).each{|event|
|
152
|
+
message.each{|key,value|
|
153
|
+
#We don't really care about the key just yet ... We are going to just care about finding our ID
|
154
|
+
if(messageWatch.keys.include?(value["Id"]))
|
155
|
+
messageWatch[value["Id"]]<<{key => value}#And now we care about our key!
|
156
|
+
puts messageWatch[value["Id"]].object_id
|
157
|
+
messageWatch.delete(value["Id"])
|
158
|
+
p [Time.now, :message_recieved, [{key => value}]]
|
159
|
+
next
|
160
|
+
#If we are currently scanning, we should Probably check and see if we recieved a ScanningFinished message
|
161
|
+
elsif(scanning&&key=="ScanningFinished")
|
162
|
+
p [Time.now,:ScanningFinished]
|
163
|
+
scanning=false
|
164
|
+
#If we are logging, we should probably Check and see if this is a log ...
|
165
|
+
elsif(logLevel>Buttplug::LogLevel::Off&&key=="Log")
|
166
|
+
p [Time.now,:ServerLog,value]
|
167
|
+
#and last but not least if we spot our server info we should probably log it ...
|
168
|
+
elsif(key=="DeviceAdded")
|
169
|
+
#Oh? Sweet let's go ahead and add it's information to our array!
|
170
|
+
currentDevices.push(
|
171
|
+
{"DeviceName" => value["DeviceName"], "DeviceIndex" => value["DeviceIndex"], "DeviceMessages" => value["DeviceMessages"]})
|
172
|
+
elsif(key=="DeviceRemoved")
|
173
|
+
#well darn, and to just have compatability with the current js version of buttplug.io we are gonna do this a bit diffrently than I'd like ... we are totally not doing this because I'm feeling lazy and want to push out this itteration, no sir
|
174
|
+
currentDevices.reject!{|device|
|
175
|
+
device["Id"]==value["Id"]
|
176
|
+
}
|
177
|
+
elsif(key=="ServerInfo")
|
178
|
+
p [Time.now, :server_info, value]
|
179
|
+
end
|
180
|
+
}
|
181
|
+
}
|
182
|
+
end
|
183
|
+
ws.on :close do |event|
|
184
|
+
p [Time.now, :close, event.code, event.reason]
|
185
|
+
ws = nil
|
186
|
+
#TODO: Add Nil checks for Sends, and Nil out the ping when closed
|
187
|
+
end
|
188
|
+
EM.add_periodic_timer(0.5){
|
189
|
+
ws.send "[{\"Ping\": {\"Id\": #{generateID()}}}]"
|
190
|
+
}
|
191
|
+
#TODO: Add Error code https://metafetish.github.io/buttplug/status.html#error
|
192
|
+
#So, I should probably add some basic error handling to most of the code then ...
|
193
|
+
#TODO: Add Log code https://metafetish.github.io/buttplug/status.html#requestlog
|
194
|
+
#Done, I think ... please correct me if I'm wrong
|
195
|
+
}}
|
132
196
|
end
|
197
|
+
#TODO: Add Method to disconnect from current Server
|
198
|
+
#TODO: Add Method for reconnecting to a Server
|
133
199
|
end
|
134
200
|
=begin rdoc
|
135
201
|
This class creates a Wrapper for your various devices you fetched from listDevices for your controlling pleasure!
|
data/lib/buttplugrb/VERSION
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buttplugrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nora Maguire
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faye-websocket
|