unjingle.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. var strophe = require("./strophe/strophe.js").Strophe;
  2. var Strophe = strophe.Strophe;
  3. var $iq = strophe.$iq;
  4. var $msg = strophe.$msg;
  5. var $build = strophe.$build;
  6. var $pres = strophe.$pres;
  7. var jsdom = require("jsdom");
  8. var window = jsdom.jsdom().parentWindow;
  9. var $ = require('jquery')(window);
  10. var stropheJingle = require("./strophe.jingle.sdp.js");
  11. var input = '';
  12. process.stdin.on('readable', function() {
  13. var chunk = process.stdin.read();
  14. if (chunk !== null) {
  15. input += chunk;
  16. }
  17. });
  18. process.stdin.on('end', function() {
  19. if (process.argv[2] == '--jingle') {
  20. var elem = $(input);
  21. // app does:
  22. // sess.setRemoteDescription($(iq).find('>jingle'), 'offer');
  23. //console.log(elem.find('>content'));
  24. var sdp = new stropheJingle.SDP('');
  25. sdp.fromJingle(elem);
  26. console.log(sdp.raw);
  27. } else if (process.argv[2] == '--sdp') {
  28. var sdp = new stropheJingle.SDP(input);
  29. var accept = $iq({to: '%(tojid)s',
  30. type: 'set'})
  31. .c('jingle', {xmlns: 'urn:xmpp:jingle:1',
  32. //action: 'session-accept',
  33. action: '%(action)s',
  34. initiator: '%(initiator)s',
  35. responder: '%(responder)s',
  36. sid: '%(sid)s' });
  37. sdp.toJingle(accept, 'responder');
  38. console.log(Strophe.serialize(accept));
  39. }
  40. });