Last active
August 1, 2020 01:20
-
-
Save kino6052/4e720807c647847d904bb2d132f9bbe9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Client { | |
private id = generateId(4, 4); | |
// Channels | |
private dataChannels: { [id: string]: RTCDataChannel } = {}; | |
private streams: { [id: string]: MediaStream[] } = {}; | |
// Agents | |
private BroadcastingAgent = new BroadcastingAgent( | |
this.id, | |
CommunicationSubject | |
); | |
private RTCMessagingAgent = new RTCMessagingAgent(this.BroadcastingAgent); | |
private ConnectionManager = new ConnectionManager(this.RTCMessagingAgent); | |
// Subjects | |
private OnDataChannelMessageSubject = new Subject<[string, string]>(); | |
private OnDataChannelSubject = new Subject<[string, RTCDataChannel]>(); | |
private OnStreamSubject = new Subject<[string, MediaStream]>(); | |
constructor() { | |
this.OnDataChannelMessageSubject.subscribe( | |
this.onDataChannelMessageSubjectHandler | |
); | |
this.ConnectionManager.OnConnectionCreatedSubject.subscribe( | |
this.onConnectionCreatedHandler | |
); | |
this.ConnectionManager.OnStreamSubject.subscribe(this.onStreamHandler); | |
this.BroadcastingAgent.sendGreeting(); | |
} | |
// Connection | |
onConnectionCreatedHandler = (message: [string, RTCPeerConnection]) => { | |
// ... | |
}; | |
// Stream | |
addStreamToConnection = (connection: RTCPeerConnection) => { | |
// ... | |
}; | |
addStream = (id: string, stream: MediaStream) => { | |
// ... | |
}; | |
onStreamHandler = (stream: MediaStream) => { | |
// ... | |
}; | |
onTrackHandler = (id: string) => (ev: RTCTrackEvent) => { | |
// ... | |
}; | |
// Data Channel | |
sendDataToChannel = (id: string, message: string) => { | |
// ... | |
}; | |
onDataChannelHandler = (id: string) => (ev: RTCDataChannelEvent) => { | |
// ... | |
}; | |
onDataChannelMessageHandler = (id: string) => (ev: MessageEvent) => { | |
// ... | |
}; | |
onDataChannelMessageSubjectHandler = (message: [string, string]) => { | |
// ... | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment