 
         nice_stream.on 'stateChanged', stateChanged stream
 
-        # mirroring
-
-        rtp = (stream) => (data) =>
-          stream.dtls_srtp.rtp data
-
-        dtls_srtp.on 'rtp', rtp(stream)
-
-        rtcp = (stream) => (data) =>
-          stream.dtls_srtp.rtcp data
-
-        dtls_srtp.on 'rtcp', rtcp(stream)
+        if profile == 'DTLS/SCTP'
+          console.log 'doing dtls stuff!', line
+
+          dtls = new Dtls(CERT_FILE, KEY_FILE)
+
+          nice_stream.on 'receive', (component, data) =>
+            console.log 'IN', data.length
+            stream.transport.decrypt(data)
+
+          dtls.on 'encrypted', (data) =>
+            console.log 'ENC', data.length
+            stream.nice.send(1, data)
+
+          dtls.on 'decrypted', (data) =>
+            console.log 'DEC', data.length
+            stream.transport.encrypt(data)
+
+          nice_stream.on 'stateChanged', (component, state) ->
+            console.log 'STATE', state
+            if component == 1 and state == 'ready'
+              console.log 'CON'
+              tick = () => stream.transport.tick()
+              @dtls_timer = setInterval tick, 100
+
+          stream.transport = dtls
+
+        else
+          # dtls srtp is assumed
+
+          dtls_srtp = new DtlsSrtp(nice_stream, CERT_FILE, KEY_FILE)
+
+          # mirroring
+          rtp = (stream) => (data) =>
+            stream.transport.rtp data
+
+          dtls_srtp.on 'rtp', rtp(stream)
+
+          rtcp = (stream) => (data) =>
+            stream.transport.rtcp data
+
+          dtls_srtp.on 'rtcp', rtcp(stream)
+
+          stream.transport = dtls_srtp
 
         # save payload types for rtpmux
 
-        rtp_types = rtp_types.concat(parseInt(type) for type in m[2].split(" "))
+        rtp_types = rtp_types.concat(parseInt(type) for type in types.split(" "))
 
       else if m = line.match(/a=mid:(.*)/)
         stream.mid = m[1]

    console.log 'closing echo'
    for _, stream of @streams
      stream.nice.close()
      stream.dtls_srtp.close()


        lines.splice i, 0, data
        i++

      if stream.needs_ice_cred and line.match(/a=.*/) and not line.match(/a=crypto.*/)
        credentials = stream.nice.getLocalCredentials()
        insert_line 'a=ice-ufrag:' + credentials.ufrag
        insert_line 'a=ice-pwd:' + credentials.pwd
        insert_line 'a=fingerprint:' + stream.transport.fingerprint()
        delete stream.needs_ice_cred

      if m = line.match(/m=(\w+) \S+ (\S+) (.*)/)
        # m-lines describe a media stream, create nice connections for them


        [_, id, profile, types] = m

        index = mline

        mline++

        nice_stream = nice.createStream(2)

        stream = {
          id: id
          index: index
          nice: nice_stream
          needs_ice_cred: true
        }

