API reference / @jsprismarine/script-host / debugger/DebugSession / ScriptDebugSession
Class: ScriptDebugSession
Defined in: script-host/src/debugger/DebugSession.ts:121
One debugger connection over a DebuggerChannel. The world host runs handshake, then attach with the engine and context of the pack the extension picked, then calls poll between ticks until the connection closes or detach ends it. Every method blocks the calling thread for as long as the extension keeps a script stopped, which is how a stopped script stops its world's tick.
Constructors
Constructor
new ScriptDebugSession(
channel,options):ScriptDebugSession
Defined in: script-host/src/debugger/DebugSession.ts:147
Parameters
channel
options
Returns
ScriptDebugSession
Accessors
attached
Get Signature
get attached():
boolean
Defined in: script-host/src/debugger/DebugSession.ts:264
Whether the session is attached to an engine.
Returns
boolean
closed
Get Signature
get closed():
boolean
Defined in: script-host/src/debugger/DebugSession.ts:154
Whether the connection has closed or the session has detached.
Returns
boolean
Methods
attach()
attach(
engine,context?):void
Defined in: script-host/src/debugger/DebugSession.ts:222
Attaches to the picked pack's context, and handles the extension's configuration, its breakpoints and exception setting, until it sends resume. The engine runs no script until then. Only that context's scripts stop: another pack's file of the same name never does.
After detachEngine, an attach to the new engine sets the breakpoints and the exception setting the extension sent before, and returns at once: the extension configures a session only once.
Parameters
engine
The engine the pack runs in.
context?
number = DEFAULT_CONTEXT
The pack's context in the engine.
Returns
void
detach()
detach():
void
Defined in: script-host/src/debugger/DebugSession.ts:305
Ends the session and detaches from the engine. A session whose handshake passed tells the extension it has terminated, as BDS does just before it closes the connection; after a refused handshake BDS sends its error line and closes.
Returns
void
detachEngine()
detachEngine():
void
Defined in: script-host/src/debugger/DebugSession.ts:254
Detaches from the engine and tells the extension the scripts' thread has exited, while the session stays open, as BDS does around /reload. attach with the new engine starts the thread again.
Returns
void
handshake()
handshake():
string|undefined
Defined in: script-host/src/debugger/DebugSession.ts:181
Offers the protocol and the plugins, unless offer already did, and checks the extension's answer as Bedrock Dedicated Server does: the same version, the passcode when one is set, and a target among the plugins.
Returns
string | undefined
The script module UUID the extension picked, lowercase, or undefined when it picked none.
Throws
With Bedrock Dedicated Server's message when the answer is refused or never comes.
offer()
offer():
void
Defined in: script-host/src/debugger/DebugSession.ts:163
Sends the protocol event, with the plugins and whether a passcode is needed, without waiting for the answer. A host that must not block until the extension answers offers first and calls handshake once a message has arrived. Only the first call sends anything.
Returns
void
poll()
poll():
void
Defined in: script-host/src/debugger/DebugSession.ts:281
Handles what the extension has sent while no script ran, without waiting. A pause request stops the next script the engine runs at its first line. Once the connection has closed and its last messages are handled, the session closes and detaches.
Returns
void
print()
print(
message,logLevel?):void
Defined in: script-host/src/debugger/DebugSession.ts:296
Shows script output in the extension's debug console.
Parameters
message
string
logLevel?
number = LogLevel.log
Returns
void
stats()
stats(
tick,stats):void
Defined in: script-host/src/debugger/DebugSession.ts:272
Sends one tick's statistics, as BDS streams a StatEvent2 each tick to an attached extension. Nothing is sent while no engine is attached.
Parameters
tick
number
stats
readonly DebuggerStat[]
Returns
void