<commit_before>'use strict'

const Socket = require('./Socket')
const Connection = require('@xmpp/connection')
const xml = require('@xmpp/xml')

const NS_FRAMING = 'urn:ietf:params:xml:ns:xmpp-framing'

/* References
 * WebSocket protocol https://tools.ietf.org/html/rfc6455
 * WebSocket Web API https://html.spec.whatwg.org/multipage/comms.html#network
 * XMPP over WebSocket https://tools.ietf.org/html/rfc7395
*/

class ConnectionWebSocket extends Connection {
  // https://tools.ietf.org/html/rfc7395#section-3.6
  footer () {
    return xml.Element('close', {
      xmlns: NS_FRAMING,
    })
  }

  // https://tools.ietf.org/html/rfc7395#section-3.4
  headerElement () {
    const el = super.headerElement()
    el.name = 'open'
    el.attrs.xmlns = NS_FRAMING
    return el
  }

  socketParameters (uri) {
    return uri.match(/^wss?:\/\//) ? uri : undefined
  }
}

ConnectionWebSocket.prototype.Socket = Socket
ConnectionWebSocket.prototype.NS = 'jabber:client'
<commit_msg>Fixed WebSocket stream closing (#408)<commit_after>'use strict'

const Socket = require('./Socket')
const Connection = require('@xmpp/connection')
const xml = require('@xmpp/xml')

const NS_FRAMING = 'urn:ietf:params:xml:ns:xmpp-framing'

/* References
 * WebSocket protocol https://tools.ietf.org/html/rfc6455
 * WebSocket Web API https://html.spec.whatwg.org/multipage/comms.html#network
 * XMPP over WebSocket https://tools.ietf.org/html/rfc7395
*/

class ConnectionWebSocket extends Connection {
  // https://tools.ietf.org/html/rfc7395#section-3.6
  footer () {
    return new xml.Element('close', {
      xmlns: NS_FRAMING,
    })
  }

  // https://tools.ietf.org/html/rfc7395#section-3.4
  headerElement () {
    const el = super.headerElement()
    el.name = 'open'
    el.attrs.xmlns = NS_FRAMING
    return el
  }

  socketParameters (uri) {
    return uri.match(/^wss?:\/\//) ? uri : undefined
  }
}

ConnectionWebSocket.prototype.Socket = Socket
ConnectionWebSocket.prototype.NS = 'jabber:client'

{'fraction_non_alphanumeric': 0.15025125628140704, 'fraction_numerical': 0.021608040201005024, 'mean_word_length': 3.6737089201877935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6097663', 'n_tokens_mistral': 730, 'n_tokens_neox': 699, 'n_words': 119}