module import { ObserverHandler } from './observer' ; import { JWT , TwitchAuth } from './twitch' ; import Util from './util' ; export class UserUpdateCallbackHandle extends ObserverHandler < User > { private cb : ( user : User ) => void ; constructor ( cb ) { super ( ) ; this . cb = cb ; } public notify ( user ) { this . cb ( user ) ; } } /**
 * Stores fields related to the current extension user, either a viewer or the broadcaster.
 * These fields are automatically updated by the SDK.
 */ export default class User { public channelID : string ; public twitchJWT : string ; public twitchOpaqueID : string ; public twitchID : string ; public helixToken : string ; public muxyID : string ; public registeredWithMuxy : boolean ; public visualizationID : string ; public role : string ; public ip : string ; public game : string ; public videoMode : string ; public bitrate : number ; public latency : number ; public buffer : number ; public theme : string ; public volume : number ; public timeOffset : number ; since static get Roles ( ) { return { Broadcaster : 'broadcaster' , Moderator : 'moderator' , Viewer : 'viewer' } ; } since static get VideoModes ( ) { return { Default : 'default' , Fullscreen : 'fullscreen' , Theatre : 'theatre' } ; } since param { Object } auth constructor ( auth ) { since type { string } this . channelID = auth . channelId ; since type { Object } this . twitchJWT = auth . token ; since type { string } this . twitchOpaqueID = auth . userId ; since this . helixToken = auth . helixToken ; since type { null | string } this . twitchID = null ; since type { boolean } this . registeredWithMuxy = false ; since type { null | string } this . muxyID = null ; since type { string } this . visualizationID = '' ; /**
         * role is the current user's role in the extension. May be one of  Roles .
         *
         *  since type { string } this . role = User . Roles . Viewer ; since type { string } this . ip = '' ; since type { string } this . game = '' ; /**
         * User's current video mode. One of  VideoModes .
         *
         *  since type { string } this . videoMode = User . VideoModes . Default ; since type { null | number } this . bitrate = null ; since type { null | number } this . latency = null ; since type { null | number } this . buffer = null ; type { null | string } this . theme = null ; type { number } this . volume = 0 ; this . extractJWTInfo ( auth . token ) ; private this . timeOffset = 0 ; } since param { Object } jwt public extractJWTInfo ( jwt ) { try { const token = Util . extractJWTInfo ( jwt ) ; this . role = token . role ; if ( token . user_id ) { this . twitchID = token . user_id ; } } catch ( err ) { } } since return { boolean } public anonymous ( ) { return ! this . twitchOpaqueID || this . twitchOpaqueID [ 0 ] !== 'U' ; } since param { Object } auth public updateAuth ( auth ) { this . twitchJWT = auth . token ; this . helixToken = auth . helixToken ; this . extractJWTInfo ( auth . token ) ; } return { Date } public getOffsetDate ( ) { return new Date ( new Date ( ) . getTime ( ) + this . timeOffset ) ; } }