import net from 'net' ; import { HolepunchType } from 'packets/holepunch/inholepunch' ; import { Channel } from 'channel/channel' ; import { Room } from 'room/room' ; import { SessionNetworkInfo } from 'user/sessionnetworkinfo' ; import { User } from 'user/user' ; /**
 * holds an user's session information
 */ export class UserSession { public user : User ; public externalNet : SessionNetworkInfo ; public internalNet : SessionNetworkInfo ; public currentChannel : Channel ; public currentRoom : Room ; constructor ( user , addr ) { this . externalNet = new SessionNetworkInfo ( ) ; this . internalNet = new SessionNetworkInfo ( ) ; this . user = user ; this . externalNet . ipAddress = addr . address ; } returns public isInRoom ( ) { return this . currentRoom != null ; } param ipAddress param portId param localPort param externalPort returns public shouldUpdatePorts ( portId , localPort , externalPort ) { switch ( portId ) { case HolepunchType . Client : return ( localPort !== this . internalNet . clientPort || externalPort !== this . externalNet . clientPort ) ; case HolepunchType . Server : return ( localPort !== this . internalNet . serverPort || externalPort !== this . externalNet . serverPort ) ; case HolepunchType . SourceTV : return ( localPort !== this . internalNet . tvPort || externalPort !== this . externalNet . tvPort ) ; } return false ; } public setHolepunch ( portId , localPort , externalPort ) { switch ( portId ) { case HolepunchType . Client : this . internalNet . clientPort = localPort ; this . externalNet . clientPort = externalPort ; return 0 ; case HolepunchType . Server : this . internalNet . serverPort = localPort ; this . externalNet . serverPort = externalPort ; return 1 ; case HolepunchType . SourceTV : this . internalNet . tvPort = localPort ; this . externalNet . tvPort = externalPort ; return 2 ; default : return - 1 ; } } }