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
- imXPCOMUtils: Additional XPCOM utilities.
- JavaScript socket: Simplified socket code.
- jsProtoHelper: Includes basic JavaScript implementations of the interfaces and some helper code.
- XML HTTP Request helper: Simplified HTTP request 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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论