From f11fec7c97b9145f6bb35ba44288627a0150d433 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Sun, 2 May 2021 16:16:19 +0200 Subject: [PATCH] Diagnostic: check prosody version. --- client/settings.ts | 21 +++++++++++++++++++-- server/lib/diagnostic/prosody.ts | 20 ++++++++++++++++++++ server/lib/diagnostic/utils.ts | 6 +++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/client/settings.ts b/client/settings.ts index 8e3d3b87..ee43418a 100644 --- a/client/settings.ts +++ b/client/settings.ts @@ -1,6 +1,11 @@ +interface MessageWithLevel { + level: 'info' | 'warning' | 'error' + message: string +} + interface Result { label?: string - messages: string[] + messages: Array debug?: Array<{ title: string message: string @@ -48,7 +53,19 @@ function launchTests (): void { const messageUl = document.createElement('ul') for (let i = 0; i < result.messages.length; i++) { const messageLi = document.createElement('li') - messageLi.textContent = result.messages[i] + const message = result.messages[i] + if (typeof message === 'string') { + messageLi.textContent = message + } else { + const messageSpan = document.createElement('span') + if (message.level === 'warning') { + messageSpan.style.color = 'orange' + } else if (message.level === 'error') { + messageSpan.style.color = 'red' + } + messageSpan.textContent = message.message + messageLi.append(messageSpan) + } messageUl.append(messageLi) } li.append(messageUl) diff --git a/server/lib/diagnostic/prosody.ts b/server/lib/diagnostic/prosody.ts index badd15bd..87db55d3 100644 --- a/server/lib/diagnostic/prosody.ts +++ b/server/lib/diagnostic/prosody.ts @@ -67,6 +67,26 @@ export async function diagProsody (test: string, options: RegisterServerOptions) return result } + const versionMatches = about.match(/^Prosody\s*(\d+)\.(\d+)\.(\d+)\s*$/mi) + if (!versionMatches) { + result.messages.push({ + level: 'error', + message: 'Errors: cant find prosody version.' + }) + return result + } else { + const major = versionMatches[1] + const minor = versionMatches[2] + const patch = versionMatches[3] + result.messages.push(`Prosody version is ${major}.${minor}.${patch}`) + if (major !== '0' && minor !== '11') { + result.messages.push({ + level: parseInt(minor) < 11 ? 'error' : 'warning', + message: 'Warning: recommended Prosody version is 0.11.x' + }) + } + } + result.ok = true return result } diff --git a/server/lib/diagnostic/utils.ts b/server/lib/diagnostic/utils.ts index 333d5550..a8d7a350 100644 --- a/server/lib/diagnostic/utils.ts +++ b/server/lib/diagnostic/utils.ts @@ -1,8 +1,12 @@ type nextValue = 'backend' | 'webchat-video' | 'webchat-type' | 'prosody' | 'converse' | 'use-uri' +interface MessageWithLevel { + level: 'info' | 'warning' | 'error' + message: string +} export interface TestResult { label?: string - messages: string[] + messages: Array debug: Array<{ title: string message: string