farcall 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/farcall/version.rb +1 -1
- data/lib/farcall/wsclient_transport.rb +49 -45
- 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: e62f0ec5501d7053137341f5ec5f46100b692b61
|
4
|
+
data.tar.gz: 9549befd37e328bef65639d99953ee15bae8da2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37f168b9631e06851ca3ebb9f84b19dd145836878210a3d7050b343b43f6e57c9bf7790f1969e9fb951270e941a7a10b14bb0f9b537ed6c2e6d805989ce2f974
|
7
|
+
data.tar.gz: 103a6f0f987801726f1876bf6f696926aada0644ed815d6ec50a06d04ced6c483f972d4011494957daec606aadc7b34e0a00793aa3e74123248bb7529b470f07
|
data/lib/farcall/version.rb
CHANGED
@@ -1,55 +1,59 @@
|
|
1
1
|
require 'farcall'
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
begin
|
3
|
+
require 'websocket-client-simple'
|
4
|
+
require_relative './monitor_lock'
|
5
|
+
require 'json'
|
5
6
|
|
6
|
-
module Farcall
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
7
|
+
module Farcall
|
8
|
+
# Websocket client transport using JSON encodeing. Works with ruby threads, pure ruby, runs
|
9
|
+
# everywhere. Use if like any thoer Farcall::Transport, for example:
|
10
|
+
#
|
11
|
+
# in your Gemfile
|
12
|
+
#
|
13
|
+
# gem 'websocket-client-simple'
|
14
|
+
#
|
15
|
+
# in the code
|
16
|
+
#
|
17
|
+
# wst = Farcall::WebsocketJsonClientTransport.new 'ws://icodici.com:8080/test'
|
18
|
+
# i = Farcall::Interface.new transport: wst
|
19
|
+
# result = i.authenticate(login, password) # remote call via interface...
|
20
|
+
#
|
21
|
+
class WebsocketJsonClientTransport < Farcall::Transport
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
# Create transport connected to the specified websocket url. Constructor blocks
|
24
|
+
# until connected, or raise error if connection can't be established. Transport uses
|
25
|
+
# JSON encodgin over standard websocket protocol.
|
26
|
+
def initialize ws_url
|
27
|
+
# The stranges bug around in the WebSocket::Client (actually in his eventemitter)
|
28
|
+
me = self
|
28
29
|
|
29
|
-
|
30
|
-
|
30
|
+
is_open = Semaphore.new
|
31
|
+
@ws = WebSocket::Client::Simple.connect(ws_url)
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
@ws.on(:open) {
|
34
|
+
# if me != self
|
35
|
+
# puts "\n\n\nSelf is set to wrong in the callback in #{RUBY_VERSION}\n\n\n"
|
36
|
+
# end
|
37
|
+
# puts "client is open"
|
38
|
+
is_open.set
|
39
|
+
}
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
@ws.on(:message) { |m|
|
42
|
+
# puts "ws client received #{JSON.parse m.data}"
|
43
|
+
me.on_data_received and me.on_data_received.call(JSON.parse m.data)
|
44
|
+
# puts "and sent"
|
45
|
+
}
|
46
|
+
@ws.on(:close) { close }
|
47
|
+
is_open.wait_set
|
48
|
+
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
# :nodoc:
|
51
|
+
def send_data data
|
52
|
+
@ws.send JSON[data]
|
53
|
+
end
|
53
54
|
|
55
|
+
end
|
54
56
|
end
|
57
|
+
rescue LoadError
|
58
|
+
$!.to_s =~ /websocket/ or raise
|
55
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: farcall
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergeych
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|