Musubi.js

From Musubi Wiki

Jump to: navigation, search

Contents

Introduction

Generally to say, the Firefox Add-on can read/write local files and communicate with external server. Naturally enough, Web pages(non-privilleged pages) are not allowed to access them for security reasons.

The Musubi is one of the Firefox Add-on and communicate with XMPP servers in particular, and needless to say, we should not allow Web pages to take the privilege, so we used the Interaction between privileged and non-privileged pages - MDC technique. In short, the Musubi observes Web page's actions beyond the security wall, and when it finds web page has done something to <xmppout> element, it presumes an intention and takes actual communications. Now then we need to be careful how much presumes it.

It's interesting that Web pages are allowed to compose contents of messages, because it enables to realize real-time Web pages like online chess which communicates game records as messege, and online whiteboard which does image data samely. Though we considered that Web pages should not to be allowed to compose a sendto of messages, and we limit it with the XMPP URI. For example, a Web page which loaded on a following URI is limited to send it to only juliet@capulet.org.

xmpp://romeo@montague.org/Balcony/juliet@capulet.org#http://musubi.im/chat/

Except, in a case of a script of the page specified a rsrc attribute of stanzas, the Musubi extends its value as a resource of the sendto address. That is to say, the page which loaded on the above URI also can send messages to juliet@capulet.org/Home by executing

Musubi.send(<message rsrc="Home">
              <body>Hello</body>
            </message>);

We introduced this to support multi-user-chat to send a whisper to a specified participant (ex. A case of a URI limits it to "chat@conference.jabber.org" and the user wants to whisper to Alice at chat@conference.jabber.org/Alice).

function: Musubi.init(aProc)

Initializes the library.
When stanzas has come, it calls aProc with an argument of the E4X object.

function: Musubi.send(aE4X)

Sends a stanza of the E4X object.

function: Musubi.parseJID(aString)

Parses a string as the Jabber ID.
In failure, it returns a null object.
In success, it returns an object like followings.

parsed "user@musubi.im"

{
 node:     "user",
 domain:   "musubi.im",
 resource: null,
 barejid:  "user@musubi.im",
 fulljid:  "user@musubi.im/"
}

parsed "user@musubi.im/"

{
 node:     "user",
 domain:   "musubi.im",
 resource: "",
 barejid:  "user@musubi.im",
 fulljid:  "user@musubi.im/"
}

parsed "user@musubi.im/Home"

{
 node:     "user",
 domain:   "musubi.im",
 resource: "Home",
 barejid:  "user@musubi.im",
 fulljid:  "user@musubi.im/Home"
}

parsed "conference.jabber.org"

{
 node:     "",
 domain:   "conference.jabber.org",
 resource: null,
 barejid:  "conference.jabber.org"
 fulljid:  "conference.jabber.org/"
}

function: Musubi.parseURI(aString)

Parses a string as the XMPP URI.
In failure, it returns a null object.
In success, it returns an object like followings.

parsed "xmpp:romeo@montague.org"

{
 auth:  null,
 path:  "romeo@montague.org",
 query: null,
 frag:  null
}

parsed "xmpp:romeo@montague.org/Balcony?subscribe#http://musubi.im/"

{
 auth:  null,
 path:  "romeo@montague.org/Balcony",
 query: "subscribe",
 frag:  "http://musubi.im"
}

parsed "xmpp://juliet@capulet.org/Home/romeo@montague.org/Balcony?subscribe#http://musubi.im"

{
 auth:  "juliet@capulet.org/Home",
 path:  "romeo@montague.org/Balcony",
 query: "subscribe",
 frag:  "http://musubi.im"
}

property: Musubi.location.href

At the time of the library is initialized, it executes parseURI(document.location.href).
In failure it sets this property to a value of document.location.href.
In success it sets this property to a value of the frag property of a result object.
In a word, this is a part of http:// of xmpp://...#http://.

property: Musubi.location.info

At the time of the library is initialized, it executes parseURI(document.location.href).
In failure it sets this property to a null object.
In success it sets this property to a result object.

Personal tools