Archived
2
0

update to pion v3

This commit is contained in:
Marcel Battista
2021-02-14 16:30:24 +00:00
parent 00a785f4c5
commit a362df4976
14 changed files with 211 additions and 84 deletions

View File

@ -2,7 +2,7 @@ import EventEmitter from 'eventemitter3'
import { OPCODE } from './data'
import { EVENT, WebSocketEvents } from './events'
import { WebSocketMessages, WebSocketPayloads, SignalProvidePayload } from './messages'
import { WebSocketMessages, WebSocketPayloads, SignalProvidePayload, SignalCandidatePayload } from './messages'
export interface BaseEvents {
info: (...message: any[]) => void
@ -211,8 +211,8 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
}
this._peer.ontrack = this.onTrack.bind(this)
this._peer.addTransceiver('audio', { direction: 'recvonly' })
this._peer.addTransceiver('video', { direction: 'recvonly' })
this._peer.addTransceiver('audio', { direction: 'sendrecv' })
this._peer.addTransceiver('video', { direction: 'sendrecv' })
this._channel = this._peer.createDataChannel('data')
this._channel.onerror = this.onError.bind(this)
@ -246,6 +246,15 @@ export abstract class BaseClient extends EventEmitter<BaseEvents> {
this.createPeer(sdp, lite, ice)
return
}
if (event === EVENT.SIGNAL.CANDIDATE) {
const { data } = payload as SignalCandidatePayload
let candidate: RTCIceCandidate = JSON.parse(data)
this._peer!.addIceCandidate(candidate)
return
}
// @ts-ignore
if (typeof this[event] === 'function') {

View File

@ -14,6 +14,7 @@ export const EVENT = {
SIGNAL: {
ANSWER: 'signal/answer',
PROVIDE: 'signal/provide',
CANDIDATE: 'signal/candidate'
},
MEMBER: {
LIST: 'member/list',
@ -78,7 +79,7 @@ export type ControlEvents =
export type SystemEvents = typeof EVENT.SYSTEM.DISCONNECT
export type MemberEvents = typeof EVENT.MEMBER.LIST | typeof EVENT.MEMBER.CONNECTED | typeof EVENT.MEMBER.DISCONNECTED
export type SignalEvents = typeof EVENT.SIGNAL.ANSWER | typeof EVENT.SIGNAL.PROVIDE
export type SignalEvents = typeof EVENT.SIGNAL.ANSWER | typeof EVENT.SIGNAL.PROVIDE | typeof EVENT.SIGNAL.CANDIDATE
export type ChatEvents = typeof EVENT.CHAT.MESSAGE | typeof EVENT.CHAT.EMOTE
export type ScreenEvents = typeof EVENT.SCREEN.CONFIGURATIONS | typeof EVENT.SCREEN.RESOLUTION | typeof EVENT.SCREEN.SET

View File

@ -15,6 +15,7 @@ export type WebSocketMessages =
| WebSocketMessage
| SignalProvideMessage
| SignalAnswerMessage
| SignalCandidateMessage
| MemberListMessage
| MemberConnectMessage
| MemberDisconnectMessage
@ -26,6 +27,7 @@ export type WebSocketMessages =
export type WebSocketPayloads =
| SignalProvidePayload
| SignalAnswerPayload
| SignalCandidatePayload
| MemberListPayload
| Member
| ControlPayload
@ -78,6 +80,14 @@ export interface SignalAnswerPayload {
displayname: string
}
// signal/candidate
export interface SignalCandidateMessage extends WebSocketMessage, SignalCandidatePayload {
event: typeof EVENT.SIGNAL.CANDIDATE
}
export interface SignalCandidatePayload {
data: string
}
/*
MEMBER MESSAGES/PAYLOADS
*/