seapig-rails 0.0.3 → 0.0.4
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb62d1753a2bd5140ae246bf3684fcb9ea0faccf
|
4
|
+
data.tar.gz: 90cd3b4c61da4f098dc4ec1b0fa84ee439d5e60f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a8d72ef25ff1af569147db2734310934c66250962ef5b7c5ca57b3292a0282cd86289aa45cb4e8185a61f1f78fd9240fd0638d83caa535cd8fa2d5b89feeceb
|
7
|
+
data.tar.gz: 27473c18d6476877676269fe3ccfe852bfad81021c38d0e9d5e9246bd305441b00d60ddbc84a4ac3ec5398b5973b95941481c46525e9feb474e11c1fc6bf861f
|
@@ -12,20 +12,20 @@ class @SeapigServer
|
|
12
12
|
connect: () ->
|
13
13
|
@connected = false
|
14
14
|
|
15
|
-
@socket = new WebSocket(@url
|
15
|
+
@socket = new WebSocket(@url)
|
16
16
|
|
17
17
|
@socket.onerror = (error) =>
|
18
18
|
console.log('Seapig socket error', error)
|
19
19
|
@socket.close()
|
20
20
|
|
21
21
|
@socket.onclose = () =>
|
22
|
-
console.log('Seapig connection closed')
|
22
|
+
console.log('Seapig connection closed') if @options.debug
|
23
23
|
for object_id, object of @slave_objects
|
24
24
|
object.valid = false
|
25
25
|
setTimeout((=>@connect()), 2000)
|
26
26
|
|
27
27
|
@socket.onopen = () =>
|
28
|
-
console.log('Seapig connection opened')
|
28
|
+
console.log('Seapig connection opened') if @options.debug
|
29
29
|
@connected = true
|
30
30
|
@socket.send(JSON.stringify(action: 'client-options-set', options: @options))
|
31
31
|
for object_id, object of @slave_objects
|
@@ -1,12 +1,13 @@
|
|
1
1
|
class @SeapigRouter
|
2
2
|
|
3
3
|
|
4
|
-
constructor: (seapig_server, session_id,
|
4
|
+
constructor: (seapig_server, session_id, initial_search, debug = false)->
|
5
5
|
@seapig_server = seapig_server
|
6
6
|
@session_id = session_id
|
7
7
|
@debug = debug
|
8
|
+
@initial_search = initial_search
|
8
9
|
|
9
|
-
@state =
|
10
|
+
@state = {session_id: @session_id, id: 0}
|
10
11
|
|
11
12
|
@session_data = @seapig_server.master('web-session-data-'+@session_id)
|
12
13
|
@session_data.object.states = [ @state ]
|
@@ -51,27 +52,32 @@ class @SeapigRouter
|
|
51
52
|
path_session_id = spl.shift()
|
52
53
|
path_state_id = spl.shift()
|
53
54
|
else
|
54
|
-
|
55
|
-
|
56
|
-
spl = []
|
55
|
+
window.history.replaceState(@state,null,'/a/'+@session_id+'/0'+@initial_search)
|
56
|
+
return @location_changed()
|
57
57
|
|
58
|
-
|
58
|
+
total_diff = []
|
59
|
+
partial_diff = []
|
59
60
|
while spl.length > 0
|
60
|
-
|
61
|
+
total_diff.push([spl.shift(),spl.shift()])
|
61
62
|
if window.location.search.length > 0
|
62
63
|
for pair in window.location.search.split('?')[1].split('&')
|
63
|
-
|
64
|
-
|
64
|
+
total_diff.push(pair.split('=',2))
|
65
|
+
partial_diff.push(pair.split('=',2))
|
66
|
+
console.log('Parsed location: session_id:',path_session_id,' partial_diff:', partial_diff) if @debug
|
65
67
|
|
66
68
|
if path_session_id == @session_id
|
67
|
-
@state_change(
|
69
|
+
@state_change(partial_diff)
|
68
70
|
else
|
69
71
|
if @remote_state?
|
70
|
-
@state_change_to_remote(
|
72
|
+
@state_change_to_remote(total_diff)
|
71
73
|
else
|
72
74
|
@state_valid = false
|
73
|
-
|
74
|
-
|
75
|
+
if path_state_id == '0'
|
76
|
+
@remote_state = {object: {session_id: path_session_id, id: 0}}
|
77
|
+
@state_change_to_remote(total_diff)
|
78
|
+
else
|
79
|
+
@remote_state = @seapig_server.slave('web-session-state-'+path_session_id+':'+path_state_id)
|
80
|
+
@remote_state.onchange = ()=> @state_change_to_remote(total_diff)
|
75
81
|
|
76
82
|
|
77
83
|
state_change_to_remote: (diff) ->
|
@@ -95,7 +101,7 @@ class @SeapigRouter
|
|
95
101
|
@session_data.object.states.push(@state)
|
96
102
|
@session_data.changed()
|
97
103
|
if @remote_state?
|
98
|
-
@remote_state.unlink()
|
104
|
+
@remote_state.unlink() if @remote_state.object.id > 0
|
99
105
|
@remote_state = null
|
100
106
|
@state_valid = true
|
101
107
|
@state_changed()
|
@@ -103,10 +109,28 @@ class @SeapigRouter
|
|
103
109
|
|
104
110
|
state_diff_apply: (state, diff)->
|
105
111
|
for entry in diff
|
106
|
-
|
107
|
-
|
112
|
+
address = entry[0]
|
113
|
+
value = entry[1]
|
114
|
+
add = (address[0] != '-')
|
115
|
+
hash = (address[address.length-1] != '~')
|
116
|
+
address = address[1..-1] if address[0] == '-'
|
117
|
+
address = address[0..-2] if address[address.length-1] == '~'
|
118
|
+
obj = state
|
119
|
+
spl = address.split('~')
|
120
|
+
for subobj,i in spl
|
121
|
+
if i < (spl.length-1)
|
122
|
+
obj[subobj] = {} if not obj[subobj]?
|
123
|
+
obj = obj[subobj]
|
124
|
+
if add
|
125
|
+
if hash
|
126
|
+
obj[spl[spl.length-1]] = value
|
127
|
+
else
|
128
|
+
obj[spl[spl.length-1]].push(value)
|
108
129
|
else
|
109
|
-
|
130
|
+
if hash
|
131
|
+
delete obj[spl[spl.length-1]]
|
132
|
+
else
|
133
|
+
state[entry[0]].splice(_.indexOf(state[entry[0]], value),1)
|
110
134
|
state
|
111
135
|
|
112
136
|
|
data/bin/seapig-notifier
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
#!/bin/env ruby
|
2
2
|
|
3
|
+
ENV['RAILS_ENV'] = 'production'
|
3
4
|
require './config/environment.rb'
|
4
5
|
|
5
6
|
require 'websocket-eventmachine-client'
|
6
7
|
require 'json'
|
7
8
|
|
8
|
-
|
9
|
-
Rails.application.eager_load!
|
10
9
|
notifiers = Hash[*ActiveRecord::Base.descendants.select { |cls| cls.respond_to?('seapig_dependency_version') }.map { |notifier| [notifier.name,notifier] }.flatten ]
|
11
10
|
|
11
|
+
puts "Known notifiers:"
|
12
|
+
notifiers.keys.each { |notifier| puts " "+notifier }
|
13
|
+
puts
|
14
|
+
|
12
15
|
$last_versions = {}
|
13
16
|
$payloads = Queue.new
|
14
17
|
|
data/lib/seapig/version.rb
CHANGED
@@ -12,8 +12,9 @@ class SeapigRouterSessionStateProducer < Producer
|
|
12
12
|
version = Time.new.to_f
|
13
13
|
p session_key, object_id
|
14
14
|
session = SeapigRouterSession.find_by(key: session_key)
|
15
|
-
|
16
|
-
|
15
|
+
state = SeapigRouterSessionState.find_by(seapig_router_session_id: session.id, state_id: state_id)
|
16
|
+
return [false, {SeapigRouterSessionState: SeapigRouterSessionState.seapig_dependency_version}] if not state
|
17
|
+
data = state.state
|
17
18
|
[data, version]
|
18
19
|
end
|
19
20
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seapig-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yunta
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|