Chat Core Protocols 编辑

The Chat Core code used by Instantbird and Thunderbird has some abstractions to deal with the differences between protocols (e.g. IRC vs. XMPP).

Protocol Interfaces

Protocols are implemented in the chat core using XPCOM (in any of the languages that supports: C++, JavaScript, etc.). For new implementations, we recommend using JavaScript. Instantbird can also use libpurple protocol plugins that are recompiled for Instantbird (it is API compatible, but not ABI compatible).

Protocols added by extensions or distributed with chat core are treated identically. They must implement the proper interfaces and be registered with the category manager in order to be found. Protocols need to implement the prplI* interfaces (this can mostly be done using jsProtoHelper). The minimum set of interfaces to implement are:

Useful Code

Example Implementations

The code for the JavaScript protocols we ship by default is here.

  • IRC: A full example implementing private chats and MUCs, etc. It is currently used in Instantbird/Thunderbird and includes hooks for other extensions.
  • JavaScript Test Protocol: An extremely simple example meant to serve as test code for the interfaces.
  • Twitter: Implements the Twitter API (link me?), included in Instantbird/Thunderbird.
  • XMPP: Included in Instantbird, but not enabled by default. Used by default in Thunderbird. Since XMPP is extensible, there are also other protocols which inherit and customize XMPP.

Example protocol add-ons

  • LJ Talk
  • Omegle: A simple example using JSON requests, implemented as an extension.

Useful Code Snippets

Using Services.core.getProtocols() to list all protocols

This lists the protocol plugins that the core service knows about. You can copy the code (as it is), paste it in the error console (linebreaks will automatically be ignored) and press "Enter" to run it.

Components.utils.import("resource:///modules/imServices.jsm");
var x = Services.core.getProtocols();
var result = "";
while (x.hasMoreElements()) {
  var y = x.getNext().QueryInterface(Components.interfaces.prplIProtocol);
  result += y.name + "\t\t" +y.id + "\n";
}
Services.console.logStringMessage(result);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:122 次

字数:6168

最后编辑:7 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文