From 56e74e08771c9050ffcb9993a271759e35ca9c01 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Sat, 12 Jun 2021 01:16:57 +0200 Subject: [PATCH 01/21] Initialize prosody-list-rooms button. --- assets/style.css | 6 ++- client/@types/peertube.d.ts | 1 + client/admin-plugin-client-plugin.ts | 56 +++++++++++++++++++++++++++- server/lib/routers/settings.ts | 33 ++++++++++++++++ server/lib/settings.ts | 7 ++++ shared/lib/types.ts | 20 +++++++++- 6 files changed, 119 insertions(+), 4 deletions(-) diff --git a/assets/style.css b/assets/style.css index e5daefed..be88360a 100644 --- a/assets/style.css +++ b/assets/style.css @@ -53,4 +53,8 @@ .peertube-plugin-livechat-warning { color: orange; -} \ No newline at end of file +} + +.peertube-plugin-livechat-error { + color: red; +} diff --git a/client/@types/peertube.d.ts b/client/@types/peertube.d.ts index 3121a03d..0d0772fc 100644 --- a/client/@types/peertube.d.ts +++ b/client/@types/peertube.d.ts @@ -11,6 +11,7 @@ interface RegisterClientHelpers { // NB: getBaseRouterRoute will come with Peertube > 3.2.1 (3.3.0?) getBaseRouterRoute?: () => string isLoggedIn: () => boolean + getAuthHeader: () => { 'Authorization': string } | undefined getSettings: () => Promise<{ [ name: string ]: string }> notifier: { info: (text: string, title?: string, timeout?: number) => void diff --git a/client/admin-plugin-client-plugin.ts b/client/admin-plugin-client-plugin.ts index 163b5c0d..5391cc45 100644 --- a/client/admin-plugin-client-plugin.ts +++ b/client/admin-plugin-client-plugin.ts @@ -1,4 +1,4 @@ -import type { ChatType } from 'shared/lib/types' +import type { ChatType, ProsodyListRoomsResult } from 'shared/lib/types' interface ActionPluginSettingsParams { npmName: string @@ -31,6 +31,59 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re diagButton.setAttribute('href', getBaseRoute() + '/settings/diagnostic') diagButton.setAttribute('target', '_blank') }) + console.log('[peertube-plugin-livechat] Initializing prosody-list-rooms button') + const listRoomsButtons: NodeListOf = + document.querySelectorAll('.peertube-plugin-livechat-prosody-list-rooms') + listRoomsButtons.forEach(listRoomsButton => { + if (listRoomsButton.classList.contains('btn')) { return } + listRoomsButton.classList.add('btn') + listRoomsButton.classList.add('action-button') + listRoomsButton.classList.add('orange-button') + listRoomsButton.onclick = async (): Promise => { + console.log('[peertube-plugin-livechat] Opening the room list...') + // TODO: use showModal (seems buggy with Peertube 3.2.1) + + try { + document.querySelectorAll('.peertube-plugin-livechat-prosody-list-rooms-content') + .forEach(dom => dom.remove()) + const container = document.createElement('div') + container.classList.add('peertube-plugin-livechat-prosody-list-rooms-content') + container.textContent = '...' + listRoomsButton.after(container) + + const response = await fetch(getBaseRoute() + '/settings/prosody-list-rooms', { + method: 'GET', + headers: peertubeHelpers.getAuthHeader() + }) + if (!response.ok) { + throw new Error('Response is not ok') + } + const json: ProsodyListRoomsResult = await response.json() + if (!json.ok) { + container.textContent = json.error + container.classList.add('peertube-plugin-livechat-error') + } else { + container.textContent = '' + const table = document.createElement('table') + container.append(table) + json.rooms.forEach(room => { + const lineEl = document.createElement('tr') + const nameEl = document.createElement('td') + const aEl = document.createElement('a') + aEl.textContent = room.name + aEl.href = room.href + aEl.target = '_blank' + nameEl.append(aEl) + lineEl.append(nameEl) + table.append(lineEl) + }) + } + } catch (error) { + console.error(error) + peertubeHelpers.notifier.error('Room list failed') + } + } + }) } }) registerSettingsScript({ @@ -41,6 +94,7 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re return options.formValues['chat-type'] !== ('disabled' as ChatType) case 'prosody-port': case 'chat-type-help-builtin-prosody': + case 'prosody-list-rooms': return options.formValues['chat-type'] !== ('builtin-prosody' as ChatType) case 'chat-server': case 'chat-room': diff --git a/server/lib/routers/settings.ts b/server/lib/routers/settings.ts index a2510c2c..88930655 100644 --- a/server/lib/routers/settings.ts +++ b/server/lib/routers/settings.ts @@ -1,4 +1,5 @@ import type { Router, Request, Response, NextFunction } from 'express' +import type { ChatType, ProsodyListRoomsResult } from '../../../shared/lib/types' import { diag } from '../diagnostic' import { getBaseStaticRoute, isUserAdmin } from '../helpers' import { asyncMiddleware } from '../middlewares/async' @@ -39,6 +40,38 @@ async function initSettingsRouter (options: RegisterServerOptions): Promise { + if (!res.locals.authenticated) { + res.sendStatus(403) + return + } + if (!await isUserAdmin(options, res)) { + res.sendStatus(403) + return + } + + const chatType: ChatType = await options.settingsManager.getSetting('chat-type') as ChatType + if (chatType !== 'builtin-prosody') { + const message = 'Please save the settings first.' // TODO: translate? + res.status(200) + const r: ProsodyListRoomsResult = { + ok: false, + error: message + } + res.json(r) + return + } + + res.status(200) + const r: ProsodyListRoomsResult = { + ok: true, + rooms: [] // TODO: get room list from Prosody + } + res.json(r) + } + )) + return router } diff --git a/server/lib/settings.ts b/server/lib/settings.ts index d4ed53fc..29ba67f1 100644 --- a/server/lib/settings.ts +++ b/server/lib/settings.ts @@ -91,6 +91,13 @@ Please read the private: true }) + registerSetting({ + name: 'prosody-list-rooms', + label: 'List existing rooms', + type: 'html', + descriptionHTML: 'List rooms', + private: true + }) registerSetting({ name: 'prosody-port', label: 'Prosody port', diff --git a/shared/lib/types.ts b/shared/lib/types.ts index f9892324..8fefdd23 100644 --- a/shared/lib/types.ts +++ b/shared/lib/types.ts @@ -1,5 +1,21 @@ type ChatType = 'disabled' | 'builtin-prosody' | 'builtin-converse' | 'external-uri' -export { - ChatType +interface ProsodyListRoomsResultError { + ok: false + error: string +} + +interface ProsodyListRoomsResultSuccess { + ok: true + rooms: Array<{ + name: string + href: string + }> +} + +type ProsodyListRoomsResult = ProsodyListRoomsResultError | ProsodyListRoomsResultSuccess + +export { + ChatType, + ProsodyListRoomsResult } From 00bf5bd96b38745989be8890fc29255378b28032 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Sat, 12 Jun 2021 02:25:56 +0200 Subject: [PATCH 02/21] Fix markdown. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f92545c7..bf55c4c8 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ If you have any question, or if you want to talk about this plugin, you can join ## Settings For the chat mode, and related settings, please refer to the corresponding documentation: + * [Prosody server controlled by Peertube (recommended)](documentation/prosody.md). **This is the recommanded setup**. * [Connect to an existing XMPP server with ConverseJS](documentation/conversejs.md) * [Use an external web chat tool](documentation/external.md) From 30d70e033e574046d081f03aaab7cd52f75b81c2 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Sat, 12 Jun 2021 03:52:45 +0200 Subject: [PATCH 03/21] Retrieving list rooms from prosody. --- CHANGELOG.md | 4 +- assets/style.css | 4 + client/admin-plugin-client-plugin.ts | 24 +- documentation/prosody.md | 6 + package-lock.json | 243 +++++++++++++++++- package.json | 2 + .../README.md | 5 + .../mod_http_peertubelivechat_list_rooms.lua | 56 ++++ server/lib/prosody/config.ts | 2 + server/lib/prosody/config/content.ts | 5 + server/lib/routers/settings.ts | 33 --- server/lib/routers/webchat.ts | 57 +++- shared/lib/types.ts | 5 +- 13 files changed, 397 insertions(+), 49 deletions(-) create mode 100644 prosody-modules/mod_http_peertubelivechat_list_rooms/README.md create mode 100644 prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a821705..c42cf75c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ * New simpler settings screen. * New field in live video form, to activate the webchat per video. There is a setting for enabling this new feature. +* When using the builtin prosody, there is a button to list existing chatrooms in the settings screen. ### Changes @@ -18,9 +19,6 @@ * New settings * By default, the «activate chat for all lives» is disabled (now that we can enable the webchat per video) -### Fixes - -* ... ## v2.3.1 diff --git a/assets/style.css b/assets/style.css index be88360a..e3219162 100644 --- a/assets/style.css +++ b/assets/style.css @@ -58,3 +58,7 @@ .peertube-plugin-livechat-error { color: red; } + +table.peertube-plugin-livechat-prosody-list-rooms { + border: 1px solid black; +} diff --git a/client/admin-plugin-client-plugin.ts b/client/admin-plugin-client-plugin.ts index 5391cc45..604c4fb8 100644 --- a/client/admin-plugin-client-plugin.ts +++ b/client/admin-plugin-client-plugin.ts @@ -51,7 +51,7 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re container.textContent = '...' listRoomsButton.after(container) - const response = await fetch(getBaseRoute() + '/settings/prosody-list-rooms', { + const response = await fetch(getBaseRoute() + '/webchat/prosody-list-rooms', { method: 'GET', headers: peertubeHelpers.getAuthHeader() }) @@ -63,18 +63,36 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re container.textContent = json.error container.classList.add('peertube-plugin-livechat-error') } else { + const rooms = json.rooms.sort((a, b) => a.name.localeCompare(b.name)) + container.textContent = '' const table = document.createElement('table') + table.classList.add('peertube-plugin-livechat-prosody-list-rooms') container.append(table) - json.rooms.forEach(room => { + // TODO: translate labels. + const titleLineEl = document.createElement('tr') + const titleNameEl = document.createElement('th') + titleNameEl.textContent = 'Name' + const titleDescriptionEl = document.createElement('th') + titleDescriptionEl.textContent = 'Description' + titleLineEl.append(titleNameEl) + titleLineEl.append(titleDescriptionEl) + table.append(titleLineEl) + rooms.forEach(room => { + // TODO: get some informations about the video. + const uuid = room.localpart + const href = getBaseRoute() + '/webchat/room/' + encodeURIComponent(uuid) const lineEl = document.createElement('tr') const nameEl = document.createElement('td') const aEl = document.createElement('a') aEl.textContent = room.name - aEl.href = room.href + aEl.href = href aEl.target = '_blank' + const descriptionEl = document.createElement('td') + descriptionEl.textContent = room.description nameEl.append(aEl) lineEl.append(nameEl) + lineEl.append(descriptionEl) table.append(lineEl) }) } diff --git a/documentation/prosody.md b/documentation/prosody.md index 10dc4656..b6433950 100644 --- a/documentation/prosody.md +++ b/documentation/prosody.md @@ -61,6 +61,12 @@ This is the port that the Prosody server will use. By default it is set to 52800 These settings are common with other chat modes. Here is the documentation: [common settings](./common.md). +## Moderation + +You can list all existing chatrooms: in the plugin settings screen, there is a button «List rooms». + +You can delete old rooms: join the room, and use the menu on the top to destroy the room. + ## Notes All instance moderators and admins will be owner for created chat rooms. diff --git a/package-lock.json b/package-lock.json index e549c955..61f77d30 100644 --- a/package-lock.json +++ b/package-lock.json @@ -129,6 +129,19 @@ "webpack-sources": "^1.0.0" } }, + "@sindresorhus/is": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.0.1.tgz", + "integrity": "sha512-Qm9hBEBu18wt1PO2flE7LPb30BHMQt1eQgbV76YntdNk73XZGpn3izvGTYxbGgzXKgbCjiia0uxTd3aTNQrY/g==" + }, + "@szmarczak/http-timer": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.5.tgz", + "integrity": "sha512-PyRA9sm1Yayuj5OIoJ1hGt2YISX45w9WcFbh6ddT0Z/0yaFxOtGLInr4jUfU1EAFVs0Yfyfev4RNwBlUaHdlDQ==", + "requires": { + "defer-to-connect": "^2.0.0" + } + }, "@trysound/sax": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@trysound/sax/-/sax-0.1.1.tgz", @@ -157,6 +170,17 @@ "@types/node": "*" } }, + "@types/cacheable-request": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.1.tgz", + "integrity": "sha512-ykFq2zmBGOCbpIXtoVbz4SKY5QriWPh3AjyU4G74RYbtt5yOc5OfaY75ftjg7mikMOla1CTGpX3lLbuJh8DTrQ==", + "requires": { + "@types/http-cache-semantics": "*", + "@types/keyv": "*", + "@types/node": "*", + "@types/responselike": "*" + } + }, "@types/connect": { "version": "3.4.34", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.34.tgz", @@ -198,6 +222,22 @@ "@types/range-parser": "*" } }, + "@types/got": { + "version": "9.6.11", + "resolved": "https://registry.npmjs.org/@types/got/-/got-9.6.11.tgz", + "integrity": "sha512-dr3IiDNg5TDesGyuwTrN77E1Cd7DCdmCFtEfSGqr83jMMtcwhf/SGPbN2goY4JUWQfvxwY56+e5tjfi+oXeSdA==", + "dev": true, + "requires": { + "@types/node": "*", + "@types/tough-cookie": "*", + "form-data": "^2.5.0" + } + }, + "@types/http-cache-semantics": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz", + "integrity": "sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A==" + }, "@types/json-schema": { "version": "7.0.7", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.7.tgz", @@ -210,6 +250,14 @@ "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=", "dev": true }, + "@types/keyv": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.1.tgz", + "integrity": "sha512-MPtoySlAZQ37VoLaPcTHCu1RWJ4llDkULYZIzOYxlhxBqYPB0RsRlmMU0R6tahtFe27mIdkHV+551ZWV4PLmVw==", + "requires": { + "@types/node": "*" + } + }, "@types/mime": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz", @@ -219,8 +267,7 @@ "@types/node": { "version": "14.14.37", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.37.tgz", - "integrity": "sha512-XYmBiy+ohOR4Lh5jE379fV2IU+6Jn4g5qASinhitfyO71b/sCo6MKsMLF5tc7Zf2CE8hViVQyYSobJNke8OvUw==", - "dev": true + "integrity": "sha512-XYmBiy+ohOR4Lh5jE379fV2IU+6Jn4g5qASinhitfyO71b/sCo6MKsMLF5tc7Zf2CE8hViVQyYSobJNke8OvUw==" }, "@types/qs": { "version": "6.9.6", @@ -234,6 +281,14 @@ "integrity": "sha512-ewFXqrQHlFsgc09MK5jP5iR7vumV/BYayNC6PgJO2LPe8vrnNFyjQjSppfEngITi0qvfKtzFvgKymGheFM9UOA==", "dev": true }, + "@types/responselike": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz", + "integrity": "sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==", + "requires": { + "@types/node": "*" + } + }, "@types/serve-static": { "version": "1.13.9", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.9.tgz", @@ -244,6 +299,12 @@ "@types/node": "*" } }, + "@types/tough-cookie": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/@types/tough-cookie/-/tough-cookie-4.0.0.tgz", + "integrity": "sha512-I99sngh224D0M7XgW1s120zxCt3VYQ3IQsuw3P3jbq5GG4yc79+ZjyKznyOGIQrflfylLgcfekeZW/vk0yng6A==", + "dev": true + }, "@types/winston": { "version": "2.4.4", "resolved": "https://registry.npmjs.org/@types/winston/-/winston-2.4.4.tgz", @@ -851,6 +912,12 @@ "dev": true, "optional": true }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", + "dev": true + }, "atob": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", @@ -1192,6 +1259,35 @@ "unset-value": "^1.0.0" } }, + "cacheable-lookup": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz", + "integrity": "sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA==" + }, + "cacheable-request": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.2.tgz", + "integrity": "sha512-pouW8/FmiPQbuGpkXQ9BAPv/Mo5xDGANgSNXzTzJ8DrKGuXOssM4wIQRjfanNRh3Yu5cfYPvcorqbhg2KIJtew==", + "requires": { + "clone-response": "^1.0.2", + "get-stream": "^5.1.0", + "http-cache-semantics": "^4.0.0", + "keyv": "^4.0.0", + "lowercase-keys": "^2.0.0", + "normalize-url": "^6.0.1", + "responselike": "^2.0.0" + }, + "dependencies": { + "get-stream": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", + "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", + "requires": { + "pump": "^3.0.0" + } + } + } + }, "call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -1356,6 +1452,14 @@ "wrap-ansi": "^5.1.0" } }, + "clone-response": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", + "integrity": "sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=", + "requires": { + "mimic-response": "^1.0.0" + } + }, "collection-visit": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz", @@ -1417,6 +1521,15 @@ "text-hex": "1.0.x" } }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", @@ -1649,12 +1762,32 @@ "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=", "dev": true }, + "decompress-response": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", + "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "requires": { + "mimic-response": "^3.1.0" + }, + "dependencies": { + "mimic-response": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", + "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==" + } + } + }, "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=", "dev": true }, + "defer-to-connect": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.1.tgz", + "integrity": "sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==" + }, "define-properties": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", @@ -1705,6 +1838,12 @@ } } }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "dev": true + }, "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", @@ -1868,7 +2007,6 @@ "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", - "dev": true, "requires": { "once": "^1.4.0" } @@ -2869,6 +3007,17 @@ "integrity": "sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=", "dev": true }, + "form-data": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.5.1.tgz", + "integrity": "sha512-m21N3WOmEEURgk6B9GLOE4RuWOFf28Lhh9qGYeNlGq4VDXUlJy2th2slBNU8Gp8EzloYZOibZJ7t5ecIrFSjVA==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + } + }, "fragment-cache": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz", @@ -3046,6 +3195,24 @@ } } }, + "got": { + "version": "11.8.2", + "resolved": "https://registry.npmjs.org/got/-/got-11.8.2.tgz", + "integrity": "sha512-D0QywKgIe30ODs+fm8wMZiAcZjypcCodPNuMz5H9Mny7RJ+IjJ10BdmGW7OM7fHXP+O7r6ZwapQ/YQmMSvB0UQ==", + "requires": { + "@sindresorhus/is": "^4.0.0", + "@szmarczak/http-timer": "^4.0.5", + "@types/cacheable-request": "^6.0.1", + "@types/responselike": "^1.0.0", + "cacheable-lookup": "^5.0.3", + "cacheable-request": "^7.0.1", + "decompress-response": "^6.0.0", + "http2-wrapper": "^1.0.0-beta.5.2", + "lowercase-keys": "^2.0.0", + "p-cancelable": "^2.0.0", + "responselike": "^2.0.0" + } + }, "graceful-fs": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.3.tgz", @@ -3151,6 +3318,11 @@ "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", "dev": true }, + "http-cache-semantics": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", + "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==" + }, "http-errors": { "version": "1.7.3", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.3.tgz", @@ -3163,6 +3335,15 @@ "toidentifier": "1.0.0" } }, + "http2-wrapper": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.3.tgz", + "integrity": "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg==", + "requires": { + "quick-lru": "^5.1.1", + "resolve-alpn": "^1.0.0" + } + }, "https-browserify": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/https-browserify/-/https-browserify-1.0.0.tgz", @@ -3509,6 +3690,11 @@ "esprima": "^4.0.0" } }, + "json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==" + }, "json-parse-better-errors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", @@ -3536,6 +3722,14 @@ "minimist": "^1.2.0" } }, + "keyv": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.0.3.tgz", + "integrity": "sha512-zdGa2TOpSZPq5mU6iowDARnMBZgtCqJ11dJROFi6tg6kTn4nuUdU09lFyLFSaHrWqpIJ+EBq4E8/Dc0Vx5vLdA==", + "requires": { + "json-buffer": "3.0.1" + } + }, "kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", @@ -3646,6 +3840,11 @@ } } }, + "lowercase-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", + "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==" + }, "lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", @@ -3800,6 +3999,11 @@ "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", "dev": true }, + "mimic-response": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", + "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==" + }, "minimalistic-assert": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", @@ -3989,6 +4193,11 @@ "dev": true, "optional": true }, + "normalize-url": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.0.1.tgz", + "integrity": "sha512-VU4pzAuh7Kip71XEmO9aNREYAdMHFGTVj/i+CaTImS8x0i1d3jUZkXhqluy/PRgjPLMgsLQulYY3PJ/aSbSjpQ==" + }, "npm-run-all": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/npm-run-all/-/npm-run-all-4.1.5.tgz", @@ -4177,7 +4386,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "requires": { "wrappy": "1" } @@ -4222,6 +4430,11 @@ "mem": "^4.0.0" } }, + "p-cancelable": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz", + "integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==" + }, "p-defer": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz", @@ -4479,7 +4692,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dev": true, "requires": { "end-of-stream": "^1.1.0", "once": "^1.3.1" @@ -4537,6 +4749,11 @@ "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", "dev": true }, + "quick-lru": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz", + "integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==" + }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -4721,6 +4938,11 @@ "path-parse": "^1.0.6" } }, + "resolve-alpn": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.1.2.tgz", + "integrity": "sha512-8OyfzhAtA32LVUsJSke3auIyINcwdh5l3cvYKdKO0nvsYSKuiLfTM5i78PJswFPT8y6cPW+L1v6/hE95chcpDA==" + }, "resolve-cwd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-2.0.0.tgz", @@ -4765,6 +4987,14 @@ "integrity": "sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo=", "dev": true }, + "responselike": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.0.tgz", + "integrity": "sha512-xH48u3FTB9VsZw7R+vvgaKeLKzT6jOogbQhEe/jewwnZgzPcnyWui2Av6JpoYZF/91uueC+lqhWqeURw5/qhCw==", + "requires": { + "lowercase-keys": "^2.0.0" + } + }, "ret": { "version": "0.1.15", "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", @@ -6348,8 +6578,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "xtend": { "version": "4.0.2", diff --git a/package.json b/package.json index 8b163f98..5cbfce8c 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "body-parser": "^1.19.0", "decache": "^4.6.0", "express-http-proxy": "^1.6.2", + "got": "^11.8.2", "log-rotate": "^0.2.8" }, "devDependencies": { @@ -40,6 +41,7 @@ "@types/async": "^3.2.6", "@types/express": "^4.17.11", "@types/express-http-proxy": "^1.6.1", + "@types/got": "^9.6.11", "@types/node": "^14.14.37", "@types/winston": "^2.4.4", "@typescript-eslint/eslint-plugin": "^4.21.0", diff --git a/prosody-modules/mod_http_peertubelivechat_list_rooms/README.md b/prosody-modules/mod_http_peertubelivechat_list_rooms/README.md new file mode 100644 index 00000000..6c4fe736 --- /dev/null +++ b/prosody-modules/mod_http_peertubelivechat_list_rooms/README.md @@ -0,0 +1,5 @@ +# mod_http_peertubelivechat_list_rooms + +This module is a custom module that allows Peertube server to list chat rooms. + +This module is part of peertube-plugin-livechat, and is under the same LICENSE. diff --git a/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua b/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua new file mode 100644 index 00000000..c7bff171 --- /dev/null +++ b/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua @@ -0,0 +1,56 @@ +local json = require "util.json"; +local jid_split = require"util.jid".split; +local array = require "util.array"; + +local mod_muc = module:depends"muc"; +local all_rooms = rawget(mod_muc, "all_rooms") + +module:depends"http"; + +function check_auth(routes) + local function check_request_auth(event) + local apikey = module:get_option_string("peertubelivechat_list_rooms_apikey", "") + if apikey == "" then + return false, 500; + end + if event.request.headers.authorization ~= "Bearer " .. apikey then + return false, 401; + end + return true; + end + + for route, handler in pairs(routes) do + routes[route] = function (event, ...) + local permit, code = check_request_auth(event); + if not permit then + return code; + end + return handler(event, ...); + end; + end + return routes; +end + +local function list_rooms(event) + local request, response = event.request, event.response; + local rooms_json = array(); + for room in all_rooms() do + local localpart = jid_split(room.jid); + rooms_json:push({ + jid = room.jid; + localpart = localpart; + name = room:get_name() or localpart; + lang = room.get_language and room:get_language(); + description = room:get_description(); + }) + end + + event.response.headers["Content-Type"] = "application/json"; + return json.encode_array(rooms_json); +end + +module:provides("http", { + route = check_auth { + ["GET /list-rooms"] = list_rooms; + }; +}); diff --git a/server/lib/prosody/config.ts b/server/lib/prosody/config.ts index 75c96bf6..33c15a00 100644 --- a/server/lib/prosody/config.ts +++ b/server/lib/prosody/config.ts @@ -96,6 +96,8 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise { - if (!res.locals.authenticated) { - res.sendStatus(403) - return - } - if (!await isUserAdmin(options, res)) { - res.sendStatus(403) - return - } - - const chatType: ChatType = await options.settingsManager.getSetting('chat-type') as ChatType - if (chatType !== 'builtin-prosody') { - const message = 'Please save the settings first.' // TODO: translate? - res.status(200) - const r: ProsodyListRoomsResult = { - ok: false, - error: message - } - res.json(r) - return - } - - res.status(200) - const r: ProsodyListRoomsResult = { - ok: true, - rooms: [] // TODO: get room list from Prosody - } - res.json(r) - } - )) - return router } diff --git a/server/lib/routers/webchat.ts b/server/lib/routers/webchat.ts index 636d04e9..584099af 100644 --- a/server/lib/routers/webchat.ts +++ b/server/lib/routers/webchat.ts @@ -1,16 +1,19 @@ import type { Router, RequestHandler, Request, Response, NextFunction } from 'express' import type { ProxyOptions } from 'express-http-proxy' -import type { ChatType } from '../../../shared/lib/types' -import { getBaseRouterRoute, getBaseStaticRoute } from '../helpers' +import type { ChatType, ProsodyListRoomsResult } from '../../../shared/lib/types' +import { getBaseRouterRoute, getBaseStaticRoute, isUserAdmin } from '../helpers' import { asyncMiddleware } from '../middlewares/async' import { getProsodyDomain } from '../prosody/config/domain' +import { getAPIKey } from '../apikey' import * as path from 'path' const bodyParser = require('body-parser') +const got = require('got') const fs = require('fs').promises const proxy = require('express-http-proxy') let httpBindRoute: RequestHandler +let prosodyPort: string | undefined async function initWebchatRouter (options: RegisterServerOptions): Promise { const { @@ -97,6 +100,54 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise { + if (!res.locals.authenticated) { + res.sendStatus(403) + return + } + if (!await isUserAdmin(options, res)) { + res.sendStatus(403) + return + } + + const chatType: ChatType = await options.settingsManager.getSetting('chat-type') as ChatType + if (chatType !== 'builtin-prosody') { + const message = 'Please save the settings first.' // TODO: translate? + res.status(200) + const r: ProsodyListRoomsResult = { + ok: false, + error: message + } + res.json(r) + return + } + + if (!prosodyPort) { + throw new Error('It seems that prosody is not binded... Cant list rooms.') + } + // FIXME: can the api be on http://localhost instead of http://room.localhost? + const apiUrl = `http://room.localhost:${prosodyPort}/peertubelivechat_list_rooms/list-rooms` + peertubeHelpers.logger.debug('Calling list rooms API on url: ' + apiUrl) + const rooms = await got(apiUrl, { + method: 'GET', + headers: { + authorization: 'Bearer ' + await getAPIKey(options) + }, + responseType: 'json', + resolveBodyOnly: true + }) + + res.status(200) + const r: ProsodyListRoomsResult = { + ok: true, + rooms: rooms + } + res.json(r) + } + )) + return router } @@ -108,6 +159,7 @@ function changeHttpBindRoute ({ peertubeHelpers }: RegisterServerOptions, port: port = null } if (port === null) { + prosodyPort = undefined httpBindRoute = (_req: Request, res: Response, _next: NextFunction) => { res.status(404) res.send('Not found') @@ -122,6 +174,7 @@ function changeHttpBindRoute ({ peertubeHelpers }: RegisterServerOptions, port: parseReqBody: true // Note that setting this to false overrides reqAsBuffer and reqBodyEncoding below. // FIXME: should we remove cookies? } + prosodyPort = port httpBindRoute = proxy('http://localhost:' + port, options) } } diff --git a/shared/lib/types.ts b/shared/lib/types.ts index 8fefdd23..9e00f40a 100644 --- a/shared/lib/types.ts +++ b/shared/lib/types.ts @@ -8,8 +8,11 @@ interface ProsodyListRoomsResultError { interface ProsodyListRoomsResultSuccess { ok: true rooms: Array<{ + jid: string + localpart: string name: string - href: string + lang: string + description: string }> } From 25e41338c8dcfbadb54b23458f7de9967022487f Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 22 Jun 2021 13:42:34 +0200 Subject: [PATCH 04/21] Initializing v3.2.0. --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 665fcbe1..dcc4f09d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v3.2.0 + +... + ## v3.1.0 ### Features diff --git a/package.json b/package.json index 46c243e3..7fb12978 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "peertube-plugin-livechat", "description": "PeerTube plugin livechat", - "version": "3.1.0", + "version": "3.2.0", "author": "John Livingston", "bugs": "https://github.com/JohnXLivingston/peertube-plugin-livechat/issues", "clientScripts": [ From 9a65da50e571da4cbb7185a1dc00fc258904f7bf Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 22 Jun 2021 14:57:57 +0200 Subject: [PATCH 05/21] FIXME. --- server/lib/routers/webchat.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/lib/routers/webchat.ts b/server/lib/routers/webchat.ts index 584099af..ad136bb7 100644 --- a/server/lib/routers/webchat.ts +++ b/server/lib/routers/webchat.ts @@ -128,6 +128,8 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise Date: Tue, 6 Jul 2021 11:26:37 +0200 Subject: [PATCH 06/21] Fix muc component http_host. --- server/lib/prosody/config/content.ts | 2 ++ server/lib/routers/webchat.ts | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/server/lib/prosody/config/content.ts b/server/lib/prosody/config/content.ts index e663f124..43ec98de 100644 --- a/server/lib/prosody/config/content.ts +++ b/server/lib/prosody/config/content.ts @@ -190,6 +190,8 @@ class ProsodyConfigContent { this.anon.set('http_external_url', 'http://' + prosodyDomain) this.muc.set('restrict_room_creation', 'local') + this.muc.set('http_host', prosodyDomain) + this.muc.set('http_external_url', 'http://' + prosodyDomain) if (this.authenticated) { this.authenticated.set('trusted_proxies', ['127.0.0.1', '::1']) diff --git a/server/lib/routers/webchat.ts b/server/lib/routers/webchat.ts index ad136bb7..8b67417d 100644 --- a/server/lib/routers/webchat.ts +++ b/server/lib/routers/webchat.ts @@ -127,10 +127,7 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise Date: Tue, 13 Jul 2021 17:40:29 +0200 Subject: [PATCH 07/21] Add localhost c2s connections --- client/admin-plugin-client-plugin.ts | 4 ++++ documentation/prosody.md | 16 ++++++++++++++ server/lib/prosody/config.ts | 7 +++++- server/lib/prosody/config/content.ts | 8 +++++-- server/lib/settings.ts | 32 ++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) diff --git a/client/admin-plugin-client-plugin.ts b/client/admin-plugin-client-plugin.ts index c86b7eeb..d9f34a70 100644 --- a/client/admin-plugin-client-plugin.ts +++ b/client/admin-plugin-client-plugin.ts @@ -42,7 +42,11 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re case 'prosody-port': case 'prosody-peertube-uri': case 'chat-type-help-builtin-prosody': + case 'prosody-advanced': + case 'prosody-c2s': return options.formValues['chat-type'] !== ('builtin-prosody' as ChatType) + case 'prosody-c2s-port': + return options.formValues['chat-type'] !== ('builtin-prosody' as ChatType) || options.formValues['prosody-c2s'] === false case 'chat-server': case 'chat-room': case 'chat-bosh-uri': diff --git a/documentation/prosody.md b/documentation/prosody.md index 10dc4656..18277ed0 100644 --- a/documentation/prosody.md +++ b/documentation/prosody.md @@ -68,3 +68,19 @@ If the video is local (not from a remote Peertube), the video owner will be admi You can use [ConverseJS moderation commands](https://conversejs.org/docs/html/features.html#moderating-chatrooms) to moderate the room. When you open the chat room in full screen, there will also be a menu with dedicated commands on the top right. + + +### Prosody advanced settings + +#### Enable client to server connections + +This setting enable XMPP clients to connect to the builtin Prosody server. +This option alone **only allows connections from localhost clients**. + +As example, this option can allow an instance of Matterbridge (once it could use anonymous login) *on the same machine* to bridge your chat with another services like a Matrix room. + +##### Prosody client to server port + +The port that will be used by the c2s module of the builtin Prosody server. +XMPP clients shall use this port to connect. +Change it if this port is already in use on your server. \ No newline at end of file diff --git a/server/lib/prosody/config.ts b/server/lib/prosody/config.ts index cf37a8a0..96d60bdf 100644 --- a/server/lib/prosody/config.ts +++ b/server/lib/prosody/config.ts @@ -77,6 +77,11 @@ async function getProsodyConfig (options: RegisterServerOptions): PromiseProsody advanced settings' + }) + + registerSetting({ + name: 'prosody-c2s', + label: 'Enable client to server connections', + type: 'input-checkbox', + default: false, + private: true, + descriptionHTML: +`Enable XMPP clients to connect to the builtin Prosody server.
+This option alone only allows connections from localhost clients.` + }) + + registerSetting({ + name: 'prosody-c2s-port', + label: 'Prosody client to server port', + type: 'input', + default: '52822', + private: true, + descriptionHTML: +`The port that will be used by the c2s module of the builtin Prosody server.
+XMPP clients shall use this port to connect.
+Change it if this port is already in use on your server.
+Keep it close this port on your firewall for now, it will not be accessed from the outer world.` + }) + // ********** settings changes management settingsManager.onSettingsChange(async (settings: any) => { if ('chat-type' in settings) { From fbf9ef3eacbaa603e923a9576658325c09567ffc Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 14 Jul 2021 18:35:46 +0200 Subject: [PATCH 08/21] Rearrange documentation. --- documentation/prosody.md | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/documentation/prosody.md b/documentation/prosody.md index 18277ed0..c48d15fa 100644 --- a/documentation/prosody.md +++ b/documentation/prosody.md @@ -61,21 +61,12 @@ This is the port that the Prosody server will use. By default it is set to 52800 These settings are common with other chat modes. Here is the documentation: [common settings](./common.md). -## Notes - -All instance moderators and admins will be owner for created chat rooms. -If the video is local (not from a remote Peertube), the video owner will be admin in the chat room. - -You can use [ConverseJS moderation commands](https://conversejs.org/docs/html/features.html#moderating-chatrooms) to moderate the room. -When you open the chat room in full screen, there will also be a menu with dedicated commands on the top right. - - ### Prosody advanced settings #### Enable client to server connections This setting enable XMPP clients to connect to the builtin Prosody server. -This option alone **only allows connections from localhost clients**. +For now, this option **only allows connections from localhost clients**. As example, this option can allow an instance of Matterbridge (once it could use anonymous login) *on the same machine* to bridge your chat with another services like a Matrix room. @@ -83,4 +74,12 @@ As example, this option can allow an instance of Matterbridge (once it could use The port that will be used by the c2s module of the builtin Prosody server. XMPP clients shall use this port to connect. -Change it if this port is already in use on your server. \ No newline at end of file +Change it if this port is already in use on your server. + +## Notes + +All instance moderators and admins will be owner for created chat rooms. +If the video is local (not from a remote Peertube), the video owner will be admin in the chat room. + +You can use [ConverseJS moderation commands](https://conversejs.org/docs/html/features.html#moderating-chatrooms) to moderate the room. +When you open the chat room in full screen, there will also be a menu with dedicated commands on the top right. From ed718d7d276d502d78c0bc9c837530428207e44c Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 14 Jul 2021 18:46:08 +0200 Subject: [PATCH 09/21] Rewriting some c2s code. --- server/lib/prosody/config.ts | 14 +++++++++----- server/lib/prosody/config/content.ts | 12 ++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/server/lib/prosody/config.ts b/server/lib/prosody/config.ts index 96d60bdf..35f44fd0 100644 --- a/server/lib/prosody/config.ts +++ b/server/lib/prosody/config.ts @@ -78,10 +78,6 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise Date: Wed, 14 Jul 2021 18:48:24 +0200 Subject: [PATCH 10/21] Changelog. --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcc4f09d..9add2665 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ ## v3.2.0 -... +### Features + +* Builtin Prosody: new settings to enable local C2S. For example, can be used with Matterbridge (thanks https://github.com/tytan652) ## v3.1.0 From b6269d7ca324e96b2039af01d5566cf6738ecfe8 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 14 Jul 2021 19:21:56 +0200 Subject: [PATCH 11/21] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 119ddfdf..46602a16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Features * Builtin Prosody: new settings to enable local C2S. For example, can be used with Matterbridge (thanks https://github.com/tytan652) +* Builtin Prosody: list existing rooms in the settings page ## v3.1.0 From e50cfa6a8b2162b52df6f46fee0b71cf07fefb73 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 14 Jul 2021 19:22:25 +0200 Subject: [PATCH 12/21] Moving setting prosody-peertube-uri in advanced settings. --- server/lib/settings.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/server/lib/settings.ts b/server/lib/settings.ts index 23e29ac0..f9c486d3 100644 --- a/server/lib/settings.ts +++ b/server/lib/settings.ts @@ -110,18 +110,6 @@ Change it if this port is already in use on your server.
You can close this port on your firewall, it will not be accessed from the outer world.` }) - registerSetting({ - name: 'prosody-peertube-uri', - label: 'Peertube url for API calls', - type: 'input', - default: '', - private: true, - descriptionHTML: -`Please let this settings empty if you don't know what you are doing.
-In some rare case, Prosody can't call Peertube's API from its public URI. -You can use this field to customise Peertube's URI for Prosody modules (for example with «http://localhost:9000»).` - }) - registerSetting({ name: 'chat-server', label: 'XMPP service server', @@ -284,6 +272,18 @@ Example: height:400px;`, descriptionHTML: '

Prosody advanced settings

' }) + registerSetting({ + name: 'prosody-peertube-uri', + label: 'Peertube url for API calls', + type: 'input', + default: '', + private: true, + descriptionHTML: +`Please let this settings empty if you don't know what you are doing.
+In some rare case, Prosody can't call Peertube's API from its public URI. +You can use this field to customise Peertube's URI for Prosody modules (for example with «http://localhost:9000»).` + }) + registerSetting({ name: 'prosody-c2s', label: 'Enable client to server connections', From 4a775b1df5bf682a435e987e5b857ffa2c3bc83b Mon Sep 17 00:00:00 2001 From: John Livingston Date: Mon, 19 Jul 2021 15:45:57 +0200 Subject: [PATCH 13/21] Room list: retrieving video metadata. --- client/@types/peertube.d.ts | 1 + client/admin-plugin-client-plugin.ts | 44 +++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/client/@types/peertube.d.ts b/client/@types/peertube.d.ts index 0d0772fc..a649d552 100644 --- a/client/@types/peertube.d.ts +++ b/client/@types/peertube.d.ts @@ -64,6 +64,7 @@ interface RegisterOptions { interface Video { isLive: boolean isLocal: boolean + name: string originInstanceUrl: string uuid: string } diff --git a/client/admin-plugin-client-plugin.ts b/client/admin-plugin-client-plugin.ts index 73787348..fde4199a 100644 --- a/client/admin-plugin-client-plugin.ts +++ b/client/admin-plugin-client-plugin.ts @@ -70,30 +70,66 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re table.classList.add('peertube-plugin-livechat-prosody-list-rooms') container.append(table) // TODO: translate labels. + const labels: any = { + Name: 'Name', + Description: 'Description', + NotFound: 'Not found', + Video: 'Video' + } const titleLineEl = document.createElement('tr') const titleNameEl = document.createElement('th') - titleNameEl.textContent = 'Name' + titleNameEl.textContent = labels.Name const titleDescriptionEl = document.createElement('th') - titleDescriptionEl.textContent = 'Description' + titleDescriptionEl.textContent = labels.Description + const titleVideoEl = document.createElement('th') + titleVideoEl.textContent = labels.Video titleLineEl.append(titleNameEl) titleLineEl.append(titleDescriptionEl) + titleLineEl.append(titleVideoEl) table.append(titleLineEl) rooms.forEach(room => { - // TODO: get some informations about the video. const uuid = room.localpart const href = getBaseRoute() + '/webchat/room/' + encodeURIComponent(uuid) const lineEl = document.createElement('tr') const nameEl = document.createElement('td') const aEl = document.createElement('a') aEl.textContent = room.name - aEl.href = href aEl.target = '_blank' const descriptionEl = document.createElement('td') descriptionEl.textContent = room.description + const videoEl = document.createElement('td') nameEl.append(aEl) lineEl.append(nameEl) lineEl.append(descriptionEl) + lineEl.append(videoEl) table.append(lineEl) + + if (/^[a-zA-A0-9-]+$/.test(uuid)) { + const p = fetch('/api/v1/videos/' + uuid, { + method: 'GET', + headers: peertubeHelpers.getAuthHeader() + }) + p.then(async res => { + if (!res.ok) { + videoEl.textContent = labels.NotFound + return + } + const video: Video | undefined = await res.json() + if (!video) { + videoEl.textContent = labels.NotFound + return + } + + aEl.href = href + const aVideoEl = document.createElement('a') + aVideoEl.textContent = video.name + aVideoEl.target = '_blank' + aVideoEl.href = '/videos/watch/' + uuid + videoEl.append(aVideoEl) + }, () => { + console.error('[peertube-plugin-livechat] Failed to retrieve video ' + uuid) + }) + } }) } } catch (error) { From 91ade27d81a7a4a8f50e7159185b882785b2e724 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Mon, 19 Jul 2021 15:47:18 +0200 Subject: [PATCH 14/21] Changing labels. --- client/admin-plugin-client-plugin.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/admin-plugin-client-plugin.ts b/client/admin-plugin-client-plugin.ts index fde4199a..916b3d67 100644 --- a/client/admin-plugin-client-plugin.ts +++ b/client/admin-plugin-client-plugin.ts @@ -71,16 +71,16 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re container.append(table) // TODO: translate labels. const labels: any = { - Name: 'Name', - Description: 'Description', + RoomName: 'Room name', + RoomDescription: 'Room description', NotFound: 'Not found', Video: 'Video' } const titleLineEl = document.createElement('tr') const titleNameEl = document.createElement('th') - titleNameEl.textContent = labels.Name + titleNameEl.textContent = labels.RoomName const titleDescriptionEl = document.createElement('th') - titleDescriptionEl.textContent = labels.Description + titleDescriptionEl.textContent = labels.RoomDescription const titleVideoEl = document.createElement('th') titleVideoEl.textContent = labels.Video titleLineEl.append(titleNameEl) From 8674ee3f999f630e75e86483401a6512bc444958 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Mon, 19 Jul 2021 16:17:34 +0200 Subject: [PATCH 15/21] Fix identation. --- .../mod_http_peertubelivechat_list_rooms.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua b/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua index c7bff171..4eca4829 100644 --- a/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua +++ b/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua @@ -32,7 +32,7 @@ function check_auth(routes) end local function list_rooms(event) - local request, response = event.request, event.response; + local request, response = event.request, event.response; local rooms_json = array(); for room in all_rooms() do local localpart = jid_split(room.jid); From b65d6ddde7c3ca73eececb4b0d3ce8909e8dade4 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Mon, 19 Jul 2021 16:19:06 +0200 Subject: [PATCH 16/21] Fix identation. --- .../mod_http_peertubelivechat_list_rooms.lua | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua b/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua index 4eca4829..ca6c9e72 100644 --- a/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua +++ b/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua @@ -8,7 +8,7 @@ local all_rooms = rawget(mod_muc, "all_rooms") module:depends"http"; function check_auth(routes) - local function check_request_auth(event) + local function check_request_auth(event) local apikey = module:get_option_string("peertubelivechat_list_rooms_apikey", "") if apikey == "" then return false, 500; @@ -16,25 +16,25 @@ function check_auth(routes) if event.request.headers.authorization ~= "Bearer " .. apikey then return false, 401; end - return true; - end + return true; + end - for route, handler in pairs(routes) do - routes[route] = function (event, ...) - local permit, code = check_request_auth(event); - if not permit then - return code; - end - return handler(event, ...); - end; - end - return routes; + for route, handler in pairs(routes) do + routes[route] = function (event, ...) + local permit, code = check_request_auth(event); + if not permit then + return code; + end + return handler(event, ...); + end; + end + return routes; end local function list_rooms(event) local request, response = event.request, event.response; local rooms_json = array(); - for room in all_rooms() do + for room in all_rooms() do local localpart = jid_split(room.jid); rooms_json:push({ jid = room.jid; @@ -43,14 +43,14 @@ local function list_rooms(event) lang = room.get_language and room:get_language(); description = room:get_description(); }) - end + end event.response.headers["Content-Type"] = "application/json"; - return json.encode_array(rooms_json); + return json.encode_array(rooms_json); end module:provides("http", { - route = check_auth { - ["GET /list-rooms"] = list_rooms; - }; + route = check_auth { + ["GET /list-rooms"] = list_rooms; + }; }); From b64d9730d0b47c27c50348fe5026a41284af54f3 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Mon, 19 Jul 2021 16:51:51 +0200 Subject: [PATCH 17/21] Adding last activity informations. --- client/admin-plugin-client-plugin.ts | 25 +++++++++++++++++-- .../mod_http_peertubelivechat_list_rooms.lua | 6 +++++ shared/lib/types.ts | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/client/admin-plugin-client-plugin.ts b/client/admin-plugin-client-plugin.ts index 916b3d67..ea5b6cbd 100644 --- a/client/admin-plugin-client-plugin.ts +++ b/client/admin-plugin-client-plugin.ts @@ -63,7 +63,17 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re container.textContent = json.error container.classList.add('peertube-plugin-livechat-error') } else { - const rooms = json.rooms.sort((a, b) => a.name.localeCompare(b.name)) + const rooms = json.rooms.sort((a, b) => { + const timestampA = a.lasttimestamp ?? 0 + const timestampB = b.lasttimestamp ?? 0 + if (timestampA === timestampB) { + return a.name.localeCompare(b.name) + } else if (timestampA < timestampB) { + return 1 + } else { + return -1 + } + }) container.textContent = '' const table = document.createElement('table') @@ -74,8 +84,10 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re RoomName: 'Room name', RoomDescription: 'Room description', NotFound: 'Not found', - Video: 'Video' + Video: 'Video', + LastActivity: 'Last activity' } + const titleLineEl = document.createElement('tr') const titleNameEl = document.createElement('th') titleNameEl.textContent = labels.RoomName @@ -83,9 +95,12 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re titleDescriptionEl.textContent = labels.RoomDescription const titleVideoEl = document.createElement('th') titleVideoEl.textContent = labels.Video + const titleLastActivityEl = document.createElement('th') + titleLastActivityEl.textContent = labels.LastActivity titleLineEl.append(titleNameEl) titleLineEl.append(titleDescriptionEl) titleLineEl.append(titleVideoEl) + titleLineEl.append(titleLastActivityEl) table.append(titleLineEl) rooms.forEach(room => { const uuid = room.localpart @@ -98,10 +113,16 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re const descriptionEl = document.createElement('td') descriptionEl.textContent = room.description const videoEl = document.createElement('td') + const lastActivityEl = document.createElement('td') + if (room.lasttimestamp && (typeof room.lasttimestamp === 'number')) { + const date = new Date(room.lasttimestamp * 1000) + lastActivityEl.textContent = date.toLocaleDateString() + ' ' + date.toLocaleTimeString() + } nameEl.append(aEl) lineEl.append(nameEl) lineEl.append(descriptionEl) lineEl.append(videoEl) + lineEl.append(lastActivityEl) table.append(lineEl) if (/^[a-zA-A0-9-]+$/.test(uuid)) { diff --git a/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua b/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua index ca6c9e72..83ee98be 100644 --- a/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua +++ b/prosody-modules/mod_http_peertubelivechat_list_rooms/mod_http_peertubelivechat_list_rooms.lua @@ -36,12 +36,18 @@ local function list_rooms(event) local rooms_json = array(); for room in all_rooms() do local localpart = jid_split(room.jid); + local history = room._history; + local lasttimestamp; + if history ~= nil and #history > 0 then + lasttimestamp = history[#history].timestamp; + end rooms_json:push({ jid = room.jid; localpart = localpart; name = room:get_name() or localpart; lang = room.get_language and room:get_language(); description = room:get_description(); + lasttimestamp = lasttimestamp; }) end diff --git a/shared/lib/types.ts b/shared/lib/types.ts index 9e00f40a..d21f4ab8 100644 --- a/shared/lib/types.ts +++ b/shared/lib/types.ts @@ -13,6 +13,7 @@ interface ProsodyListRoomsResultSuccess { name: string lang: string description: string + lasttimestamp?: number }> } From 226abcbc0e8b3b99927db806f2ac914597b42ae3 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 20 Jul 2021 01:18:01 +0200 Subject: [PATCH 18/21] Some styles. --- assets/style.css | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/assets/style.css b/assets/style.css index e3219162..5673368a 100644 --- a/assets/style.css +++ b/assets/style.css @@ -61,4 +61,26 @@ table.peertube-plugin-livechat-prosody-list-rooms { border: 1px solid black; + margin: 5px 0px; +} + +table.peertube-plugin-livechat-prosody-list-rooms tr:nth-child(odd) { + background-color: #eee; +} + +table.peertube-plugin-livechat-prosody-list-rooms tr:nth-child(even) { + background-color: #fff; +} + +table.peertube-plugin-livechat-prosody-list-rooms th { + background-color: var(--mainHoverColor); + border: 1px solid black; + color: var(--mainBackgroundColor); + padding: 4px 5px; +} + +table.peertube-plugin-livechat-prosody-list-rooms td { + border: 1px solid #555; + color: black; + padding: 4px 5px; } From b54370a62cbb9767af48b26d77d84aab299c38d8 Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 20 Jul 2021 01:21:39 +0200 Subject: [PATCH 19/21] Roadmap. --- ROADMAP.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ROADMAP.md b/ROADMAP.md index 68241fbb..e66fd8ed 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -29,7 +29,7 @@ This roadmap is given as an indication. It will be updated as we go along accord [x] | Documentation | Rewrite documentation for more clarity. | v3.0.0 [ ] | Documentation | Add screenshots. [ ] | Documentation | User documentation. -[ ] | Builtin Prosody | Room administration: add a button in the plugin settings to open a modal with existing rooms list. +[.] | Builtin Prosody | Room administration: add a button in the plugin settings to open a modal with existing rooms list. TODO: use a modal. | v3.2.0 [ ] | Builtin Prosody | Check with yunohost how to integrate. [ ] | Settings | Translate settings page. [ ] | ConverseJS | UI: make custom templates, for a better UI/UX. Autoshow muc participants depending on the chat window width. From 2d659b652259cb65bac13d9a694531ee1668318a Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 20 Jul 2021 01:50:10 +0200 Subject: [PATCH 20/21] Fix changelog. --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46602a16..b95426bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ ### Features -* Builtin Prosody: new settings to enable local C2S. For example, can be used with Matterbridge (thanks https://github.com/tytan652) * Builtin Prosody: list existing rooms in the settings page +* Builtin Prosody: new settings to enable local C2S. For example, can be used with Matterbridge (thanks https://github.com/tytan652) ## v3.1.0 @@ -26,7 +26,6 @@ * New simpler settings screen. * New field in live video form, to activate the webchat per video. There is a setting for enabling this new feature. -* When using the builtin prosody, there is a button to list existing chatrooms in the settings screen. ### Changes From 40ad9629fc1542d5a6f6558c62b3eaf9ae35d73b Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 20 Jul 2021 02:52:58 +0200 Subject: [PATCH 21/21] Fix broken API diagnostic. * Moving http_peertubelivechat_test module in muc component, as the global config has no http_host. * Adding Host HTTP Header to API call from Peertube to Prosody --- CHANGELOG.md | 4 ++++ server/lib/diagnostic/prosody.ts | 8 +++++-- server/lib/prosody/config.ts | 4 +++- server/lib/prosody/config/content.ts | 6 ++--- server/lib/prosody/ctl.ts | 5 +++- server/lib/routers/webchat.ts | 36 ++++++++++++++++++---------- 6 files changed, 43 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b95426bb..a2f49a60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ * Builtin Prosody: list existing rooms in the settings page * Builtin Prosody: new settings to enable local C2S. For example, can be used with Matterbridge (thanks https://github.com/tytan652) +### Fixes + +* Fix broken API diagnostic. + ## v3.1.0 ### Features diff --git a/server/lib/diagnostic/prosody.ts b/server/lib/diagnostic/prosody.ts index f069eb54..64b0fe70 100644 --- a/server/lib/diagnostic/prosody.ts +++ b/server/lib/diagnostic/prosody.ts @@ -21,12 +21,14 @@ export async function diagProsody (test: string, options: RegisterServerOptions) // FIXME: these tests are very similar to tests in testProsodyCorrectlyRunning. Remove from here? // Testing the prosody config file. let prosodyPort: string + let prosodyHost: string try { const wantedConfig = await getProsodyConfig(options) const filePath = wantedConfig.paths.config result.messages.push(`Prosody will run on port '${wantedConfig.port}'`) prosodyPort = wantedConfig.port + prosodyHost = wantedConfig.host result.messages.push(`Prosody will use ${wantedConfig.baseApiUrl} as base uri from api calls`) @@ -99,7 +101,8 @@ export async function diagProsody (test: string, options: RegisterServerOptions) const testResult = await got(apiUrl, { method: 'GET', headers: { - authorization: 'Bearer ' + await getAPIKey(options) + authorization: 'Bearer ' + await getAPIKey(options), + host: prosodyHost }, responseType: 'json', resolveBodyOnly: true @@ -120,7 +123,8 @@ export async function diagProsody (test: string, options: RegisterServerOptions) const testResult = await got(apiUrl, { method: 'GET', headers: { - authorization: 'Bearer ' + await getAPIKey(options) + authorization: 'Bearer ' + await getAPIKey(options), + host: prosodyHost }, responseType: 'json', resolveBodyOnly: true diff --git a/server/lib/prosody/config.ts b/server/lib/prosody/config.ts index 1c077845..ac7d4819 100644 --- a/server/lib/prosody/config.ts +++ b/server/lib/prosody/config.ts @@ -66,6 +66,7 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise { return new Promise((resolve) => { diff --git a/server/lib/routers/webchat.ts b/server/lib/routers/webchat.ts index 8b67417d..aa23019c 100644 --- a/server/lib/routers/webchat.ts +++ b/server/lib/routers/webchat.ts @@ -13,7 +13,11 @@ const fs = require('fs').promises const proxy = require('express-http-proxy') let httpBindRoute: RequestHandler -let prosodyPort: string | undefined +interface ProsodyHttpBindInfo { + host: string + port: string +} +let currentProsodyHttpBindInfo: ProsodyHttpBindInfo | null = null async function initWebchatRouter (options: RegisterServerOptions): Promise { const { @@ -124,15 +128,16 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise { res.status(404) res.send('Not found') } } else { + logger.info('Changing http-bind port for ' + prosodyHttpBindInfo.port + ', on host ' + prosodyHttpBindInfo.host) const options: ProxyOptions = { https: false, proxyReqPathResolver: async (_req: Request): Promise => { @@ -173,8 +183,8 @@ function changeHttpBindRoute ({ peertubeHelpers }: RegisterServerOptions, port: parseReqBody: true // Note that setting this to false overrides reqAsBuffer and reqBodyEncoding below. // FIXME: should we remove cookies? } - prosodyPort = port - httpBindRoute = proxy('http://localhost:' + port, options) + currentProsodyHttpBindInfo = prosodyHttpBindInfo + httpBindRoute = proxy('http://localhost:' + prosodyHttpBindInfo.port, options) } }