diff --git a/src/extensions/scratch3_mesh_v2/gql-operations.js b/src/extensions/scratch3_mesh_v2/gql-operations.js index 8c82f7ec0d..6287cbe9e4 100644 --- a/src/extensions/scratch3_mesh_v2/gql-operations.js +++ b/src/extensions/scratch3_mesh_v2/gql-operations.js @@ -42,6 +42,7 @@ const JOIN_GROUP = gql` name groupId domain + expiresAt heartbeatIntervalSeconds } } diff --git a/src/extensions/scratch3_mesh_v2/index.js b/src/extensions/scratch3_mesh_v2/index.js index 6d6d5494b3..5f02c718ad 100644 --- a/src/extensions/scratch3_mesh_v2/index.js +++ b/src/extensions/scratch3_mesh_v2/index.js @@ -299,6 +299,14 @@ class Scratch3MeshV2Blocks { return !!(this.meshService && this.meshService.groupId); } + formatExpiresAt (expiresAt) { + if (!expiresAt) return ''; + const date = new Date(expiresAt); + const h = String(date.getHours()).padStart(2, '0'); + const m = String(date.getMinutes()).padStart(2, '0'); + return `${h}:${m}`; + } + /* istanbul ignore next */ connectedMessage () { if (this.meshService && this.meshService.groupId) { @@ -326,6 +334,38 @@ class Scratch3MeshV2Blocks { }); } + /* istanbul ignore next */ + menuMessage () { + if (this.meshService && this.meshService.groupId) { + const meshIdLabel = this.makeMeshIdLabel(this.meshService.groupName); + const expiresAt = this.formatExpiresAt(this.meshService.expiresAt); + + if (this.meshService.isHost) { + return formatMessage({ + id: 'mesh.registeredHostMenu', + default: '{ MESH_ID } ({ EXPIRES_AT })', + description: 'concise label for registered Host Mesh in menu bar' + }, { + MESH_ID: meshIdLabel, + EXPIRES_AT: expiresAt + }); + } + return formatMessage({ + id: 'mesh.joinedMeshMenu', + default: '{ MESH_ID } ({ EXPIRES_AT })', + description: 'concise label for joined Mesh in menu bar' + }, { + MESH_ID: meshIdLabel, + EXPIRES_AT: expiresAt + }); + } + return formatMessage({ + id: 'mesh.notConnectedMenu', + default: 'Not connected', + description: 'concise label for not connected in menu bar' + }); + } + // HOC logic /* istanbul ignore next */ setOpcodeFunctionHOC () {