FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javascript-client/src/debug-socket.ts at main · code-game-project/javascript-client · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Jul 22, 2026. It is now read-only.
code-game-project
/
javascript-client
Public archive
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
javascript-client
/
src
/
debug-socket.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
92 lines (83 loc) · 3 KB
Breadcrumbs
javascript-client
/
src
/
debug-socket.ts
Copy path
File metadata and controls
92 lines (83 loc) · 3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
{
Verbosity
,
Socket
}
from
'./socket.js'
;
/** Severity levels. */
export
enum
Severity
{
ERROR
=
'error'
,
WARNING
=
'warning'
,
INFO
=
'info'
,
TRACE
=
'trace'
}
/** A debug message. */
export
type
DebugMessage
=
{
severity
:
Severity
,
message
:
string
,
data
?:
object
;
}
;
/** Signature of a debug message listener function. */
export
type
DebugListenerCallback
=
(
message
:
string
,
data
?:
object
)
=>
void
;
export
class
DebugSocket
<
Config
extends
object
=
object
>
extends
Socket
<
Config
>
{
/** WebSocket message handler. */
private
readonly
messageHandler
=
(
data
:
MessageEvent
<
any
>
)
=>
{
try
{
const
message
:
DebugMessage
=
JSON
.
parse
(
data
.
data
)
;
if
(
this
.
verbosityReached
(
Verbosity
.
DEBUG
)
)
{
this
.
logger
.
info
(
`
${
message
.
severity
.
toUpperCase
(
)
}
:
${
message
.
message
}
`
,
message
.
data
)
;
}
this
.
triggerListeners
(
message
.
severity
,
message
.
message
,
message
.
data
)
;
}
catch
(
error
)
{
if
(
this
.
verbosityReached
(
Verbosity
.
ERROR
)
)
{
this
.
logger
.
error
(
'Error in WebSocket "message" event listener:'
,
error
)
;
}
;
}
}
;
/**
* Registers a debug message listener for a certain severity.
*
@param
severity Severity to listen for.
*
@param
callback Function that is executed when a message with the specified severity is received.
*
@returns
the listener's ID.
*/
public
on
(
severity
:
Severity
,
callback
:
DebugListenerCallback
)
:
symbol
{
return
this
.
listen
(
severity
,
callback
,
false
)
;
}
/**
* Registers a debug message listener for a certain severity that will self-destruct after being triggered once.
*
@param
severity Severity to listen for.
*
@param
callback Function that is executed when a message with the specified severity is received.
*
@returns
the listener's ID.
*/
public
once
(
severity
:
Severity
,
callback
:
DebugListenerCallback
)
:
symbol
{
return
this
.
listen
(
severity
,
callback
,
true
)
;
}
/**
* Debug a server.
*
@throws
if the connection cannot be established.
*
@chainable
*/
public
async
debugServer
(
)
:
Promise
<
this
>
{
await
this
.
makeWebSocketConnection
(
`/api/debug`
,
this
.
messageHandler
)
;
return
this
;
}
/**
* Debug a game.
*
@param
gameId The ID of the game to debug.
*
@throws
if the connection cannot be established.
*
@chainable
*/
public
async
debugGame
(
gameId
:
string
)
:
Promise
<
this
>
{
this
.
setGameId
(
gameId
)
;
await
this
.
makeWebSocketConnection
(
`/api/games/
${
gameId
}
/debug`
,
this
.
messageHandler
)
;
return
this
;
}
/**
* Debug a player.
*
@param
gameId The ID of the game to debug.
*
@param
playerId The ID of the player to debug.
*
@param
playerSecret The secret of the player to debug.
*
@throws
if the connection cannot be established.
*
@chainable
*/
public
async
debugPlayer
(
gameId
:
string
,
playerId
:
string
,
playerSecret
:
string
)
:
Promise
<
this
>
{
this
.
setGameId
(
gameId
)
;
await
this
.
makeWebSocketConnection
(
`/api/games/
${
gameId
}
/players/
${
playerId
}
/debug?player_secret=
${
playerSecret
}
`
,
this
.
messageHandler
)
;
return
this
;
}
}
Back
|
FazBrowse Home
|
New Git URL