summaryrefslogtreecommitdiff
path: root/game/client/tf/tf_streams.h
blob: 88279e37f12eeb46a8733eb33942ad005cd78a6c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//			
//=============================================================================

#ifndef TF_STREAMS_H
#define TF_STREAMS_H
#ifdef _WIN32
#pragma once
#endif

#include "vgui_controls/EditablePanel.h"

using namespace vgui;

#define MAX_STREAM_PANELS 5

class CStreamInfo
{
public:
	CStreamInfo() : m_numViewers( 0 ) {}
public:
	CUtlString m_sGlobalName;
	int m_numViewers;
	CUtlString m_sDisplayName;
	CUtlString m_sTextDescription;
	CUtlString m_sUpdatedAtStamp;
	CUtlString m_sPreviewImage;
	CUtlString m_sPreviewImageLocalFile;
	CUtlString m_sPreviewImageSF;
	CUtlString m_sLanguage;
	CUtlString m_sCountry;
	CUtlString m_sVideoFeedUrl;
};

class CTFStreamPanel : public EditablePanel
{
public:
	DECLARE_CLASS_SIMPLE( CTFStreamPanel, EditablePanel );

	CTFStreamPanel( Panel *parent, const char *panelName );
	virtual ~CTFStreamPanel() {}

	virtual void ApplySchemeSettings( IScheme *pScheme ) OVERRIDE;
	virtual void PerformLayout() OVERRIDE;
	virtual void OnCommand( const char *command ) OVERRIDE;

	void SetGlobalName( const char *pszGlobalName ) { m_strStreamInfoGlobalName = pszGlobalName; }
	CStreamInfo *GetStreamInfo() const;

private:
	void UpdatePanels();
	void SetPreviewImage( const char *pszPreviewImageFile );

	CUtlString m_strStreamInfoGlobalName;

	class vgui::ImagePanel *m_pPreviewImage;
};

class CTFStreamListPanel : public EditablePanel, public CGameEventListener
{
public:
	DECLARE_CLASS_SIMPLE( CTFStreamListPanel, EditablePanel );

	CTFStreamListPanel( Panel *parent, const char *panelName );
	virtual ~CTFStreamListPanel() {}

	virtual void ApplySchemeSettings( IScheme *pScheme ) OVERRIDE;
	virtual void OnThink() OVERRIDE;
	virtual void OnCommand( const char *command ) OVERRIDE;

	virtual void FireGameEvent( IGameEvent *event ) OVERRIDE;

	CTFStreamPanel *m_arrStreamPanels[MAX_STREAM_PANELS];
};

enum ETwitchTvState_t
{
	k_ETwitchTvState_None,
	k_ETwitchTvState_Loading,
	k_ETwitchTvState_NoLink,
	k_ETwitchTvState_Linked,
	k_ETwitchTvState_Error
};

struct TwitchTvAccountInfo_t
{
	uint64 m_uiSteamID;

	ETwitchTvState_t m_eTwitchTvState;
	double m_dblTimeStampTwitchTvUpdate;
	uint64 m_uiTwitchTvUserId;
	CUtlString m_sTwitchTvChannel;
};

class CTFStreamManager : public CAutoGameSystemPerFrame
{
public:
	CTFStreamManager();
	~CTFStreamManager();

	virtual bool Init() OVERRIDE;
	virtual void Update( float frametime ) OVERRIDE;
	void RequestTopStreams();

	CStreamInfo * GetStreamInfoByName( char const *szName );

	CUtlVector< CStreamInfo >& GetStreamInfoVec() { return m_streamInfoVec; }

	TwitchTvAccountInfo_t* GetTwitchTvAccountInfo( uint64 uiSteamID );

private: // cache stream info
	CUtlVector< CStreamInfo > m_streamInfoVec;

private: // query for top X viewers
	double m_dblTimeStampLastUpdate;
	HTTPRequestHandle m_hHTTPRequestHandle;
	CCallResult< CTFStreamManager, HTTPRequestCompleted_t > m_CallbackOnHTTPRequestCompleted;
	void Steam_OnHTTPRequestCompletedStreams( HTTPRequestCompleted_t *p, bool bError );

private: // checking for twitch account linking with steam account
	void UpdateTwitchTvAccounts();

	TwitchTvAccountInfo_t *m_pLoadingAccount;
	CUtlVector< TwitchTvAccountInfo_t* > m_vecTwitchTvAccounts; // list of steam id to updated twitch account
	HTTPRequestHandle m_hHTTPRequestHandleTwitchTv;
	CCallResult< CTFStreamManager, HTTPRequestCompleted_t > m_CallbackOnHTTPRequestCompletedTwitchTv;
	void Steam_OnHTTPRequestCompletedMyTwitchTv( HTTPRequestCompleted_t *p, bool bError );
};
CTFStreamManager *StreamManager();

#endif // TF_STREAMS_H