new IframeBridgeHost()
- Description:
Host-seitige Bridge zur Steuerung eines iframes. Läuft in der Parent-Seite und sendet Messages an das iframe.
- Source:
Example
const bridge = new IframeBridgeHost(document.getElementById('gameFrame'), {
sourceId: 'learning-path-01',
forwardKeyboard: ['ArrowLeft', 'ArrowRight'],
initConfig: {
ui: { hideAi: true, hideBackBtn: true },
runtime: { level: 2 }
}
});
bridge.on('GAME:WON', (payload) => {
console.log('Gewonnen mit', payload.moves, 'Zügen');
});
Members
_boundKeyboardHandler :function|null
- Description:
Gebundener Keyboard-Listener für Cleanup
- Source:
Gebundener Keyboard-Listener für Cleanup
Type:
- function | null
_boundMessageHandler :function|null
- Description:
Gebundener Message-Listener für Cleanup
- Source:
Gebundener Message-Listener für Cleanup
Type:
- function | null
_handshakeTimeout :number
- Description:
Handshake-Timeout in ms
- Source:
Handshake-Timeout in ms
Type:
- number
_handshakeTimer :number|null
- Description:
Handshake-Timeout-Timer
- Source:
Handshake-Timeout-Timer
Type:
- number | null
_initConfig :Object|null
- Description:
Initiale Konfiguration
- Source:
Initiale Konfiguration
Type:
- Object | null
_listeners :Map.<string, Set.<function()>>
- Description:
Event-Listener
- Source:
Event-Listener
Type:
- Map.<string, Set.<function()>>
_queue :Array.<Object>
- Description:
Gepufferte Messages (vor Handshake)
- Source:
Gepufferte Messages (vor Handshake)
Type:
- Array.<Object>
acceptLegacy :boolean
- Source:
Type:
- boolean
iframe :HTMLIFrameElement
- Source:
Type:
- HTMLIFrameElement
ready :boolean
- Description:
Ist die Bridge betriebsbereit?
- Source:
Ist die Bridge betriebsbereit?
Type:
- boolean
sourceId :string
- Source:
Type:
- string
targetOrigin :string
- Description:
Für lokale Entwicklung: '*'. Production: window.location.origin.
- Source:
Für lokale Entwicklung: '*'. Production: window.location.origin.
Type:
- string
Methods
destroy()
- Description:
Räumt alle Listener und Timer auf. Muss aufgerufen werden wenn der Host nicht mehr benötigt wird.
- Source:
off(type, callbackopt) → {IframeBridgeHost}
- Description:
Entfernt einen Event-Listener.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
type |
string | Message-Typ |
|
callback |
function |
<optional> |
Spezifischer Callback (ohne: alle für diesen Typ) |
Returns:
this (für Chaining)
- Type
- IframeBridgeHost
on(type, callback) → {IframeBridgeHost}
- Description:
Registriert einen Event-Listener für einen Message-Typ. Unterstützt Wildcard-Matching via Namespace-Prefix (z.B. 'GAME:' für alle GAME-Events).
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
type |
string | Message-Typ oder Namespace-Prefix |
callback |
function | Callback(payload, fullMessage) |
Returns:
this (für Chaining)
- Type
- IframeBridgeHost
once(type, callback) → {IframeBridgeHost}
- Description:
Registriert einen einmaligen Event-Listener.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
type |
string | Message-Typ |
callback |
function | Callback(payload, fullMessage) |
Returns:
this (für Chaining)
- Type
- IframeBridgeHost
send(type, payloadopt)
- Description:
Sendet eine Message an das iframe. Wird gepuffert falls die Bridge noch nicht bereit ist.
- Source:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
type |
string | Hierarchischer Typ (z.B. 'CONFIG:UPDATE') |
||
payload |
Object |
<optional> |
{}
|
Datenobjekt |
waitForReady() → {Promise.<void>}
- Description:
Gibt ein Promise zurück, das resolved wenn die Bridge bereit ist.
- Source:
Returns:
- Type
- Promise.<void>