jam-cloud/ruby/lib/jam_ruby/subscription_definitions.rb

139 lines
3.9 KiB
Ruby
Raw Permalink Normal View History

2020-11-21 22:14:37 +00:00
module JamRuby
class SubscriptionDefinitions
JAM_SILVER = 'jamsubsilver'
2020-11-30 00:24:28 +00:00
JAM_SILVER_YEARLY = 'jamsubsilveryearly'
2020-11-21 22:14:37 +00:00
JAM_GOLD = 'jamsubgold'
2020-11-30 00:24:28 +00:00
JAM_GOLD_YEARLY = 'jamsubgoldyearly'
2020-11-21 22:14:37 +00:00
JAM_PLATINUM = 'jamsubplatinum'
2020-11-30 00:24:28 +00:00
JAM_PLATINUM_YEARLY = 'jamsubplatinumyearly'
2020-11-21 22:14:37 +00:00
# ALL IN HOURS
FREE_PLAY_TIME_PER_SESSION = 1
FREE_PLAY_TIME_PER_MONTH = 4
SILVER_PLAY_TIME_PER_SESSION = nil # unlimited
SILVER_PLAY_TIME_PER_MONTH = 10
GOLD_PLAY_TIME_PER_SESSION = nil # unlimited
GOLD_PLAY_TIME_PER_MONTH = nil # unlimited
PLATINUM_PLAY_TIME_PER_SESSION = nil # unlimited
PLATINUM_PLAY_TIME_PER_MONTH = nil # unlimited
2020-12-05 18:16:38 +00:00
MONTHLY_PLANS = [
nil,
JAM_SILVER,
JAM_GOLD,
JAM_PLATINUM
]
2020-11-21 22:14:37 +00:00
FREE_PLAN = {
play_time_per_month: FREE_PLAY_TIME_PER_MONTH,
play_time_per_session: FREE_PLAY_TIME_PER_SESSION,
2020-11-30 00:24:28 +00:00
can_record_audio: false,
can_use_video: false,
can_record_video: false,
can_record_wave: false,
2020-11-30 03:22:00 +00:00
video_resolution: 1,
2020-11-30 00:24:28 +00:00
audio_max_bitrate: 1, # 128
can_broadcast: false,
broadcasting_type: 3,
2020-11-30 03:22:00 +00:00
max_players: 4,
2020-12-05 20:45:44 +00:00
pro_audio: false,
2020-12-30 01:02:08 +00:00
has_support: false,
2021-01-11 18:15:15 +00:00
name: 'Free',
rank: 0,
2020-11-21 22:14:37 +00:00
}
SILVER_PLAN = {
play_time_per_month: SILVER_PLAY_TIME_PER_MONTH,
play_time_per_session: SILVER_PLAY_TIME_PER_SESSION,
2020-11-30 00:24:28 +00:00
can_record_audio: false,
can_record_video: false,
can_use_video: true,
can_record_wave: true,
video_resolution: 1, # CIF in the backend
audio_max_bitrate: 2, #192
can_broadcast: true,
broadcasting_type: 3,
2020-12-30 01:02:08 +00:00
max_players: nil,
2020-12-05 20:45:44 +00:00
pro_audio: false,
2020-12-30 01:02:08 +00:00
has_support: false,
2021-01-11 18:15:15 +00:00
name: 'Silver',
rank: 1,
2020-11-21 22:14:37 +00:00
}
GOLD_PLAN = {
play_time_per_month: GOLD_PLAY_TIME_PER_MONTH,
play_time_per_session: GOLD_PLAY_TIME_PER_SESSION,
2020-11-30 00:24:28 +00:00
can_record_audio: true,
can_record_video: true,
can_use_video: true,
can_record_wave: true,
video_resolution: 3, # 720p in the backend
audio_max_bitrate: 3, #256
can_broadcast: true,
broadcasting_type: 3,
2020-11-30 03:22:00 +00:00
max_players: nil,
2020-12-05 20:45:44 +00:00
pro_audio: true,
2020-12-30 01:02:08 +00:00
has_support: true,
2021-01-11 18:15:15 +00:00
name: 'Gold',
rank: 2
2020-11-21 22:14:37 +00:00
}
PLATINUM_PLAN = {
play_time_per_month: PLATINUM_PLAY_TIME_PER_MONTH,
play_time_per_session: PLATINUM_PLAY_TIME_PER_SESSION,
2020-11-30 00:24:28 +00:00
can_record_audio: true,
can_record_video: true,
can_use_video: true,
can_record_wave: true,
video_resolution: 4, # 1080p in the backend
audio_max_bitrate: 5, #512
can_broadcast: true,
broadcasting_type: 3,
2020-11-30 03:22:00 +00:00
max_players: nil,
2020-12-05 20:45:44 +00:00
pro_audio: true,
2020-12-30 01:02:08 +00:00
has_support: true,
2021-01-11 18:15:15 +00:00
name: 'Platinum',
rank: 3
2020-11-21 22:14:37 +00:00
}
def self.rules(plan_code)
2021-01-11 18:15:15 +00:00
if plan_code == nil || plan_code == ''
2020-11-21 22:14:37 +00:00
FREE_PLAN
2020-11-30 00:24:28 +00:00
elsif plan_code == JAM_SILVER || plan_code == JAM_SILVER_YEARLY
2020-11-21 22:14:37 +00:00
SILVER_PLAN
2020-11-30 00:24:28 +00:00
elsif plan_code == JAM_GOLD || plan_code == JAM_GOLD_YEARLY
2020-11-21 22:14:37 +00:00
GOLD_PLAN
2020-11-30 00:24:28 +00:00
elsif plan_code == JAM_PLATINUM || plan_code == JAM_PLATINUM_YEARLY
2020-11-21 22:14:37 +00:00
PLATINUM_PLAN
else
raise "unknown plan #{plan_code}"
end
end
2021-01-11 18:15:15 +00:00
def self.is_downgrade(next_plan, current_plan)
next_plan_rank = rules(next_plan)[:rank]
current_plan_rank = rules(current_plan)[:rank]
next_plan_rank < current_plan_rank
end
def self.higher_plan(plan_a, plan_b)
if plan_a.nil?
plan_b
elsif plan_b.nil?
plan_a
else
plan_a_rank = rules(plan_a)[:rank]
plan_b_rank = rules(plan_b)[:rank]
# if plan a is higher, take plan_a
if plan_a_rank > plan_b_rank
plan_a
else
plan_b
end
end
end
2020-11-21 22:14:37 +00:00
end
end