MCPcopy Index your code
hub / github.com/4ian/GDevelop / receiveLobbiesMessage

Function receiveLobbiesMessage

Extensions/Multiplayer/multiplayertools.ts:1517–1565  ·  view source on GitHub ↗
(
      runtimeScene: gdjs.RuntimeScene,
      event: MessageEvent,
      { checkOrigin }: { checkOrigin: boolean }
    )

Source from the content-addressed store, hash-verified

1515 * react accordingly.
1516 */
1517 const receiveLobbiesMessage = function (
1518 runtimeScene: gdjs.RuntimeScene,
1519 event: MessageEvent,
1520 { checkOrigin }: { checkOrigin: boolean }
1521 ) {
1522 const allowedOrigins = ['https://gd.games', 'http://localhost:4000'];
1523
1524 // Check origin of message.
1525 if (checkOrigin && !allowedOrigins.includes(event.origin)) {
1526 // Wrong origin. Return silently.
1527 return;
1528 }
1529 // Check that message is not malformed.
1530 if (!event.data.id) {
1531 throw new Error('Malformed message');
1532 }
1533
1534 // Handle message.
1535 switch (event.data.id) {
1536 case 'lobbiesListenerReady': {
1537 sendSessionInformation(runtimeScene);
1538 break;
1539 }
1540 case 'joinLobby': {
1541 if (!event.data.lobbyId) {
1542 throw new Error('Malformed message.');
1543 }
1544 _actionAfterJoiningLobby = null;
1545 handleJoinLobbyEvent(runtimeScene, event.data.lobbyId);
1546 break;
1547 }
1548 case 'startGameCountdown': {
1549 handleStartGameCountdownMessage();
1550 break;
1551 }
1552 case 'startGame': {
1553 handleStartGameMessage();
1554 break;
1555 }
1556 case 'leaveLobby': {
1557 handleLeaveLobbyEvent();
1558 break;
1559 }
1560 case 'joinGame': {
1561 handleJoinGameMessage();
1562 break;
1563 }
1564 }
1565 };
1566
1567 /**
1568 * Handle any error that can occur as part of displaying the lobbies.

Callers 1

openLobbiesIframeFunction · 0.85

Calls 6

sendSessionInformationFunction · 0.85
handleJoinLobbyEventFunction · 0.85
handleStartGameMessageFunction · 0.85
handleLeaveLobbyEventFunction · 0.85
handleJoinGameMessageFunction · 0.85

Tested by

no test coverage detected