ran prettier

This commit is contained in:
2025-11-28 14:35:23 -05:00
parent eca9dfc631
commit 8fb108b04f
15 changed files with 3168 additions and 3166 deletions

View File

@@ -24,7 +24,7 @@ export default class PeerConnection implements IPeerConnectionOperations {
this._readOnlyConnectionState = new ReadOnlySubject(this._connectionState);
this._readOnlyIceGatheringState = new ReadOnlySubject(this._iceGatheringState);
this._readOnlyIceConnectionState = new ReadOnlySubject(this._iceConnectionState);
this.initialize();
}
@@ -68,7 +68,7 @@ export default class PeerConnection implements IPeerConnectionOperations {
public async createAnswer(options?: RTCAnswerOptions): Promise<RTCSessionDescriptionInit> {
try {
const answer = await this._peerConnection.createAnswer(options);
return answer;
} catch (error) {
throw new Error(`Failed to create answer [${error instanceof Error ? error.message : String(error)}]`);
@@ -127,12 +127,14 @@ export default class PeerConnection implements IPeerConnectionOperations {
this._iceConnectionState.value = peerConnection.iceConnectionState;
};
this._disposables.add(new Disposable(() => {
peerConnection.oniceconnectionstatechange = null;
peerConnection.onicegatheringstatechange = null;
peerConnection.onconnectionstatechange = null;
peerConnection.onsignalingstatechange = null;
}));
this._disposables.add(
new Disposable(() => {
peerConnection.oniceconnectionstatechange = null;
peerConnection.onicegatheringstatechange = null;
peerConnection.onconnectionstatechange = null;
peerConnection.onsignalingstatechange = null;
})
);
}
private setPeerConnectionEventListeners(peerConnection: RTCPeerConnection): void {
@@ -152,15 +154,17 @@ export default class PeerConnection implements IPeerConnectionOperations {
payload: event
});
}
};
};
peerConnection.onicecandidate = iceCandidateHandler;
peerConnection.ontrack = trackHandler;
this._disposables.add(new Disposable(() => {
peerConnection.onicecandidate = null;
peerConnection.ontrack = null;
}));
this._disposables.add(
new Disposable(() => {
peerConnection.onicecandidate = null;
peerConnection.ontrack = null;
})
);
}
private initialize(): void {

View File

@@ -1,48 +1,48 @@
import type { ICandidateMessage, IAnswerMessage, IOfferMessage, IMessage } from "./messaging/IMessage";
import { MessageKind } from "./messaging/MessageKind";
import type { ISignalingClient } from "./interfaces/ISignalingClient";
import type {ICandidateMessage, IAnswerMessage, IOfferMessage, IMessage} from './messaging/IMessage';
import {MessageKind} from './messaging/MessageKind';
import type {ISignalingClient} from './interfaces/ISignalingClient';
export default class SignalingServer implements ISignalingClient {
private readonly _webSocket: WebSocket;
private readonly _webSocket: WebSocket;
constructor(webSocket: WebSocket) {
this._webSocket = webSocket;
}
constructor(webSocket: WebSocket) {
this._webSocket = webSocket;
}
public on<T>(kind: MessageKind, callback: (message: IMessage<T>) => Promise<void>): void {
this._webSocket.addEventListener('message', (event) => {
const message = JSON.parse(event.data) as IMessage<T>;
public on<T>(kind: MessageKind, callback: (message: IMessage<T>) => Promise<void>): void {
this._webSocket.addEventListener('message', event => {
const message = JSON.parse(event.data) as IMessage<T>;
if (message.type === kind) {
callback(message);
}
});
}
if (message.type === kind) {
callback(message);
}
});
}
public async sendOffer(offer: RTCSessionDescriptionInit): Promise<void> {
const message: IOfferMessage = {
type: MessageKind.Offer,
payload: offer
};
public async sendOffer(offer: RTCSessionDescriptionInit): Promise<void> {
const message: IOfferMessage = {
type: MessageKind.Offer,
payload: offer
};
this._webSocket.send(JSON.stringify(message));
}
this._webSocket.send(JSON.stringify(message));
}
public async sendAnswer(answer: RTCSessionDescriptionInit): Promise<void> {
const message: IAnswerMessage = {
type: MessageKind.Answer,
payload: answer
};
public async sendAnswer(answer: RTCSessionDescriptionInit): Promise<void> {
const message: IAnswerMessage = {
type: MessageKind.Answer,
payload: answer
};
this._webSocket.send(JSON.stringify(message));
}
this._webSocket.send(JSON.stringify(message));
}
public async sendCandidate(candidate: RTCIceCandidateInit): Promise<void> {
const message: ICandidateMessage = {
type: MessageKind.Candidate,
payload: candidate
};
public async sendCandidate(candidate: RTCIceCandidateInit): Promise<void> {
const message: ICandidateMessage = {
type: MessageKind.Candidate,
payload: candidate
};
this._webSocket.send(JSON.stringify(message));
}
}
this._webSocket.send(JSON.stringify(message));
}
}

