realtime 0.0.6 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/realtime.rb +1 -0
- data/lib/realtime/realtime_controller.rb +27 -5
- data/lib/realtime/version.rb +1 -1
- data/lib/realtime/zmq_wrapper.rb +32 -0
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d51386293451f00ca5c30c478f81b44b5319f596
|
4
|
+
data.tar.gz: 2fe074b98ff94585282dd45013ba26abb5f1280c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d82fa7edbc079e5db5bf883e06b38fe189be50302e95c19548a068f6b4001c5d7170e4a4268969a409cb65def6f3ccb36ee58a8f359e33efb543f3200b43f8a3
|
7
|
+
data.tar.gz: 73e0f8b6669caaba4067d9a3bdb6312c857f853a272b7792075b1c830198786fd87584a5698dad6b2cf19109abef6f8891bf02b3da4a0ea27aa31b3e9f9f0608
|
data/lib/realtime.rb
CHANGED
@@ -3,11 +3,17 @@ module Realtime
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
module ClassMethods
|
6
|
-
def realtime_controller
|
6
|
+
def realtime_controller(options = nil)
|
7
7
|
before_filter :do_realtime_token
|
8
8
|
before_filter :do_realtime_user_id
|
9
9
|
before_filter :do_realtime_server_url
|
10
|
-
|
10
|
+
if options.nil?
|
11
|
+
after_filter :store_realtime_session_redis
|
12
|
+
elsif options[:queue] == :redis
|
13
|
+
after_filter :store_realtime_session_redis
|
14
|
+
elsif options[:queue] == :zmq
|
15
|
+
after_filter :store_realtime_session_zmq
|
16
|
+
end
|
11
17
|
end
|
12
18
|
end
|
13
19
|
|
@@ -26,8 +32,26 @@ module Realtime
|
|
26
32
|
return @realtime_server_url
|
27
33
|
end
|
28
34
|
|
35
|
+
# create shared session tokens for redis/socketio realtime server running on node.js
|
36
|
+
def store_realtime_session_zmq
|
37
|
+
# store session data or any authentication data you want here, generate to JSON data
|
38
|
+
session_data = {
|
39
|
+
"user_id" => realtime_user_id,
|
40
|
+
}
|
41
|
+
|
42
|
+
# todo: merge additional session data passed in
|
43
|
+
stored_session_data = JSON.generate(session_data)
|
44
|
+
|
45
|
+
ZmqWrapper.store_session(
|
46
|
+
realtime_user_id,
|
47
|
+
@realtime_token,
|
48
|
+
stored_session_data,
|
49
|
+
86400
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
29
53
|
# create shared session tokens for redis/socketio realtime server running on node.js
|
30
|
-
def
|
54
|
+
def store_realtime_session_redis
|
31
55
|
# store session data or any authentication data you want here, generate to JSON data
|
32
56
|
session_data = {
|
33
57
|
"user_id" => realtime_user_id,
|
@@ -45,8 +69,6 @@ module Realtime
|
|
45
69
|
|
46
70
|
# expire this realtime session after one day.
|
47
71
|
RedisWrapper.redis.expire("rtSession-" + realtime_user_id.to_s, 86400)
|
48
|
-
|
49
|
-
|
50
72
|
end
|
51
73
|
|
52
74
|
end
|
data/lib/realtime/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
class ZmqWrapper
|
2
|
+
|
3
|
+
require 'em-zeromq'
|
4
|
+
|
5
|
+
def self.publish(the_message)
|
6
|
+
EM.run {
|
7
|
+
zmq = EM::ZeroMQ::Context.new(1)
|
8
|
+
pusher = zmq.socket(ZMQ::PUSH)
|
9
|
+
pusher.connect($zmq_server)
|
10
|
+
message = "realtime_msg:" + the_message.to_json
|
11
|
+
puts "Pushing realtime message: " + message
|
12
|
+
pusher.send_msg(message)
|
13
|
+
EM.stop
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.store_session(user_id, session_id, session_data, expiration)
|
18
|
+
EM.run {
|
19
|
+
zmq = EM::ZeroMQ::Context.new(1)
|
20
|
+
pusher = zmq.socket(ZMQ::PUSH)
|
21
|
+
pusher.connect($zmq_server)
|
22
|
+
the_message = {user_id: user_id,
|
23
|
+
session_id: session_id,
|
24
|
+
session_data: session_data,
|
25
|
+
expiration: expiration}
|
26
|
+
message = "rtSession:" + the_message.to_json
|
27
|
+
puts "Pushing session message: " + message
|
28
|
+
pusher.send_msg(message)
|
29
|
+
EM.stop
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: realtime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Atlas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.1.1
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: redis
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '>='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
description: Provides a simple Realtime framework for Rails applications.
|
42
28
|
email:
|
43
29
|
- mike.atlas@gmail.com
|
@@ -53,6 +39,7 @@ files:
|
|
53
39
|
- lib/realtime/redis_wrapper.rb
|
54
40
|
- lib/realtime/version.rb
|
55
41
|
- lib/realtime/view_helpers.rb
|
42
|
+
- lib/realtime/zmq_wrapper.rb
|
56
43
|
- lib/realtime.rb
|
57
44
|
- MIT-LICENSE
|
58
45
|
homepage: http://mikeatlas.github.io/realtime-rails/
|