Class: SessionRouter

Inherits:
Router
  • Object
show all
Defined in:
lib/shot_mvc/session_router.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ SessionRouter

Returns a new instance of SessionRouter.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/shot_mvc/session_router.rb', line 30

def initialize(client)
	super(client)

	client.on 'session_key' do |key|
		create_session_folder unless Dir.exists? 'app/sessions'
		create_session_file key unless File.exists? "app/sessions/#{key}.json"

		client.config[:session_key] = key
		client.config[:session] = JSON.parse File.read "app/sessions/#{key}.json"

		client.emit 'session_ready'
	end

	client.on 'request_session_key' do
		session_key = SecureRandom.uuid
		client.emit 'assign_session_key', :key => session_key, :session_hash => client.config['server']['Security']['SessionHash']

		create_session_folder unless Dir.exists? 'app/sessions'
		create_session_file session_key unless File.exists? "app/sessions/#{session_key}.json"

		client.config[:session_key] = session_key
		client.config[:session] = JSON.parse File.read "app/sessions/#{session_key}.json"

		client.emit 'session_ready'
	end

	client.emit 'provide_session_key', client.config['server']['Security']['SessionHash']
end