View File

@@ -1,8 +1,8 @@
import type {ILogger} from '@techniker-me/logger';
import {LoggerFactory} from '@techniker-me/logger';
import {ReadOnlySubject, Subject, type IEvent} from '@techniker-me/tools';
import type { IPeerConnectionOperations } from './interfaces/IPeerConnectionOperations';
import type { ISignalingClient } from './interfaces/ISignalingClient';
import type {IPeerConnectionOperations} from './interfaces/IPeerConnectionOperations';
import type {ISignalingClient} from './interfaces/ISignalingClient';
/**
* User class - manages local and remote media streams
@@ -10,71 +10,71 @@ import type { ISignalingClient } from './interfaces/ISignalingClient';
* Follows Dependency Inversion Principle - depends on abstractions (interfaces)
*/
export default class User {
private readonly _logger: ILogger = LoggerFactory.getLogger('User');
private readonly _localVideoElement: HTMLVideoElement;
private readonly _remoteVideoElement: HTMLVideoElement;
private readonly _peerConnection: IPeerConnectionOperations;
private readonly _signalingClient: ISignalingClient;
private readonly _mediaStream: Subject<MediaStream | null> = new Subject(null);
private readonly _readOnlyMediaStream: ReadOnlySubject<MediaStream | null> = new ReadOnlySubject(this._mediaStream);
private readonly _logger: ILogger = LoggerFactory.getLogger('User');
private readonly _localVideoElement: HTMLVideoElement;
private readonly _remoteVideoElement: HTMLVideoElement;
private readonly _peerConnection: IPeerConnectionOperations;
private readonly _signalingClient: ISignalingClient;
private readonly _mediaStream: Subject<MediaStream | null> = new Subject(null);
private readonly _readOnlyMediaStream: ReadOnlySubject<MediaStream | null> = new ReadOnlySubject(this._mediaStream);
constructor(localVideoElement: HTMLVideoElement, remoteVideoElement: HTMLVideoElement, peerConnection: IPeerConnectionOperations, signalingClient: ISignalingClient) {
this._localVideoElement = localVideoElement;
this._remoteVideoElement = remoteVideoElement;
this._peerConnection = peerConnection;
this._signalingClient = signalingClient;
this.initialize();
}
constructor(localVideoElement: HTMLVideoElement, remoteVideoElement: HTMLVideoElement, peerConnection: IPeerConnectionOperations, signalingClient: ISignalingClient) {
this._localVideoElement = localVideoElement;
this._remoteVideoElement = remoteVideoElement;
this._peerConnection = peerConnection;
this._signalingClient = signalingClient;
this.initialize();
}
get videoElement(): HTMLVideoElement {
return this._localVideoElement;
}
get videoElement(): HTMLVideoElement {
return this._localVideoElement;
}
get peerConnection(): IPeerConnectionOperations {
return this._peerConnection;
}
get peerConnection(): IPeerConnectionOperations {
return this._peerConnection;
}
get mediaStream(): ReadOnlySubject<MediaStream | null> {
return this._readOnlyMediaStream;
}
get mediaStream(): ReadOnlySubject<MediaStream | null> {
return this._readOnlyMediaStream;
}
public async startLocalMedia(): Promise<void> {
const mediaStream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true });
this._peerConnection.addMediaStream(mediaStream);
this._mediaStream.value = mediaStream;
this._localVideoElement.srcObject = mediaStream;
this._logger.info('Local media started');
}
public async startLocalMedia(): Promise<void> {
const mediaStream = await navigator.mediaDevices.getUserMedia({audio: true, video: true});
public async stopLocalMedia(): Promise<void> {
this._mediaStream.value?.getTracks().forEach(track => {
track.stop();
});
this._mediaStream.value = null;
this._localVideoElement.srcObject = null;
}
this._peerConnection.addMediaStream(mediaStream);
private initialize(): void {
this._peerConnection.on<RTCPeerConnectionIceEvent>('icecandidate', (event: IEvent<RTCPeerConnectionIceEvent>) => {
// Only send candidate if it exists (null means ICE gathering is complete)
if (event.payload?.candidate) {
this._signalingClient.sendCandidate(event.payload.candidate);
}
});
this._peerConnection.on<RTCTrackEvent>('track', (event: IEvent<RTCTrackEvent>) => {
if (!event.payload) {
return;
}
this._mediaStream.value = mediaStream;
this._localVideoElement.srcObject = mediaStream;
this._logger.info('Local media started');
}
console.log('Track event', event);
public async stopLocalMedia(): Promise<void> {
this._mediaStream.value?.getTracks().forEach(track => {
track.stop();
});
this._mediaStream.value = null;
this._localVideoElement.srcObject = null;
}
if (event.payload.streams?.length === 0) {
return;
}
private initialize(): void {
this._peerConnection.on<RTCPeerConnectionIceEvent>('icecandidate', (event: IEvent<RTCPeerConnectionIceEvent>) => {
// Only send candidate if it exists (null means ICE gathering is complete)
if (event.payload?.candidate) {
this._signalingClient.sendCandidate(event.payload.candidate);
}
});
this._peerConnection.on<RTCTrackEvent>('track', (event: IEvent<RTCTrackEvent>) => {
if (!event.payload) {
return;
}
this._remoteVideoElement.srcObject = event.payload.streams[0];
});
}
}
console.log('Track event', event);
if (event.payload.streams?.length === 0) {
return;
}
this._remoteVideoElement.srcObject = event.payload.streams[0];
});
}
}

