Use SignalData on server-side
This should not cause compile issues when simple-peer is not installed (because client-side JS will be precompiled after pkg is published in NPM repository) because types are not used in runtime.
This commit is contained in:
parent
7fa09fa6b8
commit
92a5f2063c
@ -2,7 +2,7 @@ import * as ChatActions from '../actions/ChatActions'
|
|||||||
import * as NotifyActions from '../actions/NotifyActions'
|
import * as NotifyActions from '../actions/NotifyActions'
|
||||||
import * as StreamActions from '../actions/StreamActions'
|
import * as StreamActions from '../actions/StreamActions'
|
||||||
import * as constants from '../constants'
|
import * as constants from '../constants'
|
||||||
import Peer from 'simple-peer'
|
import Peer, { SignalData } from 'simple-peer'
|
||||||
import forEach from 'lodash/forEach'
|
import forEach from 'lodash/forEach'
|
||||||
import _debug from 'debug'
|
import _debug from 'debug'
|
||||||
import { play, iceServers } from '../window'
|
import { play, iceServers } from '../window'
|
||||||
@ -42,7 +42,7 @@ class PeerHandler {
|
|||||||
peer && peer.destroy()
|
peer && peer.destroy()
|
||||||
dispatch(removePeer(user.id))
|
dispatch(removePeer(user.id))
|
||||||
}
|
}
|
||||||
handleSignal = (signal: unknown) => {
|
handleSignal = (signal: SignalData) => {
|
||||||
const { socket, user } = this
|
const { socket, user } = this
|
||||||
debug('peer: %s, signal: %o', user.id, signal)
|
debug('peer: %s, signal: %o', user.id, signal)
|
||||||
|
|
||||||
|
|||||||
@ -33,5 +33,6 @@ router.use('/', index)
|
|||||||
app.use(BASE_URL, router)
|
app.use(BASE_URL, router)
|
||||||
|
|
||||||
io.on('connection', socket => handleSocket(socket, io))
|
io.on('connection', socket => handleSocket(socket, io))
|
||||||
|
io.sockets.adapter.rooms['test'].sockets
|
||||||
|
|
||||||
export default server
|
export default server
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'events'
|
||||||
|
import { Socket } from 'socket.io'
|
||||||
|
import { TypedIO } from '../shared'
|
||||||
import handleSocket from './socket'
|
import handleSocket from './socket'
|
||||||
import { Socket, Server } from 'socket.io'
|
|
||||||
|
|
||||||
describe('server/socket', () => {
|
describe('server/socket', () => {
|
||||||
type SocketMock = Socket & {
|
type SocketMock = Socket & {
|
||||||
@ -12,7 +13,7 @@ describe('server/socket', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let socket: SocketMock
|
let socket: SocketMock
|
||||||
let io: Server & {
|
let io: TypedIO & {
|
||||||
in: jest.Mock<(room: string) => SocketMock>
|
in: jest.Mock<(room: string) => SocketMock>
|
||||||
to: jest.Mock<(room: string) => SocketMock>
|
to: jest.Mock<(room: string) => SocketMock>
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { TypedEmitter, TypedEmitterKeys } from './TypedEmitter'
|
import { TypedEmitter, TypedEmitterKeys } from './TypedEmitter'
|
||||||
|
import { SignalData } from 'simple-peer'
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
id: string
|
id: string
|
||||||
@ -12,7 +13,7 @@ export interface SocketEvent {
|
|||||||
signal: {
|
signal: {
|
||||||
userId: string
|
userId: string
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
signal: any
|
signal: SignalData
|
||||||
}
|
}
|
||||||
connect: undefined
|
connect: undefined
|
||||||
disconnect: undefined
|
disconnect: undefined
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user