diff options
-rw-r--r-- | server/tests/api/live/live-socket-messages.ts | 11 | ||||
-rw-r--r-- | shared/extra-utils/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/socket/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/socket/socket-io-command.ts | 15 | ||||
-rw-r--r-- | shared/extra-utils/socket/socket-io.ts | 18 | ||||
-rw-r--r-- | shared/extra-utils/users/user-notifications.ts | 7 |
7 files changed, 28 insertions, 28 deletions
diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index 0159d5199..20fec16a9 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts | |||
@@ -2,7 +2,6 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { getLiveNotificationSocket } from '@shared/extra-utils/socket/socket-io' | ||
6 | import { VideoPrivacy, VideoState } from '@shared/models' | 5 | import { VideoPrivacy, VideoState } from '@shared/models' |
7 | import { | 6 | import { |
8 | cleanupTests, | 7 | cleanupTests, |
@@ -77,7 +76,7 @@ describe('Test live', function () { | |||
77 | { | 76 | { |
78 | const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) | 77 | const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) |
79 | 78 | ||
80 | const localSocket = getLiveNotificationSocket(servers[0].url) | 79 | const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() |
81 | localSocket.on('state-change', data => localStateChanges.push(data.state)) | 80 | localSocket.on('state-change', data => localStateChanges.push(data.state)) |
82 | localSocket.emit('subscribe', { videoId }) | 81 | localSocket.emit('subscribe', { videoId }) |
83 | } | 82 | } |
@@ -85,7 +84,7 @@ describe('Test live', function () { | |||
85 | { | 84 | { |
86 | const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) | 85 | const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) |
87 | 86 | ||
88 | const remoteSocket = getLiveNotificationSocket(servers[1].url) | 87 | const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() |
89 | remoteSocket.on('state-change', data => remoteStateChanges.push(data.state)) | 88 | remoteSocket.on('state-change', data => remoteStateChanges.push(data.state)) |
90 | remoteSocket.emit('subscribe', { videoId }) | 89 | remoteSocket.emit('subscribe', { videoId }) |
91 | } | 90 | } |
@@ -125,7 +124,7 @@ describe('Test live', function () { | |||
125 | { | 124 | { |
126 | const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) | 125 | const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) |
127 | 126 | ||
128 | const localSocket = getLiveNotificationSocket(servers[0].url) | 127 | const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket() |
129 | localSocket.on('views-change', data => { localLastVideoViews = data.views }) | 128 | localSocket.on('views-change', data => { localLastVideoViews = data.views }) |
130 | localSocket.emit('subscribe', { videoId }) | 129 | localSocket.emit('subscribe', { videoId }) |
131 | } | 130 | } |
@@ -133,7 +132,7 @@ describe('Test live', function () { | |||
133 | { | 132 | { |
134 | const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) | 133 | const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID) |
135 | 134 | ||
136 | const remoteSocket = getLiveNotificationSocket(servers[1].url) | 135 | const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket() |
137 | remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views }) | 136 | remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views }) |
138 | remoteSocket.emit('subscribe', { videoId }) | 137 | remoteSocket.emit('subscribe', { videoId }) |
139 | } | 138 | } |
@@ -169,7 +168,7 @@ describe('Test live', function () { | |||
169 | 168 | ||
170 | const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) | 169 | const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID) |
171 | 170 | ||
172 | const socket = getLiveNotificationSocket(servers[0].url) | 171 | const socket = servers[0].socketIOCommand.getLiveNotificationSocket() |
173 | socket.on('state-change', data => stateChanges.push(data.state)) | 172 | socket.on('state-change', data => stateChanges.push(data.state)) |
174 | socket.emit('subscribe', { videoId }) | 173 | socket.emit('subscribe', { videoId }) |
175 | 174 | ||
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' | |||
9 | export * from './overviews' | 9 | export * from './overviews' |
10 | export * from './search' | 10 | export * from './search' |
11 | export * from './server' | 11 | export * from './server' |
12 | export * from './socket' | ||
12 | 13 | ||
13 | export * from './requests/check-api-params' | 14 | export * from './requests/check-api-params' |
14 | export * from './requests/requests' | 15 | export * 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' | |||
16 | import { OverviewsCommand } from '../overviews' | 16 | import { OverviewsCommand } from '../overviews' |
17 | import { makeGetRequest } from '../requests/requests' | 17 | import { makeGetRequest } from '../requests/requests' |
18 | import { SearchCommand } from '../search' | 18 | import { SearchCommand } from '../search' |
19 | import { SocketIOCommand } from '../socket' | ||
19 | import { ConfigCommand } from './config-command' | 20 | import { ConfigCommand } from './config-command' |
20 | import { ContactFormCommand } from './contact-form-command' | 21 | import { ContactFormCommand } from './contact-form-command' |
21 | import { DebugCommand } from './debug-command' | 22 | import { 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 | ||
98 | function parallelTests () { | 100 | function 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 @@ | |||
1 | import { io } from 'socket.io-client' | ||
2 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
3 | |||
4 | export 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 @@ | |||
1 | import { io } from 'socket.io-client' | ||
2 | |||
3 | function getUserNotificationSocket (serverUrl: string, accessToken: string) { | ||
4 | return io(serverUrl + '/user-notifications', { | ||
5 | query: { accessToken } | ||
6 | }) | ||
7 | } | ||
8 | |||
9 | function getLiveNotificationSocket (serverUrl: string) { | ||
10 | return io(serverUrl + '/live-videos') | ||
11 | } | ||
12 | |||
13 | // --------------------------------------------------------------------------- | ||
14 | |||
15 | export { | ||
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' | |||
9 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | 9 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' |
10 | import { doubleFollow } from '../server/follows' | 10 | import { doubleFollow } from '../server/follows' |
11 | import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' | 11 | import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' |
12 | import { getUserNotificationSocket } from '../socket/socket-io' | ||
13 | import { setAccessTokensToServers, userLogin } from './login' | 12 | import { setAccessTokensToServers, userLogin } from './login' |
14 | import { createUser, getMyUserInformation } from './users' | 13 | import { 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 | ||