View File

@@ -1,11 +1,11 @@
import { Caller } from './Caller';
import { Callee } from './Callee';
import type { ISignalingClient } from '../interfaces/ISignalingClient';
import type { IPeerConnectionOperations } from '../interfaces/IPeerConnectionOperations';
import { MessageKind } from '../messaging/MessageKind';
import type { IMessage } from '../messaging/IMessage';
import type { ILogger } from '@techniker-me/logger';
import { LoggerFactory } from '@techniker-me/logger';
import {Caller} from './Caller';
import {Callee} from './Callee';
import type {ISignalingClient} from '../interfaces/ISignalingClient';
import type {IPeerConnectionOperations} from '../interfaces/IPeerConnectionOperations';
import {MessageKind} from '../messaging/MessageKind';
import type {IMessage} from '../messaging/IMessage';
import type {ILogger} from '@techniker-me/logger';
import {LoggerFactory} from '@techniker-me/logger';
/**
* CallCoordinator - coordinates between Caller and Callee roles
@@ -20,15 +20,12 @@ export class CallCoordinator {
private readonly _peerConnection: IPeerConnectionOperations;
private _lastReceivedOffer: RTCSessionDescriptionInit | null = null;
constructor(
signalingClient: ISignalingClient,
peerConnection: IPeerConnectionOperations
) {
constructor(signalingClient: ISignalingClient, peerConnection: IPeerConnectionOperations) {
this._signalingClient = signalingClient;
this._peerConnection = peerConnection;
this._caller = new Caller(signalingClient, peerConnection);
this._callee = new Callee(signalingClient, peerConnection);
this.setupMessageHandlers();
}
@@ -49,26 +46,26 @@ export class CallCoordinator {
*/
public async createAndSendAnswer(): Promise<void> {
const currentState = this._peerConnection.getSignalingState();
// Verify we have a remote offer
if (currentState !== 'have-remote-offer' && currentState !== 'have-remote-pranswer') {
throw new Error('Cannot send answer: no remote offer received. Current state: ' + currentState);
}
if (!this._lastReceivedOffer) {
throw new Error('Cannot send answer: no offer stored');
}
this._logger.info('Creating and sending answer manually...');
// Step 1: Create Answer (remote description was already set when offer was received)
const answer = await this._peerConnection.createAnswer();
this._logger.info('Answer created');
// Step 2: Set local description to Answer
await this._peerConnection.setLocalDescription(answer);
this._logger.info('Local description set to answer');
// Step 3: Send Answer to signaling server
await this._signalingClient.sendAnswer(answer);
this._logger.info('Answer sent to signaling server');
@@ -81,40 +78,33 @@ export class CallCoordinator {
// Handle incoming offers (when acting as callee)
// Only set remote description - don't automatically create/send answer
// The answer will be sent when the user clicks the "Send Answer" button
this._signalingClient.on<RTCSessionDescriptionInit>(
MessageKind.Offer,
async (message: IMessage<RTCSessionDescriptionInit>) => {
// Only handle offer if we're not the caller (don't have local offer)
const currentState = this._peerConnection.getSignalingState();
if (currentState === 'have-local-offer' || currentState === 'have-local-pranswer') {
this._logger.info('Already have local offer, ignoring incoming offer');
return;
}
this._logger.info('Received offer, setting remote description (waiting for manual answer)');
this._lastReceivedOffer = message.payload;
// Only set the remote description - don't create/send answer yet
// This allows the callee to manually click "Send Answer" button
await this._peerConnection.setRemoteDescription(message.payload);
this._signalingClient.on<RTCSessionDescriptionInit>(MessageKind.Offer, async (message: IMessage<RTCSessionDescriptionInit>) => {
// Only handle offer if we're not the caller (don't have local offer)
const currentState = this._peerConnection.getSignalingState();
if (currentState === 'have-local-offer' || currentState === 'have-local-pranswer') {
this._logger.info('Already have local offer, ignoring incoming offer');
return;
}
);
this._logger.info('Received offer, setting remote description (waiting for manual answer)');
this._lastReceivedOffer = message.payload;
// Only set the remote description - don't create/send answer yet
// This allows the callee to manually click "Send Answer" button
await this._peerConnection.setRemoteDescription(message.payload);
});
// Handle incoming answers (when acting as caller)
this._signalingClient.on<RTCSessionDescriptionInit>(
MessageKind.Answer,
async (message: IMessage<RTCSessionDescriptionInit>) => {
// Only handle answer if we're the caller (have local offer)
const currentState = this._peerConnection.getSignalingState();
if (currentState !== 'have-local-offer' && currentState !== 'have-local-pranswer') {
this._logger.info('Not in caller state, ignoring incoming answer');
return;
}
this._logger.info('Received answer, acting as caller');
await this._caller.handleAnswer(message.payload);
this._signalingClient.on<RTCSessionDescriptionInit>(MessageKind.Answer, async (message: IMessage<RTCSessionDescriptionInit>) => {
// Only handle answer if we're the caller (have local offer)
const currentState = this._peerConnection.getSignalingState();
if (currentState !== 'have-local-offer' && currentState !== 'have-local-pranswer') {
this._logger.info('Not in caller state, ignoring incoming answer');
return;
}
);
this._logger.info('Received answer, acting as caller');
await this._caller.handleAnswer(message.payload);
});
}
}

View File

@@ -1,7 +1,7 @@
import type { ISignalingClient } from '../interfaces/ISignalingClient';
import type { IPeerConnectionOperations } from '../interfaces/IPeerConnectionOperations';
import type { ILogger } from '@techniker-me/logger';
import { LoggerFactory } from '@techniker-me/logger';
import type {ISignalingClient} from '../interfaces/ISignalingClient';
import type {IPeerConnectionOperations} from '../interfaces/IPeerConnectionOperations';
import type {ILogger} from '@techniker-me/logger';
import {LoggerFactory} from '@techniker-me/logger';
/**
* Callee class - responsible for receiving and responding to WebRTC calls
@@ -13,10 +13,7 @@ export class Callee {
private readonly _signalingClient: ISignalingClient;
private readonly _peerConnection: IPeerConnectionOperations;
constructor(
signalingClient: ISignalingClient,
peerConnection: IPeerConnectionOperations
) {
constructor(signalingClient: ISignalingClient, peerConnection: IPeerConnectionOperations) {
this._signalingClient = signalingClient;
this._peerConnection = peerConnection;
}
@@ -32,19 +29,19 @@ export class Callee {
public async handleOffer(offer: RTCSessionDescriptionInit): Promise<void> {
try {
this._logger.info('Handling offer from caller...');
// Step 1: Set remote description to offer
await this._peerConnection.setRemoteDescription(offer);
this._logger.info('Remote description set to offer');
// Step 2: Create Answer
const answer = await this._peerConnection.createAnswer();
this._logger.info('Answer created');
// Step 3: Set local description to Answer
await this._peerConnection.setLocalDescription(answer);
this._logger.info('Local description set to answer');
// Step 4: Send Answer to signaling server
await this._signalingClient.sendAnswer(answer);
this._logger.info('Answer sent to signaling server');
@@ -54,4 +51,3 @@ export class Callee {
}
}
}

View File

@@ -1,7 +1,7 @@
import type { ISignalingClient } from '../interfaces/ISignalingClient';
import type { IPeerConnectionOperations } from '../interfaces/IPeerConnectionOperations';
import type { ILogger } from '@techniker-me/logger';
import { LoggerFactory } from '@techniker-me/logger';
import type {ISignalingClient} from '../interfaces/ISignalingClient';
import type {IPeerConnectionOperations} from '../interfaces/IPeerConnectionOperations';
import type {ILogger} from '@techniker-me/logger';
import {LoggerFactory} from '@techniker-me/logger';
/**
* Caller class - responsible for initiating WebRTC calls
@@ -13,10 +13,7 @@ export class Caller {
private readonly _signalingClient: ISignalingClient;
private readonly _peerConnection: IPeerConnectionOperations;
constructor(
signalingClient: ISignalingClient,
peerConnection: IPeerConnectionOperations
) {
constructor(signalingClient: ISignalingClient, peerConnection: IPeerConnectionOperations) {
this._signalingClient = signalingClient;
this._peerConnection = peerConnection;
}
@@ -30,14 +27,14 @@ export class Caller {
public async createAndSendOffer(): Promise<void> {
try {
this._logger.info('Creating offer...');
// Step 1: Create Offer
const offer = await this._peerConnection.createOffer();
// Step 2: Set local description to offer
await this._peerConnection.setLocalDescription(offer);
this._logger.info('Local description set to offer');
// Step 3: Send Offer to signaling server
await this._signalingClient.sendOffer(offer);
this._logger.info('Offer sent to signaling server');
@@ -54,7 +51,7 @@ export class Caller {
public async handleAnswer(answer: RTCSessionDescriptionInit): Promise<void> {
try {
this._logger.info('Handling answer from callee...');
// Set Answer as remote description
await this._peerConnection.setRemoteDescription(answer);
this._logger.info('Answer set as remote description');
@@ -64,4 +61,3 @@ export class Caller {
}
}
}

View File

@@ -1,4 +1,4 @@
import type { IEvent, IDisposable } from '@techniker-me/tools';
import type {IEvent, IDisposable} from '@techniker-me/tools';
/**
* Interface for peer connection operations
@@ -44,4 +44,3 @@ export interface IPeerConnectionOperations {
*/
on<T>(event: string, callback: (event: IEvent<T>) => void | Promise<void>): IDisposable;
}

View File

@@ -1,5 +1,5 @@
import type { IMessage } from '../messaging/IMessage';
import { MessageKind } from '../messaging/MessageKind';
import type {IMessage} from '../messaging/IMessage';
import {MessageKind} from '../messaging/MessageKind';
/**
* Interface for signaling client operations
@@ -26,4 +26,3 @@ export interface ISignalingClient {
*/
sendCandidate(candidate: RTCIceCandidateInit): Promise<void>;
}

