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:
Jerko Steiner 2019-11-15 23:46:54 -03:00
parent 7fa09fa6b8
commit 92a5f2063c
4 changed files with 8 additions and 5 deletions

View File

@ -2,7 +2,7 @@ import * as ChatActions from '../actions/ChatActions'
import * as NotifyActions from '../actions/NotifyActions'
import * as StreamActions from '../actions/StreamActions'
import * as constants from '../constants'
import Peer from 'simple-peer'
import Peer, { SignalData } from 'simple-peer'
import forEach from 'lodash/forEach'
import _debug from 'debug'
import { play, iceServers } from '../window'
@ -42,7 +42,7 @@ class PeerHandler {
peer && peer.destroy()
dispatch(removePeer(user.id))
}
handleSignal = (signal: unknown) => {
handleSignal = (signal: SignalData) => {
const { socket, user } = this
debug('peer: %s, signal: %o', user.id, signal)

View File

@ -33,5 +33,6 @@ router.use('/', index)
app.use(BASE_URL, router)
io.on('connection', socket => handleSocket(socket, io))
io.sockets.adapter.rooms['test'].sockets
export default server

View File

@ -1,6 +1,7 @@
import { EventEmitter } from 'events'
import { Socket } from 'socket.io'
import { TypedIO } from '../shared'
import handleSocket from './socket'
import { Socket, Server } from 'socket.io'
describe('server/socket', () => {
type SocketMock = Socket & {
@ -12,7 +13,7 @@ describe('server/socket', () => {
}
let socket: SocketMock
let io: Server & {
let io: TypedIO & {
in: jest.Mock<(room: string) => SocketMock>
to: jest.Mock<(room: string) => SocketMock>
}

View File

@ -1,4 +1,5 @@
import { TypedEmitter, TypedEmitterKeys } from './TypedEmitter'
import { SignalData } from 'simple-peer'
export interface User {
id: string
@ -12,7 +13,7 @@ export interface SocketEvent {
signal: {
userId: string
// eslint-disable-next-line
signal: any
signal: SignalData
}
connect: undefined
disconnect: undefined