How to use ltx - 10 common examples

To help you get started, we’ve selected a few ltx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kartikrustagi / nodejs-xmpp-server / node_modules / node-xmpp / lib / xmpp / stream_parser.js View on Github external
this.parser.addListener('startElement', function(name, attrs) {
        // TODO: refuse anything but 
        if (!self.element && name == 'stream:stream') {
			//console.log("StreamParser : emitting start");
			//'start' event is captured by Connection (startParser)
            self.emit('start', attrs);
        } else {
	    var child;
            if (!self.element) {
                /* A new stanza */
		child = new Stanza(name, attrs);
                self.element = child;
                self.bytesParsedOnStanzaBegin = self.bytesParsed;
            } else {
                /* A child element of a stanza */
		child = new ltx.Element(name, attrs);
                self.element = self.element.cnode(child);
            }
        }
    });
github fabioberger / Mobile-Live-Chat-Support-Server / xmpp-server / modules / message.js View on Github external
client.on('stanza', function(stz) {

            // Parse stanza and check that it is of type message
            var stanza = ltx.parse(stz.toString());
            if (stanza.is('message') && stanza.attrs.type !== 'error') {

                var agentUsername = stanza.attrs.from.split("@")[0]; //isolate username
                var customerId = stanza.attrs.to.split("@")[0]; // isolate customerId

                // If message has body, send it to the customer
                if(stanza.getChild('body') !== undefined) {
                    var content = stanza.getChildText('body');
                    relay.agentMessage(customerId, content);
                } else if(stanza.getChild('composing') !== undefined) {
                    // Notify customer that agent is typing
                    //console.log('Agent is typing');
                    relay.agentStatus(agentUsername, 'composing');
                } else if(stanza.getChild('paused') !== undefined) {
                    // Notify customer that agent has paused
                    //console.log('Agent is paused');
github webinos / Webinos-Platform / webinos / common / xmpp / lib / xmpp.js View on Github external
resultQuery.c('identity', {'category': 'client', 'type': 'webinos'});
	
    	for (var i in currentFeatures) {
    	    logger.trace('key found: ' + currentFeatures[i]);
    	    var splitted = currentFeatures[i].split('#');
    	    var id = splitted[splitted.length - 1];
	    
    	    logger.trace('Feature id found: ' + id);
	    
    	    if (id && this.sharedFeatures[id]) {
    	        // a webinos feature
    	        logger.trace('Feature found: ' + id);
        	    var feature = this.sharedFeatures[id];

                var instanceNode = new ltx.Element('instance', {'xmlns': 'webinos:rpc#disco', 'id': feature.id });
                instanceNode.cnode(new ltx.Element('displayName').t(feature.displayName));
                instanceNode.cnode(new ltx.Element('description').t(feature.description));

                var featureNode = new ltx.Element('feature', {'var': feature.ns});
                featureNode.cnode(instanceNode);
        		resultQuery.cnode(featureNode);
    	    } else {
    	        // an xmpp feature
    	        var feature = currentFeatures[i];

                var featureNode = new ltx.Element('feature', {'var': feature});
        		resultQuery.cnode(featureNode);
    	    }
    	}
	
    	var result = new xmpp.Element('iq', { 'to': stanza.attrs.from, 'type': 'result', 'id': stanza.attrs.id });
    	result.cnode(resultQuery);
github xmppjs / xmpp.js / lib / node-xmpp-core / lib / stream_parser.js View on Github external
function StreamParser(maxStanzaSize) {
    EventEmitter.call(this)

    var self = this
    this.parser = new ltx.bestSaxParser()

    /* Count traffic for entire life-time */
    this.bytesParsed = 0
    this.maxStanzaSize = maxStanzaSize
    /* Will be reset upon first stanza, but enforce maxStanzaSize until it is parsed */
    this.bytesParsedOnStanzaBegin = 0

    this.parser.addListener(
        'startElement',
        function(name, attrs) {
            // TODO: refuse anything but 
            if (!self.element && (name === 'stream:stream')) {
                self.emit('streamStart', attrs)
            } else {
                var child
                if (!self.element) {
github xmppjs / radiowave / lib / components / Xep0060-pubsub / modules / Publish.js View on Github external
Publish.prototype.buildPublishedStanza = function (node, items) {
  // send response to sender
  var publishDetail = new ltx.Element('publish', {
    node: node.name
  });
  publishDetail.children = items;

  var detail = new ltx.Element(
    'pubsub', {
      'xmlns': 'http://jabber.org/protocol/pubsub'
    }).cnode(publishDetail).up();

  return detail;
};
github microsoft / azure-pipelines-tasks / Tasks / Common / packaging-common / nuget / Utility.ts View on Github external
// strip BOM; xml parser doesn't like it
    if (xmlString.charCodeAt(0) === 0xFEFF) {
        xmlString = xmlString.substr(1);
    }

    // parse sources xml
    let xml: ltx.Element;
    try {
        xml = ltx.parse(xmlString);
    } catch (e) {
        throw new Error(tl.loc("NGCommon_NuGetConfigIsInvalid", configPath));
    }

    // give clearer errors if the user has set an invalid nuget.config
    if(!xml.nameEquals(new ltx.Element("configuration"))) {
        if(xml.nameEquals(new ltx.Element("packages"))) {
            throw new Error(tl.loc(
                "NGCommon_NuGetConfigIsPackagesConfig",
                configPath,
                tl.getVariable("Task.DisplayName")));
        }
        else {
            throw new Error(tl.loc("NGCommon_NuGetConfigIsInvalid", configPath));
        }
    }

    // check that the config contains packageSources entries
    let hasSources = false;
    let packageSources = xml.getChild("packageSources");
    let addPackageSources: ltx.Element[];
    if (packageSources) {
github microsoft / azure-pipelines-tasks / Tasks / Common / packaging-common / nuget / NuGetXmlHelper.ts View on Github external
private static _updateXmlFile(xmlPath: string, updateFn: (xml: any) => any): void {
        let xmlString = fs.readFileSync(xmlPath).toString();

        // strip BOM; xml parser doesn't like it
        if (xmlString.charCodeAt(0) === 0xFEFF) {
            xmlString = xmlString.substr(1);
        }

        let xml = ltx.parse(xmlString);
        xml = updateFn(xml);
        fs.writeFileSync(xmlPath, xml.root().toString());
    }
github xmppjs / radiowave / test / rfc3921-ch07.js View on Github external
it('7.4. Adding a Roster Item', function (done) {
      var id = 'add-roaster-item';
      var el = ltx.parse("");
      var returnType = 'result';

      var stanza = generateRoasterStanza(helper.userJulia.jid, el, id);

      helper.sendMessageWithRomeo(stanza.root()).then(function (stanza) {
        try {
          assert.equal(stanza.is('iq'), true, 'wrong stanza ' + stanza.root().toString());
          assert.equal(stanza.attrs.type, returnType);
          assert.equal(stanza.attrs.id, id);
          done();
        } catch (err) {
          done(err);
        }
      }).catch(function (err) {
        done(err);
      });
github buddycloud / buddycloud-http-api / test / content_item.js View on Github external
tutil.get(options, function(res, body) {
        res.statusCode.should.equal(200);
        var entry = ltx.parse(body);

        entry.is('entry').should.be.true;
        entry.attrs.xmlns.should.equal(atom.ns);
        entry.getChildText('id').should.equal('foo');
        entry.getChild('author').getChildText('name')
            .should.equal('alice@localhost');
        entry.getChildText('content').should.equal('bar');
        entry.getChild('title').should.exist;

        done();
      }).on('error', done);
    });
github buddycloud / buddycloud-http-api / test / content_feed.js View on Github external
tutil.get(options, function(res, body) {
        res.statusCode.should.equal(200);
        var feed = ltx.parse(body);
        var entries = feed.getChildren('entry', atom.ns)
        entries.length.should.equal(2);
        entries[0].getChildText('id').should.equal('1');
        entries[1].getChildText('id').should.equal('2');
        done();
      }).on('error', done);
    });