View File

@@ -1,10 +1,10 @@
import PeerConnection from './PeerConnection';
import User from './User';
import SignalingServer from './SignalingServer';
import { CallCoordinator } from './call/CallCoordinator';
import { MessageKind } from './messaging/MessageKind';
import type { IMessage } from './messaging/IMessage';
import type { ISignalingClient } from './interfaces/ISignalingClient';
import {CallCoordinator} from './call/CallCoordinator';
import {MessageKind} from './messaging/MessageKind';
import type {IMessage} from './messaging/IMessage';
import type {ISignalingClient} from './interfaces/ISignalingClient';
type Elements = {
localVideo: HTMLVideoElement;
@@ -16,7 +16,7 @@ type Elements = {
iceConnectionStateValue: HTMLSpanElement;
iceGatheringStateValue: HTMLSpanElement;
connectionStateValue: HTMLSpanElement;
}
};
const elements: Elements = {
localVideo: document.getElementById('local-video') as HTMLVideoElement,
@@ -28,7 +28,7 @@ const elements: Elements = {
iceConnectionStateValue: document.getElementById('ice-connection-state-value') as HTMLSpanElement,
iceGatheringStateValue: document.getElementById('ice-gathering-state-value') as HTMLSpanElement,
connectionStateValue: document.getElementById('connection-state-value') as HTMLSpanElement
}
};
// Initialize WebSocket and signaling server
const websocket = new WebSocket(`ws://${window.location.hostname}:3000/ws`);
@@ -57,9 +57,9 @@ signalingServer.on<RTCIceCandidateInit>(MessageKind.Candidate, async (message: I
});
// Setup UI state subscriptions
peerConnection.signalingState.subscribe((state) => {
peerConnection.signalingState.subscribe(state => {
elements.signalingStateValue.textContent = state;
// Enable send answer button when remote offer is received
if (state === 'have-remote-offer' || state === 'have-remote-pranswer') {
elements.sendAnswerButton.disabled = false;
@@ -68,15 +68,15 @@ peerConnection.signalingState.subscribe((state) => {
}
});
peerConnection.iceConnectionState.subscribe((state) => {
peerConnection.iceConnectionState.subscribe(state => {
elements.iceConnectionStateValue.textContent = state;
});
peerConnection.iceGatheringState.subscribe((state) => {
peerConnection.iceGatheringState.subscribe(state => {
elements.iceGatheringStateValue.textContent = state;
});
});
peerConnection.connectionState.subscribe((state) => {
peerConnection.connectionState.subscribe(state => {
elements.connectionStateValue.textContent = state;
});
@@ -103,10 +103,10 @@ elements.sendAnswerButton.addEventListener('click', async () => {
await user.startLocalMedia();
elements.startLocalMediaButton.disabled = true;
}
await callCoordinator.createAndSendAnswer();
elements.sendAnswerButton.disabled = true;
} catch (error) {
console.error('Failed to send answer', error);
}
});
});

View File

@@ -1,24 +1,23 @@
import type {MessageType} from './MessageKind';
export interface IMessage<T> {
type: MessageType;
payload: T;
type: MessageType;
payload: T;
}
export type IOfferMessage = {
type: 'offer';
payload: RTCSessionDescriptionInit;
}
type: 'offer';
payload: RTCSessionDescriptionInit;
};
export type IAnswerMessage = {
type: 'answer';
payload: RTCSessionDescriptionInit;
}
type: 'answer';
payload: RTCSessionDescriptionInit;
};
export type ICandidateMessage = {
type: 'candidate';
payload: RTCIceCandidateInit;
}
export type ICandidateMessage = {
type: 'candidate';
payload: RTCIceCandidateInit;
};
export type Message = IOfferMessage | IAnswerMessage | ICandidateMessage;
export type Message = IOfferMessage | IAnswerMessage | ICandidateMessage;

View File

@@ -1,32 +1,32 @@
export enum MessageKind {
Offer = 0,
Answer = 1,
Candidate = 2
Offer = 0,
Answer = 1,
Candidate = 2
}
export type MessageKindType = 'offer' | 'answer' | 'candidate';
export type MessageType = MessageKindType;
export class MessageKindMapping {
public static convertMessageKindToMessageType(messageKind: MessageKind): MessageType {
switch (messageKind) {
case MessageKind.Offer:
return 'offer';
case MessageKind.Answer:
return 'answer';
case MessageKind.Candidate:
return 'candidate';
}
public static convertMessageKindToMessageType(messageKind: MessageKind): MessageType {
switch (messageKind) {
case MessageKind.Offer:
return 'offer';
case MessageKind.Answer:
return 'answer';
case MessageKind.Candidate:
return 'candidate';
}
}
public static convertMessageTypeToMessageKind(messageType: MessageType): MessageKind {
switch (messageType) {
case 'offer':
return MessageKind.Offer;
case 'answer':
return MessageKind.Answer;
case 'candidate':
return MessageKind.Candidate;
}
public static convertMessageTypeToMessageKind(messageType: MessageType): MessageKind {
switch (messageType) {
case 'offer':
return MessageKind.Offer;
case 'answer':
return MessageKind.Answer;
case 'candidate':
return MessageKind.Candidate;
}
}
}
}