2012-10-07 03:38:38 +00:00
|
|
|
module JamWebsockets
|
2012-08-17 03:22:31 +00:00
|
|
|
class ClientContext
|
|
|
|
|
|
2020-12-27 23:58:31 +00:00
|
|
|
attr_accessor :user, :client, :msg_count, :session, :client_type, :sent_bad_state_previously, :active, :updated_at
|
2012-08-17 03:22:31 +00:00
|
|
|
|
2014-04-30 03:01:28 +00:00
|
|
|
def initialize(user, client, client_type)
|
2012-08-22 03:08:01 +00:00
|
|
|
@user = user
|
2012-10-02 05:03:08 +00:00
|
|
|
@client = client
|
2014-04-30 03:01:28 +00:00
|
|
|
|
|
|
|
|
@client_type = client_type
|
2012-10-02 05:03:08 +00:00
|
|
|
@msg_count = 0
|
|
|
|
|
@session = nil
|
2013-07-15 02:50:34 +00:00
|
|
|
@sent_bad_state_previously = false
|
2016-01-19 00:41:53 +00:00
|
|
|
@active = true
|
2020-12-27 23:58:31 +00:00
|
|
|
@updated_at = Time.now
|
2014-04-30 03:01:28 +00:00
|
|
|
client.context = self
|
2012-08-17 03:22:31 +00:00
|
|
|
end
|
2012-08-26 18:42:22 +00:00
|
|
|
|
2020-12-27 23:58:31 +00:00
|
|
|
def stale?(stale_time)
|
|
|
|
|
return Time.now - @updated_at > stale_time
|
|
|
|
|
end
|
|
|
|
|
|
2012-10-02 05:03:08 +00:00
|
|
|
def to_s
|
2014-05-01 19:09:33 +00:00
|
|
|
return "Client[user:#{@user} client:#{@client.client_id} msgs:#{@msg_count} session:#{@session} client_type:#{@client_type} channel_id: #{@client.channel_id}]"
|
2012-10-02 05:03:08 +00:00
|
|
|
end
|
2012-08-26 18:42:22 +00:00
|
|
|
|
2014-04-30 03:01:28 +00:00
|
|
|
def to_json
|
2014-05-01 19:09:33 +00:00
|
|
|
{user_id: @user.id, client_id: @client.client_id, msg_count: @msg_count, client_type: @client_type, socket_id: @client.channel_id}.to_json
|
2014-04-30 03:01:28 +00:00
|
|
|
end
|
|
|
|
|
|
2013-08-07 15:38:35 +00:00
|
|
|
def hash
|
|
|
|
|
@client.hash
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def ==(o)
|
|
|
|
|
o.class == self.class && o.client == @client
|
|
|
|
|
end
|
|
|
|
|
alias_method :eql?, :==
|
|
|
|
|
|
2012-08-17 03:22:31 +00:00
|
|
|
end
|
|
|
|
|
end
|