desc time author veaba
 *  import { insertOne , updateOne } from "../mongo/curd" ; import { _sid_obj } from "../utils/utils" ; import { getTime } from 'date-fns' ; import { isObject } from "../utils/check" ; import { delKey , delSet , setSet , totalOnline } from "../redis/redis" ; import { getTotal , getWorldMap } from "./worldMap" ; import { getChinaRank , getChinaDay , getWorldRank } from "./rank" ; import { talkIn } from "./talk" ; import { _pushSuccess } from "../app" ; desc param socket { Object } export const connectSocket = async ( socket ) => { const { id , handshake } = socket ; const { issued } = handshake ; const { sid } = _sid_obj ( id ) ; await insertOne ( { ... _sid_obj ( id ) , noAuthCount : 1 , beginTime : issued } , 'sockets' ) ; await setSet ( 'onlineSocket' , sid ) ; await _pushSuccess ( 'broadcast' , 'online' , await totalOnline ( 'onlineSocket' ) ) ; socket . on ( 'disconnect' , async ( ) => { const { id } = socket ; await delSet ( 'onlineSocket' , sid ) ; await updateOne ( { sid } , { ... _sid_obj ( id ) , endTime : getTime ( new Date ( ) ) } , 'sockets' ) ; await delKey ( sid ) ; await _pushSuccess ( 'broadcast' , 'online' , await totalOnline ( 'onlineSocket' ) ) ; } ) ; } ; desc report feat check bug export const onSocket = async ( socket , eventName ) => { const { nsp , id } = socket ; const { name } = nsp || { } ; const { sid } = _sid_obj ( id ) ; const channel = ( name || '' ) . replace ( '/' , '' , '' ) ; await socket . on ( eventName , async ( data ) => { switch ( eventName ) { case 'talk' : await talkIn ( socket , sid , data , channel , eventName ) ; break ; case 'getTotal' : await getTotal ( socket , data , channel , eventName ) ; break ; case 'getChinaDay' : await getChinaDay ( socket , data , channel , eventName ) ; break ; case 'getChinaRank' : await getChinaRank ( socket , data , channel , eventName ) ; break ; case 'getWorldRank' : await getWorldRank ( socket , data , channel , eventName ) ; break ; case 'getWorldMap' : return await getWorldMap ( socket , data , channel , eventName ) ; default : throw new Error ( '未能识别Channel类型' ) ; } } ) ; } ; desc param socket param body param channel param eventName param logType export const logSocket = async ( socket , body , channel , eventName , logType ) => { let insertBody = { } ; if ( Array . isArray ( body ) || isObject ( body ) ) { insertBody = body ; } else { insertBody = { data : body } ; } const { id , handshake } = socket ; const { sid } = _sid_obj ( id ) ; const { headers , issued } = handshake ; await insertOne ( { sid , channel , body : { ... insertBody } , headers , eventName , reportTime : issued , logType } , 'logs' ) ; } ;