瀏覽代碼

Merge converse-api and converse-core

Otherwise `require('converse-core')` can be called, exposing the inner converse
object.
JC Brand 8 年之前
父節點
當前提交
fe6a9ca748

+ 1 - 2
config.js

@@ -50,11 +50,10 @@ require.config({
         "utils":                    "src/utils",
         "utils":                    "src/utils",
 
 
         // Converse
         // Converse
-        "converse-api":             "src/converse-api",
+        "converse-core":            "src/converse-core",
         "converse-bookmarks":       "src/converse-bookmarks",
         "converse-bookmarks":       "src/converse-bookmarks",
         "converse-chatview":        "src/converse-chatview",
         "converse-chatview":        "src/converse-chatview",
         "converse-controlbox":      "src/converse-controlbox",
         "converse-controlbox":      "src/converse-controlbox",
-        "converse-core":            "src/converse-core",
         "converse-dragresize":      "src/converse-dragresize",
         "converse-dragresize":      "src/converse-dragresize",
         "converse-headline":        "src/converse-headline",
         "converse-headline":        "src/converse-headline",
         "converse-mam":             "src/converse-mam",
         "converse-mam":             "src/converse-mam",

+ 1 - 2
docs/source/other_frameworks.rst

@@ -53,8 +53,7 @@ Below is an example code that wraps converse.js as an angular.js service.
 
 
         // Here we define the core components of converse.js that will be
         // Here we define the core components of converse.js that will be
         // loaded and used.
         // loaded and used.
-        define("converse", [
-            "converse-api",
+        define(["converse-core",
             // START: Removable components
             // START: Removable components
             // --------------------
             // --------------------
             // Any of the following components may be removed if they're not needed.
             // Any of the following components may be removed if they're not needed.

+ 0 - 2
docs/source/security.rst

@@ -36,8 +36,6 @@ Separate code/data into public and private parts
 1. Encapsulate Converse.js's data structures into a private closured object (named ``_converse``).
 1. Encapsulate Converse.js's data structures into a private closured object (named ``_converse``).
 2. Split the API into public and private parts.
 2. Split the API into public and private parts.
 
 
-TODO: Merge ``converse-core.js`` and ``converse-api.js``, so that the ``_converse`` object can't be accessed outside of a plugin.
-
 Restrict access to private code/data
 Restrict access to private code/data
 ------------------------------------
 ------------------------------------
 
 

+ 1 - 1
embedded.html

@@ -55,7 +55,7 @@
 </body>
 </body>
 
 
 <script>
 <script>
-    require(['converse-api', 'converse-muc-embedded'], function (converse) {
+    require(['converse-core', 'converse-muc-embedded'], function (converse) {
         converse.initialize({
         converse.initialize({
             allow_logout: false, // No point in logging out when we have auto_login as true.
             allow_logout: false, // No point in logging out when we have auto_login as true.
             allow_muc_invitations: false, // Doesn't make sense to allow because only
             allow_muc_invitations: false, // Doesn't make sense to allow because only

+ 1 - 1
spec/bookmarks.js

@@ -1,7 +1,7 @@
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
         "jquery",
         "jquery",
-        "converse-api",
+        "converse-core",
         "utils",
         "utils",
         "mock",
         "mock",
         "test_utils"
         "test_utils"

+ 1 - 1
spec/chatbox.js

@@ -1,7 +1,7 @@
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
         "utils",
         "utils",
-        "converse-api",
+        "converse-core",
         "mock",
         "mock",
         "test_utils"
         "test_utils"
         ], factory);
         ], factory);

+ 1 - 1
spec/chatroom.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
 (function (root, factory) {
-    define(["mock", "converse-api", "test_utils", "utils" ], factory);
+    define(["mock", "converse-core", "test_utils", "utils" ], factory);
 } (this, function (mock, converse, test_utils, utils) {
 } (this, function (mock, converse, test_utils, utils) {
     var _ = converse.env._;
     var _ = converse.env._;
     var $ = converse.env.jQuery;
     var $ = converse.env.jQuery;

+ 1 - 1
spec/controlbox.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
 (function (root, factory) {
-    define(["mock", "converse-api", "test_utils"], factory);
+    define(["mock", "converse-core", "test_utils"], factory);
 } (this, function (mock, converse, test_utils) {
 } (this, function (mock, converse, test_utils) {
     var _ = converse.env._;
     var _ = converse.env._;
     var $ = converse.env.jQuery;
     var $ = converse.env.jQuery;

+ 1 - 1
spec/converse.js

@@ -1,6 +1,6 @@
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
-        "converse-api",
+        "converse-core",
         "mock",
         "mock",
         "test_utils"], factory);
         "test_utils"], factory);
 } (this, function (converse, mock, test_utils) {
 } (this, function (converse, mock, test_utils) {

+ 1 - 1
spec/disco.js

@@ -1,7 +1,7 @@
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
         "jquery",
         "jquery",
-        "converse-api",
+        "converse-core",
         "mock",
         "mock",
         "test_utils"], factory);
         "test_utils"], factory);
 } (this, function ($, converse, mock, test_utils) {
 } (this, function ($, converse, mock, test_utils) {

+ 1 - 1
spec/eventemitter.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
 (function (root, factory) {
-    define(["mock", "converse-api", "test_utils"], factory);
+    define(["mock", "converse-core", "test_utils"], factory);
 } (this, function (mock, converse, test_utils) {
 } (this, function (mock, converse, test_utils) {
 
 
     return describe("The _converse Event Emitter", function() {
     return describe("The _converse Event Emitter", function() {

+ 1 - 1
spec/headline.js

@@ -1,7 +1,7 @@
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
         "jquery",
         "jquery",
-        "converse-api",
+        "converse-core",
         "utils",
         "utils",
         "mock",
         "mock",
         "test_utils"
         "test_utils"

+ 1 - 1
spec/mam.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
 (function (root, factory) {
-    define(["mock", "converse-api", "test_utils"], factory);
+    define(["mock", "converse-core", "test_utils"], factory);
 } (this, function (mock, converse, test_utils) {
 } (this, function (mock, converse, test_utils) {
     "use strict";
     "use strict";
     var _ = converse.env._;
     var _ = converse.env._;

+ 1 - 1
spec/minchats.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
 (function (root, factory) {
-    define(["mock", "converse-api", "test_utils"], factory);
+    define(["mock", "converse-core", "test_utils"], factory);
 } (this, function (mock, converse, test_utils) {
 } (this, function (mock, converse, test_utils) {
     var _ = converse.env._;
     var _ = converse.env._;
     var $msg = converse.env.$msg;
     var $msg = converse.env.$msg;

+ 1 - 1
spec/notification.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
 (function (root, factory) {
-    define(["mock", "converse-api", "test_utils"], factory);
+    define(["mock", "converse-core", "test_utils"], factory);
 } (this, function (mock, converse, test_utils) {
 } (this, function (mock, converse, test_utils) {
     "use strict";
     "use strict";
     var $msg = converse.env.$msg;
     var $msg = converse.env.$msg;

+ 1 - 1
spec/otr.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
 (function (root, factory) {
-    define(["mock", "converse-api", "test_utils"], factory);
+    define(["mock", "converse-core", "test_utils"], factory);
 } (this, function (mock, converse, test_utils) {
 } (this, function (mock, converse, test_utils) {
     var $ = converse.env.jQuery;
     var $ = converse.env.jQuery;
     var Strophe = converse.env.Strophe;
     var Strophe = converse.env.Strophe;

+ 1 - 1
spec/ping.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
 (function (root, factory) {
-    define(["mock", "converse-api", "test_utils", "converse-ping"], factory);
+    define(["mock", "converse-core", "test_utils", "converse-ping"], factory);
 } (this, function (mock, test_utils) {
 } (this, function (mock, test_utils) {
     "use strict";
     "use strict";
 
 

+ 1 - 1
spec/profiling.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
 (function (root, factory) {
-    define(["mock", "converse-api", "test_utils"], factory);
+    define(["mock", "converse-core", "test_utils"], factory);
 } (this, function (mock, converse, test_utils) {
 } (this, function (mock, converse, test_utils) {
     var _ = converse.env._;
     var _ = converse.env._;
     var $iq = converse.env.$iq;
     var $iq = converse.env.$iq;

+ 1 - 1
spec/protocol.js

@@ -1,7 +1,7 @@
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
         "jquery",
         "jquery",
-        "converse-api",
+        "converse-core",
         "mock",
         "mock",
         "test_utils"], factory);
         "test_utils"], factory);
 } (this, function ($, converse, mock, test_utils) {
 } (this, function ($, converse, mock, test_utils) {

+ 1 - 1
spec/register.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
 (function (root, factory) {
-    define(["mock", "converse-api", "test_utils"], factory);
+    define(["mock", "converse-core", "test_utils"], factory);
 } (this, function (mock, converse, test_utils) {
 } (this, function (mock, converse, test_utils) {
     var $ = converse.env.jQuery;
     var $ = converse.env.jQuery;
     var Strophe = converse.env.Strophe;
     var Strophe = converse.env.Strophe;

+ 1 - 1
spec/utils.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
 (function (root, factory) {
-    define(["converse-api"], factory);
+    define(["converse-core"], factory);
 } (this, function (converse) {
 } (this, function (converse) {
     var utils = converse.env.utils,
     var utils = converse.env.utils,
         _ = converse.env._;
         _ = converse.env._;

+ 1 - 1
spec/xmppstatus.js

@@ -1,5 +1,5 @@
 (function (root, factory) {
 (function (root, factory) {
-    define(["mock", "converse-api", "test_utils"], factory);
+    define(["mock", "converse-core", "test_utils"], factory);
 } (this, function (mock, converse, test_utils) {
 } (this, function (mock, converse, test_utils) {
     var $ = converse.env.jQuery;
     var $ = converse.env.jQuery;
 
 

+ 0 - 224
src/converse-api.js

@@ -1,224 +0,0 @@
-// Converse.js (A browser based XMPP chat client)
-// http://conversejs.org
-//
-// Copyright (c) 2012-2017, Jan-Carel Brand <jc@opkode.com>
-// Licensed under the Mozilla Public License (MPLv2)
-//
-/*global define */
-(function (root, factory) {
-    define(["jquery",
-            "lodash",
-            "moment_with_locales",
-            "strophe",
-            "utils",
-            "converse-core"
-        ],
-        factory);
-}(this, function ($, _, moment, strophe, utils, _converse) {
-    var Strophe = strophe.Strophe;
-
-    // API methods only available to plugins
-    _converse.api = {
-        'connection': {
-            'connected': function () {
-                return _converse.connection && _converse.connection.connected || false;
-            },
-            'disconnect': function () {
-                _converse.connection.disconnect();
-            },
-        },
-        'user': {
-            'jid': function () {
-                return _converse.connection.jid;
-            },
-            'login': function (credentials) {
-                _converse.initConnection();
-                _converse.logIn(credentials);
-            },
-            'logout': function () {
-                _converse.logOut();
-            },
-            'status': {
-                'get': function () {
-                    return _converse.xmppstatus.get('status');
-                },
-                'set': function (value, message) {
-                    var data = {'status': value};
-                    if (!_.includes(_.keys(_converse.STATUS_WEIGHTS), value)) {
-                        throw new Error('Invalid availability value. See https://xmpp.org/rfcs/rfc3921.html#rfc.section.2.2.2.1');
-                    }
-                    if (_.isString(message)) {
-                        data.status_message = message;
-                    }
-                    _converse.xmppstatus.sendPresence(value);
-                    _converse.xmppstatus.save(data);
-                },
-                'message': {
-                    'get': function () {
-                        return _converse.xmppstatus.get('status_message');
-                    },
-                    'set': function (stat) {
-                        _converse.xmppstatus.save({'status_message': stat});
-                    }
-                }
-            },
-        },
-        'settings': {
-            'get': function (key) {
-                if (_.includes(_.keys(_converse.default_settings), key)) {
-                    return _converse[key];
-                }
-            },
-            'set': function (key, val) {
-                var o = {};
-                if (_.isObject(key)) {
-                    _.assignIn(_converse, _.pick(key, _.keys(_converse.default_settings)));
-                } else if (_.isString("string")) {
-                    o[key] = val;
-                    _.assignIn(_converse, _.pick(o, _.keys(_converse.default_settings)));
-                }
-            }
-        },
-        'contacts': {
-            'get': function (jids) {
-                var _transform = function (jid) {
-                    var contact = _converse.roster.get(Strophe.getBareJidFromJid(jid));
-                    if (contact) {
-                        return contact.attributes;
-                    }
-                    return null;
-                };
-                if (_.isUndefined(jids)) {
-                    jids = _converse.roster.pluck('jid');
-                } else if (_.isString(jids)) {
-                    return _transform(jids);
-                }
-                return _.map(jids, _transform);
-            },
-            'add': function (jid, name) {
-                if (!_.isString(jid) || !_.includes(jid, '@')) {
-                    throw new TypeError('contacts.add: invalid jid');
-                }
-                _converse.roster.addAndSubscribe(jid, _.isEmpty(name)? jid: name);
-            }
-        },
-        'chats': {
-            'open': function (jids, attrs) {
-                var chatbox;
-                if (_.isUndefined(jids)) {
-                    _converse.log("chats.open: You need to provide at least one JID", "error");
-                    return null;
-                } else if (_.isString(jids)) {
-                    chatbox = _converse.wrappedChatBox(
-                        _converse.chatboxes.getChatBox(jids, true, attrs).trigger('show')
-                    );
-                    return chatbox;
-                }
-                return _.map(jids, function (jid) {
-                    chatbox = _converse.wrappedChatBox(
-                        _converse.chatboxes.getChatBox(jid, true, attrs).trigger('show')
-                    );
-                    return chatbox;
-                });
-            },
-            'get': function (jids) {
-                if (_.isUndefined(jids)) {
-                    var result = [];
-                    _converse.chatboxes.each(function (chatbox) {
-                        // FIXME: Leaky abstraction from MUC. We need to add a
-                        // base type for chat boxes, and check for that.
-                        if (chatbox.get('type') !== 'chatroom') {
-                            result.push(_converse.wrappedChatBox(chatbox));
-                        }
-                    });
-                    return result;
-                } else if (_.isString(jids)) {
-                    return _converse.wrappedChatBox(_converse.chatboxes.getChatBox(jids));
-                }
-                return _.map(jids,
-                    _.partial(
-                        _.flow(
-                            _converse.chatboxes.getChatBox.bind(_converse.chatboxes),
-                            _converse.wrappedChatBox.bind(_converse)
-                        ), _, true
-                    )
-                );
-            }
-        },
-        'tokens': {
-            'get': function (id) {
-                if (!_converse.expose_rid_and_sid || _.isUndefined(_converse.connection)) {
-                    return null;
-                }
-                if (id.toLowerCase() === 'rid') {
-                    return _converse.connection.rid || _converse.connection._proto.rid;
-                } else if (id.toLowerCase() === 'sid') {
-                    return _converse.connection.sid || _converse.connection._proto.sid;
-                }
-            }
-        },
-        'listen': {
-            'once': _converse.once,
-            'on': _converse.on,
-            'not': _converse.off,
-            'stanza': function (name, options, handler) {
-                if (_.isFunction(options)) {
-                    handler = options;
-                    options = {};
-                } else {
-                    options = options || {};
-                }
-                _converse.connection.addHandler(
-                    handler,
-                    options.ns,
-                    name,
-                    options.type,
-                    options.id,
-                    options.from,
-                    options
-                );
-            },
-        },
-        'waitUntil': function (name) {
-            var promise = _converse.promises[name];
-            if (_.isUndefined(promise)) {
-                return null;
-            }
-            return _converse.promises[name].promise();
-        },
-        'send': function (stanza) {
-            _converse.connection.send(stanza);
-        },
-    };
-
-    // The public API
-    return {
-        'initialize': function (settings, callback) {
-            return _converse.initialize(settings, callback);
-        },
-        'plugins': {
-            'add': function (name, plugin) {
-                plugin.__name__ = name;
-                if (!_.isUndefined(_converse.pluggable.plugins[name])) {
-                    throw new TypeError(
-                        'Error: plugin with name "'+name+'" has already been '+
-                        'registered!');
-                } else {
-                    _converse.pluggable.plugins[name] = plugin;
-                }
-            }
-        },
-        'env': {
-            '$build': strophe.$build,
-            '$iq': strophe.$iq,
-            '$msg': strophe.$msg,
-            '$pres': strophe.$pres,
-            'Strophe': strophe.Strophe,
-            'b64_sha1':  strophe.SHA1.b64_sha1,
-            '_': _,
-            'jQuery': $,
-            'moment': moment,
-            'utils': utils
-        }
-    };
-}));

+ 1 - 1
src/converse-bookmarks.js

@@ -16,7 +16,7 @@
             "moment_with_locales",
             "moment_with_locales",
             "strophe",
             "strophe",
             "utils",
             "utils",
-            "converse-api",
+            "converse-core",
             "converse-muc",
             "converse-muc",
             "tpl!chatroom_bookmark_form",
             "tpl!chatroom_bookmark_form",
             "tpl!chatroom_bookmark_toggle",
             "tpl!chatroom_bookmark_toggle",

+ 1 - 1
src/converse-chatview.js

@@ -8,7 +8,7 @@
 
 
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
-            "converse-api",
+            "converse-core",
             "tpl!chatbox",
             "tpl!chatbox",
             "tpl!new_day",
             "tpl!new_day",
             "tpl!action",
             "tpl!action",

+ 1 - 1
src/converse-controlbox.js

@@ -8,7 +8,7 @@
 
 
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
-            "converse-api",
+            "converse-core",
             "tpl!add_contact_dropdown",
             "tpl!add_contact_dropdown",
             "tpl!add_contact_form",
             "tpl!add_contact_form",
             "tpl!change_status_message",
             "tpl!change_status_message",

+ 219 - 16
src/converse-core.js

@@ -5,23 +5,21 @@
 // Licensed under the Mozilla Public License (MPLv2)
 // Licensed under the Mozilla Public License (MPLv2)
 //
 //
 /*global Backbone, define, window, document */
 /*global Backbone, define, window, document */
-
 (function (root, factory) {
 (function (root, factory) {
-    define([
-        "sizzle",
-        "jquery",
-        "lodash",
-        "polyfill",
-        "locales",
-        "utils",
-        "moment_with_locales",
-        "strophe",
-        "pluggable",
-        "strophe.disco",
-        "backbone.browserStorage",
-        "backbone.overview",
+    define(["sizzle",
+            "jquery",
+            "lodash",
+            "polyfill",
+            "locales",
+            "utils",
+            "moment_with_locales",
+            "strophe",
+            "pluggable",
+            "strophe.disco",
+            "backbone.browserStorage",
+            "backbone.overview",
     ], factory);
     ], factory);
-}(this, function (sizzle, $, _, dummy, locales, utils, moment, Strophe, pluggable) {
+}(this, function (sizzle, $, _, polyfill, locales, utils, moment, Strophe, pluggable) {
     /*
     /*
      * Cannot use this due to Safari bug.
      * Cannot use this due to Safari bug.
      * See https://github.com/jcbrand/converse.js/issues/196
      * See https://github.com/jcbrand/converse.js/issues/196
@@ -31,6 +29,7 @@
     // Strophe globals
     // Strophe globals
     var $build = Strophe.$build;
     var $build = Strophe.$build;
     var $iq = Strophe.$iq;
     var $iq = Strophe.$iq;
+    var $msg = Strophe.$msg;
     var $pres = Strophe.$pres;
     var $pres = Strophe.$pres;
     var b64_sha1 = Strophe.SHA1.b64_sha1;
     var b64_sha1 = Strophe.SHA1.b64_sha1;
     Strophe = Strophe.Strophe;
     Strophe = Strophe.Strophe;
@@ -2034,5 +2033,209 @@
             return init_deferred.promise();
             return init_deferred.promise();
         }
         }
     };
     };
-    return _converse;
+
+    // API methods only available to plugins
+    _converse.api = {
+        'connection': {
+            'connected': function () {
+                return _converse.connection && _converse.connection.connected || false;
+            },
+            'disconnect': function () {
+                _converse.connection.disconnect();
+            },
+        },
+        'user': {
+            'jid': function () {
+                return _converse.connection.jid;
+            },
+            'login': function (credentials) {
+                _converse.initConnection();
+                _converse.logIn(credentials);
+            },
+            'logout': function () {
+                _converse.logOut();
+            },
+            'status': {
+                'get': function () {
+                    return _converse.xmppstatus.get('status');
+                },
+                'set': function (value, message) {
+                    var data = {'status': value};
+                    if (!_.includes(_.keys(_converse.STATUS_WEIGHTS), value)) {
+                        throw new Error('Invalid availability value. See https://xmpp.org/rfcs/rfc3921.html#rfc.section.2.2.2.1');
+                    }
+                    if (_.isString(message)) {
+                        data.status_message = message;
+                    }
+                    _converse.xmppstatus.sendPresence(value);
+                    _converse.xmppstatus.save(data);
+                },
+                'message': {
+                    'get': function () {
+                        return _converse.xmppstatus.get('status_message');
+                    },
+                    'set': function (stat) {
+                        _converse.xmppstatus.save({'status_message': stat});
+                    }
+                }
+            },
+        },
+        'settings': {
+            'get': function (key) {
+                if (_.includes(_.keys(_converse.default_settings), key)) {
+                    return _converse[key];
+                }
+            },
+            'set': function (key, val) {
+                var o = {};
+                if (_.isObject(key)) {
+                    _.assignIn(_converse, _.pick(key, _.keys(_converse.default_settings)));
+                } else if (_.isString("string")) {
+                    o[key] = val;
+                    _.assignIn(_converse, _.pick(o, _.keys(_converse.default_settings)));
+                }
+            }
+        },
+        'contacts': {
+            'get': function (jids) {
+                var _transform = function (jid) {
+                    var contact = _converse.roster.get(Strophe.getBareJidFromJid(jid));
+                    if (contact) {
+                        return contact.attributes;
+                    }
+                    return null;
+                };
+                if (_.isUndefined(jids)) {
+                    jids = _converse.roster.pluck('jid');
+                } else if (_.isString(jids)) {
+                    return _transform(jids);
+                }
+                return _.map(jids, _transform);
+            },
+            'add': function (jid, name) {
+                if (!_.isString(jid) || !_.includes(jid, '@')) {
+                    throw new TypeError('contacts.add: invalid jid');
+                }
+                _converse.roster.addAndSubscribe(jid, _.isEmpty(name)? jid: name);
+            }
+        },
+        'chats': {
+            'open': function (jids, attrs) {
+                var chatbox;
+                if (_.isUndefined(jids)) {
+                    _converse.log("chats.open: You need to provide at least one JID", "error");
+                    return null;
+                } else if (_.isString(jids)) {
+                    chatbox = _converse.wrappedChatBox(
+                        _converse.chatboxes.getChatBox(jids, true, attrs).trigger('show')
+                    );
+                    return chatbox;
+                }
+                return _.map(jids, function (jid) {
+                    chatbox = _converse.wrappedChatBox(
+                        _converse.chatboxes.getChatBox(jid, true, attrs).trigger('show')
+                    );
+                    return chatbox;
+                });
+            },
+            'get': function (jids) {
+                if (_.isUndefined(jids)) {
+                    var result = [];
+                    _converse.chatboxes.each(function (chatbox) {
+                        // FIXME: Leaky abstraction from MUC. We need to add a
+                        // base type for chat boxes, and check for that.
+                        if (chatbox.get('type') !== 'chatroom') {
+                            result.push(_converse.wrappedChatBox(chatbox));
+                        }
+                    });
+                    return result;
+                } else if (_.isString(jids)) {
+                    return _converse.wrappedChatBox(_converse.chatboxes.getChatBox(jids));
+                }
+                return _.map(jids,
+                    _.partial(
+                        _.flow(
+                            _converse.chatboxes.getChatBox.bind(_converse.chatboxes),
+                            _converse.wrappedChatBox.bind(_converse)
+                        ), _, true
+                    )
+                );
+            }
+        },
+        'tokens': {
+            'get': function (id) {
+                if (!_converse.expose_rid_and_sid || _.isUndefined(_converse.connection)) {
+                    return null;
+                }
+                if (id.toLowerCase() === 'rid') {
+                    return _converse.connection.rid || _converse.connection._proto.rid;
+                } else if (id.toLowerCase() === 'sid') {
+                    return _converse.connection.sid || _converse.connection._proto.sid;
+                }
+            }
+        },
+        'listen': {
+            'once': _converse.once,
+            'on': _converse.on,
+            'not': _converse.off,
+            'stanza': function (name, options, handler) {
+                if (_.isFunction(options)) {
+                    handler = options;
+                    options = {};
+                } else {
+                    options = options || {};
+                }
+                _converse.connection.addHandler(
+                    handler,
+                    options.ns,
+                    name,
+                    options.type,
+                    options.id,
+                    options.from,
+                    options
+                );
+            },
+        },
+        'waitUntil': function (name) {
+            var promise = _converse.promises[name];
+            if (_.isUndefined(promise)) {
+                return null;
+            }
+            return _converse.promises[name].promise();
+        },
+        'send': function (stanza) {
+            _converse.connection.send(stanza);
+        },
+    };
+
+    // The public API
+    return {
+        'initialize': function (settings, callback) {
+            return _converse.initialize(settings, callback);
+        },
+        'plugins': {
+            'add': function (name, plugin) {
+                plugin.__name__ = name;
+                if (!_.isUndefined(_converse.pluggable.plugins[name])) {
+                    throw new TypeError(
+                        'Error: plugin with name "'+name+'" has already been '+
+                        'registered!');
+                } else {
+                    _converse.pluggable.plugins[name] = plugin;
+                }
+            }
+        },
+        'env': {
+            '$build': $build,
+            '$iq': $iq,
+            '$msg': $msg,
+            '$pres': $pres,
+            'Strophe': Strophe,
+            'b64_sha1':  b64_sha1,
+            '_': _,
+            'jQuery': $,
+            'moment': moment,
+            'utils': utils
+        }
+    };
 }));
 }));

+ 1 - 1
src/converse-dragresize.js

@@ -8,7 +8,7 @@
 
 
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
-            "converse-api",
+            "converse-core",
             "tpl!dragresize",
             "tpl!dragresize",
             "converse-chatview",
             "converse-chatview",
             "converse-muc", // XXX: would like to remove this
             "converse-muc", // XXX: would like to remove this

+ 1 - 1
src/converse-headline.js

@@ -8,7 +8,7 @@
 
 
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
-            "converse-api",
+            "converse-core",
             "converse-chatview"
             "converse-chatview"
     ], factory);
     ], factory);
 }(this, function (converse) {
 }(this, function (converse) {

+ 1 - 1
src/converse-mam.js

@@ -10,7 +10,7 @@
 
 
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
-            "converse-api",
+            "converse-core",
             "converse-chatview", // Could be made a soft dependency
             "converse-chatview", // Could be made a soft dependency
             "converse-muc", // Could be made a soft dependency
             "converse-muc", // Could be made a soft dependency
             "strophe.rsm"
             "strophe.rsm"

+ 1 - 1
src/converse-minimize.js

@@ -8,7 +8,7 @@
 
 
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
-            "converse-api",
+            "converse-core",
             "tpl!chatbox_minimize",
             "tpl!chatbox_minimize",
             "tpl!toggle_chats",
             "tpl!toggle_chats",
             "tpl!trimmed_chat",
             "tpl!trimmed_chat",

+ 1 - 1
src/converse-muc-embedded.js

@@ -6,7 +6,7 @@
 //
 //
 /*global Backbone */
 /*global Backbone */
 (function (root, factory) {
 (function (root, factory) {
-    define(["converse-api", "converse-muc"], factory);
+    define(["converse-core", "converse-muc"], factory);
 }(this, function (converse) {
 }(this, function (converse) {
     "use strict";
     "use strict";
 
 

+ 1 - 1
src/converse-muc.js

@@ -11,7 +11,7 @@
  */
  */
 (function (root, factory) {
 (function (root, factory) {
     define([
     define([
-            "converse-api",
+            "converse-core",
             "tpl!chatarea",
             "tpl!chatarea",
             "tpl!chatroom",
             "tpl!chatroom",
             "tpl!chatroom_form",
             "tpl!chatroom_form",

+ 1 - 1
src/converse-notification.js

@@ -7,7 +7,7 @@
 /*global define */
 /*global define */
 
 
 (function (root, factory) {
 (function (root, factory) {
-    define(["converse-api"], factory);
+    define(["converse-core"], factory);
 }(this, function (converse) {
 }(this, function (converse) {
     "use strict";
     "use strict";
     var $ = converse.env.jQuery,
     var $ = converse.env.jQuery,

+ 1 - 1
src/converse-otr.js

@@ -10,7 +10,7 @@
  * encryption of one-on-one chat messages.
  * encryption of one-on-one chat messages.
  */
  */
 (function (root, factory) {
 (function (root, factory) {
-    define(["otr", "converse-api", "tpl!toolbar_otr"], factory);
+    define(["otr", "converse-core", "tpl!toolbar_otr"], factory);
 }(this, function (otr, converse, tpl_toolbar_otr) {
 }(this, function (otr, converse, tpl_toolbar_otr) {
     "use strict";
     "use strict";
     // Strophe methods for building stanzas
     // Strophe methods for building stanzas

+ 1 - 1
src/converse-ping.js

@@ -10,7 +10,7 @@
  * as specified in XEP-0199 XMPP Ping.
  * as specified in XEP-0199 XMPP Ping.
  */
  */
 (function (root, factory) {
 (function (root, factory) {
-    define(["converse-api", "strophe.ping"], factory);
+    define(["converse-core", "strophe.ping"], factory);
 }(this, function (converse) {
 }(this, function (converse) {
     "use strict";
     "use strict";
     // Strophe methods for building stanzas
     // Strophe methods for building stanzas

+ 1 - 1
src/converse-register.js

@@ -10,7 +10,7 @@
  * as specified in XEP-0077.
  * as specified in XEP-0077.
  */
  */
 (function (root, factory) {
 (function (root, factory) {
-    define(["converse-api",
+    define(["converse-core",
             "tpl!form_username",
             "tpl!form_username",
             "tpl!register_panel",
             "tpl!register_panel",
             "tpl!register_tab",
             "tpl!register_tab",

+ 1 - 1
src/converse-rosterview.js

@@ -7,7 +7,7 @@
 /*global Backbone, define */
 /*global Backbone, define */
 
 
 (function (root, factory) {
 (function (root, factory) {
-    define(["converse-api",
+    define(["converse-core",
             "tpl!group_header",
             "tpl!group_header",
             "tpl!pending_contact",
             "tpl!pending_contact",
             "tpl!requesting_contact",
             "tpl!requesting_contact",

+ 1 - 1
src/converse-vcard.js

@@ -7,7 +7,7 @@
 /*global define */
 /*global define */
 
 
 (function (root, factory) {
 (function (root, factory) {
-    define(["converse-api", "strophe.vcard"], factory);
+    define(["converse-core", "strophe.vcard"], factory);
 }(this, function (converse) {
 }(this, function (converse) {
     "use strict";
     "use strict";
     var Strophe = converse.env.Strophe,
     var Strophe = converse.env.Strophe,

+ 1 - 1
src/converse.js

@@ -8,7 +8,7 @@
 if (typeof define !== 'undefined') {
 if (typeof define !== 'undefined') {
     /* When running tests, define is not defined. */
     /* When running tests, define is not defined. */
     define("converse", [
     define("converse", [
-        "converse-api",
+        "converse-core",
         // PLEASE NOTE: By default all translations are included.
         // PLEASE NOTE: By default all translations are included.
         // You can modify the file src/locales.js to include only those
         // You can modify the file src/locales.js to include only those
         // translations that you care about.
         // translations that you care about.