Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun
commit
af1e1a7831
@ -0,0 +1,41 @@
|
|||||||
|
module UserOnline
|
||||||
|
class << self
|
||||||
|
def login(user_id)
|
||||||
|
set_bit(user_id, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def logout(user_id)
|
||||||
|
set_bit(user_id, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_bit(user_id, flag)
|
||||||
|
if !Rails.cache.data.exists(cache_key)
|
||||||
|
Rails.cache.data.setbit(cache_key, user_id, flag)
|
||||||
|
Rails.cache.data.expire(cache_key, 20 * 60 + 10)
|
||||||
|
else
|
||||||
|
Rails.cache.data.setbit(cache_key, user_id, flag)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def count
|
||||||
|
if Rails.cache.is_a?(ActiveSupport::Cache::RedisStore)
|
||||||
|
Rails.cache.data.bitcount(cache_key)
|
||||||
|
else
|
||||||
|
0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def cache_key
|
||||||
|
if Rails.cache.is_a?(ActiveSupport::Cache::RedisStore)
|
||||||
|
# 10分钟为一段记录用户在线, 统计范围为20分钟内的线用户
|
||||||
|
# TODO 更精确时长
|
||||||
|
begin_hour = Time.now.beginning_of_hour
|
||||||
|
minutes_piece = (Time.now - begin_hour) / 600
|
||||||
|
time = begin_hour.since((minutes_piece.to_i - 1) * 600).strftime("%H-%M")
|
||||||
|
"online_user_#{time}"
|
||||||
|
else
|
||||||
|
raise '请配置config.cache_store = redis_store'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,4 +1,4 @@
|
|||||||
json.status 1
|
json.status 1
|
||||||
json.message "发送成功"
|
json.message "发送成功"
|
||||||
json.course_id @course.id
|
json.course_id @course.id
|
||||||
json.first_category_url module_url(@course.none_hidden_course_modules.first, @course)
|
json.first_category_url module_url(@course.shixun_course_modules.first, @course)
|
@ -1,3 +1,3 @@
|
|||||||
json.status 1
|
json.status 1
|
||||||
json.message "发送成功"
|
json.message "发送成功"
|
||||||
json.url module_url(@course.none_hidden_course_modules.first, @course)
|
json.url module_url(@course.shixun_course_modules.first, @course)
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -0,0 +1,37 @@
|
|||||||
|
import React, { useEffect, useRef } from 'react'
|
||||||
|
|
||||||
|
export default ({ url }) => {
|
||||||
|
const ref = useRef()
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let player = null
|
||||||
|
if (window.flvjs.isSupported) {
|
||||||
|
player = window.flvjs.createPlayer({
|
||||||
|
type: 'flv',
|
||||||
|
volume: 0.8,
|
||||||
|
cors: true,
|
||||||
|
url,
|
||||||
|
muted: false
|
||||||
|
})
|
||||||
|
|
||||||
|
if (ref.current) {
|
||||||
|
player.attachMediaElement(ref.current)
|
||||||
|
player.load()
|
||||||
|
player.play()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
if (player) {
|
||||||
|
player.unload()
|
||||||
|
player.pause()
|
||||||
|
player.destroy()
|
||||||
|
player = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}, [url, ref.current])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<video ref={ref} controls autoPlay={true} muted={false} className="flv-player"></video>
|
||||||
|
)
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
import React, { Fragment } from 'react'
|
||||||
|
import ReactFlvPlayer from './flv-player'
|
||||||
|
|
||||||
|
export default ({ src }) => {
|
||||||
|
const suf = src.split('.').pop()
|
||||||
|
const isFlv = suf === 'flv'
|
||||||
|
return (
|
||||||
|
<Fragment>
|
||||||
|
{
|
||||||
|
isFlv ? <ReactFlvPlayer url={src} isMuted={true} /> : <video src={src} controls autoPlay={true} controlsList="nodownload">
|
||||||
|
<source type={`video/${suf}`} src={src} />
|
||||||
|
您的浏览器不支持 video 标签。
|
||||||
|
</video>
|
||||||
|
}
|
||||||
|
</Fragment>
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in new issue