Migrate Detach to interface

Relates to #20
This commit is contained in:
backkem 2019-04-01 20:16:18 +02:00
parent acb4a86f4b
commit 4e9085a705
2 changed files with 9 additions and 9 deletions

14
conn.go
View File

@ -51,7 +51,7 @@ type Conn struct {
config *connConfig config *connConfig
peerConnection *webrtc.PeerConnection peerConnection *webrtc.PeerConnection
initChannel *datachannel.DataChannel initChannel datachannel.ReadWriteCloser
lock sync.RWMutex lock sync.RWMutex
accept chan chan detachResult accept chan chan detachResult
@ -59,7 +59,7 @@ type Conn struct {
muxedConn smux.Conn muxedConn smux.Conn
} }
func newConn(config *connConfig, pc *webrtc.PeerConnection, initChannel *datachannel.DataChannel) *Conn { func newConn(config *connConfig, pc *webrtc.PeerConnection, initChannel datachannel.ReadWriteCloser) *Conn {
conn := &Conn{ conn := &Conn{
config: config, config: config,
peerConnection: pc, peerConnection: pc,
@ -147,7 +147,7 @@ func dial(ctx context.Context, config *connConfig) (*Conn, error) {
} }
type detachResult struct { type detachResult struct {
dc *datachannel.DataChannel dc datachannel.ReadWriteCloser
err error err error
} }
@ -271,7 +271,7 @@ func (c *Conn) useMuxer(conn net.Conn, muxer smux.Transport) error {
return nil return nil
} }
func (c *Conn) checkInitChannel() *datachannel.DataChannel { func (c *Conn) checkInitChannel() datachannel.ReadWriteCloser {
c.lock.Lock() c.lock.Lock()
defer c.lock.Unlock() defer c.lock.Unlock()
// Since a WebRTC offer can't be empty the offering side will have // Since a WebRTC offer can't be empty the offering side will have
@ -304,7 +304,7 @@ func (c *Conn) AcceptStream() (smux.Stream, error) {
return newStream(rawDC), nil return newStream(rawDC), nil
} }
func (c *Conn) awaitAccept() (*datachannel.DataChannel, error) { func (c *Conn) awaitAccept() (datachannel.ReadWriteCloser, error) {
detachRes, ok := <-c.accept detachRes, ok := <-c.accept
if !ok { if !ok {
return nil, errors.New("Conn closed") return nil, errors.New("Conn closed")
@ -356,9 +356,9 @@ func (c *Conn) Transport() tpt.Transport {
return c.config.transport return c.config.transport
} }
// dcWrapper wraps datachannel.DataChannel to form a net.Conn // dcWrapper wraps datachannel.ReadWriteCloser to form a net.Conn
type dcWrapper struct { type dcWrapper struct {
channel *datachannel.DataChannel channel datachannel.ReadWriteCloser
addr net.Addr addr net.Addr
} }

View File

@ -9,10 +9,10 @@ import (
// Stream is a bidirectional io pipe within a connection. // Stream is a bidirectional io pipe within a connection.
type Stream struct { type Stream struct {
channel *datachannel.DataChannel channel datachannel.ReadWriteCloser
} }
func newStream(channel *datachannel.DataChannel) *Stream { func newStream(channel datachannel.ReadWriteCloser) *Stream {
return &Stream{channel: channel} return &Stream{channel: channel}
} }