aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-07 11:55:16 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commit87e2635a50ac2decb1c330e55c2ff7b6d07a85de (patch)
treed47c126e74189648916b49d7fea588e3488fdbe6 /shared/extra-utils
parent65e6e2602c0d5521f3a6740f7469bb92830ecb53 (diff)
downloadPeerTube-87e2635a50ac2decb1c330e55c2ff7b6d07a85de.tar.gz
PeerTube-87e2635a50ac2decb1c330e55c2ff7b6d07a85de.tar.zst
PeerTube-87e2635a50ac2decb1c330e55c2ff7b6d07a85de.zip
Introduce socket io command
Diffstat (limited to 'shared/extra-utils')
-rw-r--r--shared/extra-utils/index.ts1
-rw-r--r--shared/extra-utils/server/servers.ts3
-rw-r--r--shared/extra-utils/socket/index.ts1
-rw-r--r--shared/extra-utils/socket/socket-io-command.ts15
-rw-r--r--shared/extra-utils/socket/socket-io.ts18
-rw-r--r--shared/extra-utils/users/user-notifications.ts7
6 files changed, 23 insertions, 22 deletions
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts
index f69d7241e..ed7d7ab04 100644
--- a/shared/extra-utils/index.ts
+++ b/shared/extra-utils/index.ts
@@ -9,6 +9,7 @@ export * from './moderation'
9export * from './overviews' 9export * from './overviews'
10export * from './search' 10export * from './search'
11export * from './server' 11export * from './server'
12export * from './socket'
12 13
13export * from './requests/check-api-params' 14export * from './requests/check-api-params'
14export * from './requests/requests' 15export * from './requests/requests'
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index c33b68316..8bd4446be 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -16,6 +16,7 @@ import { AbusesCommand } from '../moderation'
16import { OverviewsCommand } from '../overviews' 16import { OverviewsCommand } from '../overviews'
17import { makeGetRequest } from '../requests/requests' 17import { makeGetRequest } from '../requests/requests'
18import { SearchCommand } from '../search' 18import { SearchCommand } from '../search'
19import { SocketIOCommand } from '../socket'
19import { ConfigCommand } from './config-command' 20import { ConfigCommand } from './config-command'
20import { ContactFormCommand } from './contact-form-command' 21import { ContactFormCommand } from './contact-form-command'
21import { DebugCommand } from './debug-command' 22import { DebugCommand } from './debug-command'
@@ -93,6 +94,7 @@ interface ServerInfo {
93 redundancyCommand?: RedundancyCommand 94 redundancyCommand?: RedundancyCommand
94 statsCommand?: StatsCommand 95 statsCommand?: StatsCommand
95 configCommand?: ConfigCommand 96 configCommand?: ConfigCommand
97 socketIOCommand?: SocketIOCommand
96} 98}
97 99
98function parallelTests () { 100function parallelTests () {
@@ -314,6 +316,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
314 server.redundancyCommand = new RedundancyCommand(server) 316 server.redundancyCommand = new RedundancyCommand(server)
315 server.statsCommand = new StatsCommand(server) 317 server.statsCommand = new StatsCommand(server)
316 server.configCommand = new ConfigCommand(server) 318 server.configCommand = new ConfigCommand(server)
319 server.socketIOCommand = new SocketIOCommand(server)
317 320
318 res(server) 321 res(server)
319 }) 322 })
diff --git a/shared/extra-utils/socket/index.ts b/shared/extra-utils/socket/index.ts
new file mode 100644
index 000000000..594329b2f
--- /dev/null
+++ b/shared/extra-utils/socket/index.ts
@@ -0,0 +1 @@
export * from './socket-io-command'
diff --git a/shared/extra-utils/socket/socket-io-command.ts b/shared/extra-utils/socket/socket-io-command.ts
new file mode 100644
index 000000000..545561bed
--- /dev/null
+++ b/shared/extra-utils/socket/socket-io-command.ts
@@ -0,0 +1,15 @@
1import { io } from 'socket.io-client'
2import { AbstractCommand, OverrideCommandOptions } from '../shared'
3
4export class SocketIOCommand extends AbstractCommand {
5
6 getUserNotificationSocket (options: OverrideCommandOptions = {}) {
7 return io(this.server.url + '/user-notifications', {
8 query: { accessToken: this.server.accessToken }
9 })
10 }
11
12 getLiveNotificationSocket () {
13 return io(this.server.url + '/live-videos')
14 }
15}
diff --git a/shared/extra-utils/socket/socket-io.ts b/shared/extra-utils/socket/socket-io.ts
deleted file mode 100644
index 4ca93f453..000000000
--- a/shared/extra-utils/socket/socket-io.ts
+++ /dev/null
@@ -1,18 +0,0 @@
1import { io } from 'socket.io-client'
2
3function getUserNotificationSocket (serverUrl: string, accessToken: string) {
4 return io(serverUrl + '/user-notifications', {
5 query: { accessToken }
6 })
7}
8
9function getLiveNotificationSocket (serverUrl: string) {
10 return io(serverUrl + '/live-videos')
11}
12
13// ---------------------------------------------------------------------------
14
15export {
16 getUserNotificationSocket,
17 getLiveNotificationSocket
18}
diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts
index e75946eec..961cfcc0f 100644
--- a/shared/extra-utils/users/user-notifications.ts
+++ b/shared/extra-utils/users/user-notifications.ts
@@ -9,7 +9,6 @@ import { MockSmtpServer } from '../mock-servers/mock-email'
9import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' 9import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
10import { doubleFollow } from '../server/follows' 10import { doubleFollow } from '../server/follows'
11import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' 11import { flushAndRunMultipleServers, ServerInfo } from '../server/servers'
12import { getUserNotificationSocket } from '../socket/socket-io'
13import { setAccessTokensToServers, userLogin } from './login' 12import { setAccessTokensToServers, userLogin } from './login'
14import { createUser, getMyUserInformation } from './users' 13import { createUser, getMyUserInformation } from './users'
15 14
@@ -748,16 +747,16 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
748 } 747 }
749 748
750 { 749 {
751 const socket = getUserNotificationSocket(servers[0].url, userAccessToken) 750 const socket = servers[0].socketIOCommand.getUserNotificationSocket({ token: userAccessToken })
752 socket.on('new-notification', n => userNotifications.push(n)) 751 socket.on('new-notification', n => userNotifications.push(n))
753 } 752 }
754 { 753 {
755 const socket = getUserNotificationSocket(servers[0].url, servers[0].accessToken) 754 const socket = servers[0].socketIOCommand.getUserNotificationSocket()
756 socket.on('new-notification', n => adminNotifications.push(n)) 755 socket.on('new-notification', n => adminNotifications.push(n))
757 } 756 }
758 757
759 if (serversCount > 1) { 758 if (serversCount > 1) {
760 const socket = getUserNotificationSocket(servers[1].url, servers[1].accessToken) 759 const socket = servers[1].socketIOCommand.getUserNotificationSocket()
761 socket.on('new-notification', n => adminNotificationsServer2.push(n)) 760 socket.on('new-notification', n => adminNotificationsServer2.push(n))
762 } 761 }
763 762