aboutsummaryrefslogtreecommitdiffhomepage
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
parent65e6e2602c0d5521f3a6740f7469bb92830ecb53 (diff)
downloadPeerTube-87e2635a50ac2decb1c330e55c2ff7b6d07a85de.tar.gz
PeerTube-87e2635a50ac2decb1c330e55c2ff7b6d07a85de.tar.zst
PeerTube-87e2635a50ac2decb1c330e55c2ff7b6d07a85de.zip
Introduce socket io command
-rw-r--r--server/tests/api/live/live-socket-messages.ts11
-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
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
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { getLiveNotificationSocket } from '@shared/extra-utils/socket/socket-io'
6import { VideoPrivacy, VideoState } from '@shared/models' 5import { VideoPrivacy, VideoState } from '@shared/models'
7import { 6import {
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'
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