-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4843bab
commit eb1db6a
Showing
4 changed files
with
136 additions
and
43 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,47 @@ | ||
import RTCIceTransport from './RTCIceTransport.js'; | ||
|
||
export default class _RTCDtlsTransport extends EventTarget { | ||
#pc = null; | ||
#extraFunctions = null; | ||
#iceTransport = null; | ||
#state = null; | ||
|
||
onerror = createEmptyFunction(); | ||
onstatechange = createEmptyFunction(); | ||
onerror = null; | ||
onstatechange = null; | ||
|
||
constructor() { | ||
constructor({ pc, extraFunctions }) { | ||
super(); | ||
this.#pc = pc; | ||
this.#extraFunctions = extraFunctions; | ||
|
||
this.#iceTransport = new RTCIceTransport({ pc, extraFunctions }); | ||
|
||
// forward peerConnection events | ||
this.#pc.addEventListener('connectionstatechange', () => { | ||
this.dispatchEvent(new Event('statechange')); | ||
}); | ||
|
||
// forward events to properties | ||
this.addEventListener('statechange', (e) => { | ||
if (this.onstatechange) this.onstatechange(e); | ||
}); | ||
} | ||
|
||
get iceTransport() { | ||
return this.#iceTransport; | ||
} | ||
|
||
get state() { | ||
return this.#state; | ||
// reduce state from new, connecting, connected, disconnected, failed, closed, unknown | ||
// to RTCDtlsTRansport states new, connecting, connected, closed, failed | ||
let state = this.#pc ? this.#pc.connectionState : 'new'; | ||
if (state === 'disconnected' || state === 'unknown') { | ||
state = 'closed'; | ||
} | ||
return state; | ||
} | ||
|
||
getRemoteCertificates() { | ||
/** */ | ||
// TODO: implement | ||
return new ArrayBuffer(0); | ||
} | ||
} | ||
|
||
function createEmptyFunction() { | ||
return () => { | ||
/** */ | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,85 @@ | ||
import RTCIceCandidate from './RTCIceCandidate.js'; | ||
|
||
export default class _RTCIceTransport extends EventTarget { | ||
#pc = null; | ||
#extraFunctions = null; | ||
#component = null; | ||
#gatheringState = null; | ||
#role = null; | ||
#state = null; | ||
|
||
ongatheringstatechange = createEmptyFunction(); | ||
onselectedcandidatepairchange = createEmptyFunction(); | ||
onstatechange = createEmptyFunction(); | ||
ongatheringstatechange = null; | ||
onselectedcandidatepairchange = null; | ||
onstatechange = null; | ||
|
||
constructor() { | ||
constructor({ pc, extraFunctions }) { | ||
super(); | ||
this.#pc = pc; | ||
this.#extraFunctions = extraFunctions; | ||
|
||
// forward peerConnection events | ||
this.#pc.addEventListener('icegatheringstatechange', () => { | ||
this.dispatchEvent(new Event('gatheringstatechange')); | ||
}); | ||
this.#pc.addEventListener('iceconnectionstatechange', () => { | ||
console.log('*********'); | ||
this.dispatchEvent(new Event('statechange')); | ||
}); | ||
|
||
// forward events to properties | ||
this.addEventListener('gatheringstatechange', (e) => { | ||
if (this.ongatheringstatechange) this.ongatheringstatechange(e); | ||
}); | ||
this.addEventListener('statechange', (e) => { | ||
if (this.onstatechange) this.onstatechange(e); | ||
}); | ||
} | ||
|
||
get component() { | ||
// TODO: expose component from pc | ||
return this.#component; | ||
} | ||
|
||
get gatheringState() { | ||
return this.#gatheringState; | ||
return this.#pc ? this.#pc.iceGatheringState : 'new'; | ||
} | ||
|
||
get role() { | ||
// return controlled or controlling | ||
return this.#role; | ||
} | ||
|
||
get state() { | ||
return this.#state; | ||
return this.#pc ? this.#pc.iceConnectionState : 'new'; | ||
} | ||
|
||
getLocalCandidates() { | ||
/** */ | ||
return this.#pc ? this.#extraFunctions.localCandidates() : []; | ||
} | ||
|
||
getLocalParameters() { | ||
/** */ | ||
} | ||
|
||
getRemoteCandidates() { | ||
/** */ | ||
return this.#pc ? this.#extraFunctions.remoteCandidates() : []; | ||
} | ||
|
||
getRemoteParameters() { | ||
/** */ | ||
} | ||
|
||
getSelectedCandidatePair() { | ||
/** */ | ||
let cp = this.#extraFunctions.selectedCandidatePair(); | ||
if (!cp) return null; | ||
return { | ||
local: new RTCIceCandidate({ | ||
candidate: cp.local.candidate, | ||
sdpMid: cp.local.mid, | ||
}), | ||
remote: new RTCIceCandidate({ | ||
candidate: cp.remote.candidate, | ||
sdpMid: cp.remote.mid, | ||
}), | ||
}; | ||
} | ||
} | ||
|
||
function createEmptyFunction() { | ||
return () => { | ||
/** */ | ||
}; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,54 @@ | ||
import RTCDtlsTransport from './RTCDtlsTransport.js'; | ||
|
||
export default class _RTCSctpTransport extends EventTarget { | ||
#maxChannels = null; | ||
#maxMessageSize = null; | ||
#state = null; | ||
#pc = null; | ||
#extraFunctions = null; | ||
#transport = null; | ||
|
||
onstatechange = createEmptyFunction(); | ||
onstatechange = null; | ||
|
||
constructor(init = {}) { | ||
constructor({ pc, extraFunctions }) { | ||
super(); | ||
this.#pc = pc; | ||
this.#extraFunctions = extraFunctions; | ||
|
||
this.#transport = new RTCDtlsTransport({ pc, extraFunctions }); | ||
|
||
// forward peerConnection events | ||
this.#pc.addEventListener('connectionstatechange', () => { | ||
this.dispatchEvent(new Event('statechange')); | ||
}); | ||
|
||
// forward events to properties | ||
this.addEventListener('statechange', (e) => { | ||
if (this.onstatechange) this.onstatechange(e); | ||
}); | ||
} | ||
|
||
get maxChannels() { | ||
return this.#maxChannels; | ||
if (this.state !== 'connected') return null; | ||
return this.#pc ? this.#extraFunctions.maxDataChannelId() : 0; | ||
} | ||
|
||
get maxMessageSize() { | ||
return this.#maxMessageSize; | ||
// Default from libdatachannel | ||
// Change that after exposing pc.maxMessageSize | ||
return 256 * 1024; | ||
} | ||
|
||
get state() { | ||
return this.#state; | ||
// reduce state from new, connecting, connected, disconnected, failed, closed, unknown | ||
// to RTCSctpTransport states connecting, connected, closed | ||
let state = this.#pc.connectionState; | ||
if (state === 'new' || state === 'connecting') { | ||
state = 'connecting'; | ||
} else if (state === 'disconnected' || state === 'failed' || state === 'closed' || state === 'unknown') { | ||
state = 'closed'; | ||
} | ||
return state; | ||
} | ||
|
||
get transport() { | ||
return this.#transport; | ||
} | ||
} | ||
|
||
function createEmptyFunction() { | ||
return () => { | ||
/** */ | ||
}; | ||
} |