mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
webrtc connected on data channel connected.
This commit is contained in:
parent
c179ad4c8d
commit
710675f4fa
@ -32,7 +32,12 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get connected() {
|
get connected() {
|
||||||
return typeof this._peer !== 'undefined' && ['connected', 'checking', 'completed'].includes(this._state)
|
return (
|
||||||
|
typeof this._peer !== 'undefined' &&
|
||||||
|
['connected', 'checking', 'completed'].includes(this._state) &&
|
||||||
|
typeof this._channel !== 'undefined' &&
|
||||||
|
this._channel.readyState == 'open'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async connect(sdp: string, lite: boolean, servers: string[]): Promise<string> {
|
public async connect(sdp: string, lite: boolean, servers: string[]): Promise<string> {
|
||||||
@ -68,11 +73,6 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
|
|||||||
this._log.debug(`peer ice connection state changed: ${this._peer!.iceConnectionState}`)
|
this._log.debug(`peer ice connection state changed: ${this._peer!.iceConnectionState}`)
|
||||||
|
|
||||||
switch (this._state) {
|
switch (this._state) {
|
||||||
case 'checking':
|
|
||||||
break
|
|
||||||
case 'connected':
|
|
||||||
this.onConnected()
|
|
||||||
break
|
|
||||||
case 'failed':
|
case 'failed':
|
||||||
this.onDisconnected(new Error('peer failed'))
|
this.onDisconnected(new Error('peer failed'))
|
||||||
break
|
break
|
||||||
@ -89,6 +89,7 @@ export class NekoWebRTC extends EventEmitter<NekoWebRTCEvents> {
|
|||||||
this._channel = this._peer.createDataChannel('data')
|
this._channel = this._peer.createDataChannel('data')
|
||||||
this._channel.onerror = this.onDisconnected.bind(this, new Error('peer data channel error'))
|
this._channel.onerror = this.onDisconnected.bind(this, new Error('peer data channel error'))
|
||||||
this._channel.onmessage = this.onData.bind(this)
|
this._channel.onmessage = this.onData.bind(this)
|
||||||
|
this._channel.onopen = this.onConnected.bind(this)
|
||||||
this._channel.onclose = this.onDisconnected.bind(this, new Error('peer data channel closed'))
|
this._channel.onclose = this.onDisconnected.bind(this, new Error('peer data channel closed'))
|
||||||
|
|
||||||
this._peer.setRemoteDescription({ type: 'offer', sdp })
|
this._peer.setRemoteDescription({ type: 'offer', sdp })
|
||||||
|
Loading…
Reference in New Issue
Block a user