mirror of https://github.com/Chocobozzz/PeerTube
Introduce socket io command
parent
65e6e2602c
commit
87e2635a50
|
@ -2,7 +2,6 @@
|
|||
|
||||
import 'mocha'
|
||||
import * as chai from 'chai'
|
||||
import { getLiveNotificationSocket } from '@shared/extra-utils/socket/socket-io'
|
||||
import { VideoPrivacy, VideoState } from '@shared/models'
|
||||
import {
|
||||
cleanupTests,
|
||||
|
@ -77,7 +76,7 @@ describe('Test live', function () {
|
|||
{
|
||||
const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
|
||||
|
||||
const localSocket = getLiveNotificationSocket(servers[0].url)
|
||||
const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket()
|
||||
localSocket.on('state-change', data => localStateChanges.push(data.state))
|
||||
localSocket.emit('subscribe', { videoId })
|
||||
}
|
||||
|
@ -85,7 +84,7 @@ describe('Test live', function () {
|
|||
{
|
||||
const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID)
|
||||
|
||||
const remoteSocket = getLiveNotificationSocket(servers[1].url)
|
||||
const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket()
|
||||
remoteSocket.on('state-change', data => remoteStateChanges.push(data.state))
|
||||
remoteSocket.emit('subscribe', { videoId })
|
||||
}
|
||||
|
@ -125,7 +124,7 @@ describe('Test live', function () {
|
|||
{
|
||||
const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
|
||||
|
||||
const localSocket = getLiveNotificationSocket(servers[0].url)
|
||||
const localSocket = servers[0].socketIOCommand.getLiveNotificationSocket()
|
||||
localSocket.on('views-change', data => { localLastVideoViews = data.views })
|
||||
localSocket.emit('subscribe', { videoId })
|
||||
}
|
||||
|
@ -133,7 +132,7 @@ describe('Test live', function () {
|
|||
{
|
||||
const videoId = await getVideoIdFromUUID(servers[1].url, liveVideoUUID)
|
||||
|
||||
const remoteSocket = getLiveNotificationSocket(servers[1].url)
|
||||
const remoteSocket = servers[1].socketIOCommand.getLiveNotificationSocket()
|
||||
remoteSocket.on('views-change', data => { remoteLastVideoViews = data.views })
|
||||
remoteSocket.emit('subscribe', { videoId })
|
||||
}
|
||||
|
@ -169,7 +168,7 @@ describe('Test live', function () {
|
|||
|
||||
const videoId = await getVideoIdFromUUID(servers[0].url, liveVideoUUID)
|
||||
|
||||
const socket = getLiveNotificationSocket(servers[0].url)
|
||||
const socket = servers[0].socketIOCommand.getLiveNotificationSocket()
|
||||
socket.on('state-change', data => stateChanges.push(data.state))
|
||||
socket.emit('subscribe', { videoId })
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ export * from './moderation'
|
|||
export * from './overviews'
|
||||
export * from './search'
|
||||
export * from './server'
|
||||
export * from './socket'
|
||||
|
||||
export * from './requests/check-api-params'
|
||||
export * from './requests/requests'
|
||||
|
|
|
@ -16,6 +16,7 @@ import { AbusesCommand } from '../moderation'
|
|||
import { OverviewsCommand } from '../overviews'
|
||||
import { makeGetRequest } from '../requests/requests'
|
||||
import { SearchCommand } from '../search'
|
||||
import { SocketIOCommand } from '../socket'
|
||||
import { ConfigCommand } from './config-command'
|
||||
import { ContactFormCommand } from './contact-form-command'
|
||||
import { DebugCommand } from './debug-command'
|
||||
|
@ -93,6 +94,7 @@ interface ServerInfo {
|
|||
redundancyCommand?: RedundancyCommand
|
||||
statsCommand?: StatsCommand
|
||||
configCommand?: ConfigCommand
|
||||
socketIOCommand?: SocketIOCommand
|
||||
}
|
||||
|
||||
function parallelTests () {
|
||||
|
@ -314,6 +316,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
|
|||
server.redundancyCommand = new RedundancyCommand(server)
|
||||
server.statsCommand = new StatsCommand(server)
|
||||
server.configCommand = new ConfigCommand(server)
|
||||
server.socketIOCommand = new SocketIOCommand(server)
|
||||
|
||||
res(server)
|
||||
})
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export * from './socket-io-command'
|
|
@ -0,0 +1,15 @@
|
|||
import { io } from 'socket.io-client'
|
||||
import { AbstractCommand, OverrideCommandOptions } from '../shared'
|
||||
|
||||
export class SocketIOCommand extends AbstractCommand {
|
||||
|
||||
getUserNotificationSocket (options: OverrideCommandOptions = {}) {
|
||||
return io(this.server.url + '/user-notifications', {
|
||||
query: { accessToken: this.server.accessToken }
|
||||
})
|
||||
}
|
||||
|
||||
getLiveNotificationSocket () {
|
||||
return io(this.server.url + '/live-videos')
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
import { io } from 'socket.io-client'
|
||||
|
||||
function getUserNotificationSocket (serverUrl: string, accessToken: string) {
|
||||
return io(serverUrl + '/user-notifications', {
|
||||
query: { accessToken }
|
||||
})
|
||||
}
|
||||
|
||||
function getLiveNotificationSocket (serverUrl: string) {
|
||||
return io(serverUrl + '/live-videos')
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export {
|
||||
getUserNotificationSocket,
|
||||
getLiveNotificationSocket
|
||||
}
|
|
@ -9,7 +9,6 @@ import { MockSmtpServer } from '../mock-servers/mock-email'
|
|||
import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
|
||||
import { doubleFollow } from '../server/follows'
|
||||
import { flushAndRunMultipleServers, ServerInfo } from '../server/servers'
|
||||
import { getUserNotificationSocket } from '../socket/socket-io'
|
||||
import { setAccessTokensToServers, userLogin } from './login'
|
||||
import { createUser, getMyUserInformation } from './users'
|
||||
|
||||
|
@ -748,16 +747,16 @@ async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: an
|
|||
}
|
||||
|
||||
{
|
||||
const socket = getUserNotificationSocket(servers[0].url, userAccessToken)
|
||||
const socket = servers[0].socketIOCommand.getUserNotificationSocket({ token: userAccessToken })
|
||||
socket.on('new-notification', n => userNotifications.push(n))
|
||||
}
|
||||
{
|
||||
const socket = getUserNotificationSocket(servers[0].url, servers[0].accessToken)
|
||||
const socket = servers[0].socketIOCommand.getUserNotificationSocket()
|
||||
socket.on('new-notification', n => adminNotifications.push(n))
|
||||
}
|
||||
|
||||
if (serversCount > 1) {
|
||||
const socket = getUserNotificationSocket(servers[1].url, servers[1].accessToken)
|
||||
const socket = servers[1].socketIOCommand.getUserNotificationSocket()
|
||||
socket.on('new-notification', n => adminNotificationsServer2.push(n))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue