import moment from 'moment' ; import { map } from 'lodash' ; import { Session , Participant } from './types' ; export default function makeSession ( json ) { const clusterId = json . cluster_name ; const created = new Date ( json . created ) ; const duration = moment ( new Date ( ) ) . diff ( created ) ; const durationText = moment . duration ( duration ) . humanize ( ) ; const login = json . login ; const namespace = json . namespace ; const parties = map ( json . parties , makeParticipant ) ; const serverId = json . server_id ; const sid = json . id ; const hostname = json . server_hostname ; const addr = json . server_addr . replace ( PORT_REGEX , '' ) ; return { sid , namespace , login , created , durationText , serverId , hostname , clusterId , parties , addr , } ; } export function makeParticipant ( json ) { const remoteAddr = json . remote_addr || '' ; return { user : json . user , remoteAddr : remoteAddr . replace ( PORT_REGEX , '' ) , } ; } const PORT_REGEX = /:\d+$/ ;