Skip to content

Fix rtcerror typing #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Subscribe to events using `network.on(eventName, callback)`:
- `'error'`: Network error occurred
- `'connected'`: New peer connected
- `'disconnected'`: Peer disconnected
- `'rtcerror'`: WebRTC error occurred (callback receives `RTCErrorEvent`)

#### Lobby Events
- `'lobby'`: Lobby created/joined
Expand Down
2 changes: 1 addition & 1 deletion example/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ n.on('lobby', code => {
})

n.on('signalingerror', console.error.bind(console.error))
n.on('rtcerror', console.error.bind(console.error))
n.on('rtcerror', (e: RTCErrorEvent) => console.error(e))

n.on('connecting', peer => { log(`peer connecting ${peer.id}`) })
n.on('disconnected', peer => {
Expand Down
2 changes: 1 addition & 1 deletion lib/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface NetworkListeners {
failed: () => void | Promise<void>
message: (peer: Peer, channel: string, data: string | Blob | ArrayBuffer | ArrayBufferView) => void | Promise<void>
close: (reason?: string) => void | Promise<void>
rtcerror: (e: Event) => void | Promise<void> // TODO: Figure out how to make this e type be RTCErrorEvent
rtcerror: (e: RTCErrorEvent) => void | Promise<void>
signalingerror: (e: SignalingError) => void | Promise<void>
}

Expand Down
2 changes: 1 addition & 1 deletion lib/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export default class Peer {
}
}

private onError (e: Event): void {
private onError (e: RTCErrorEvent): void {
this.network.emit('rtcerror', e)
if (this.network.listenerCount('rtcerror') === 0) {
console.error('rtcerror not handled:', e)
Expand Down