<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>WebXDC</title>
  <abstract>This document defines an XMPP protocol extension to communicate WebXDC widgets and their state updates.</abstract>
  
<legal>
<copyright>This XMPP Extension Protocol is copyright © 1999 – 2024 by the <link url="https://xmpp.org/">XMPP Standards Foundation</link> (XSF).</copyright>
<permissions>Permission is hereby granted, free of charge, to any person obtaining a copy of this specification (the "Specification"), to make use of the Specification without restriction, including without limitation the rights to implement the Specification in a software program, deploy the Specification in a network service, and copy, modify, merge, publish, translate, distribute, sublicense, or sell copies of the Specification, and to permit persons to whom the Specification is furnished to do so, subject to the condition that the foregoing copyright notice and this permission notice shall be included in all copies or substantial portions of the Specification. Unless separate permission is granted, modified works that are redistributed shall not contain misleading information regarding the authors, title, number, or publisher of the Specification, and shall not claim endorsement of the modified works by the authors, any organization or project to which the authors belong, or the XMPP Standards Foundation.</permissions>
<warranty>## NOTE WELL: This Specification is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. ##</warranty>
<liability>In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall the XMPP Standards Foundation or any author of this Specification be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.</liability>
<conformance>This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which can be found at &lt;<link url="https://xmpp.org/about/xsf/ipr-policy">https://xmpp.org/about/xsf/ipr-policy</link>&gt; or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).</conformance>
</legal>
  <number>0491</number>
  <status>Experimental</status>
  <type>Standards Track</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XMPP IM</spec>
    <spec>XEP-0335</spec>
    <spec>XEP-0421</spec>
    <spec>WebXDC</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>webxdc</shortname>
  
  <author>
    <firstname>Stephen Paul</firstname>
    <surname>Weber</surname>
    <email>singpolyma@singpolyma.net</email>
    <jid>singpolyma@singpolyma.net</jid>
  </author>

  <revision>
    <version>0.1.3</version>
    <date>2024-10-17</date>
    <initials>spw</initials>
    <remark>
      <ul>
        <li>Clarifications and wording</li>
        <li>Better references for WebXDC spec</li>
      </ul>
    </remark>
  </revision>
  <revision>
    <version>0.1.2</version>
    <date>2024-07-03</date>
    <initials>spw</initials>
    <remark>
      <ul>
        <li>Suggest what to use for selfAddr</li>
        <li>Add acknowledgements</li>
      </ul>
    </remark>
  </revision>
  <revision>
    <version>0.1.0</version>
    <date>2024-06-20</date>
    <initials>XEP Editor: dg</initials>
    <remark>
      <ul>
        <li>Promoted to Experimental</li>
      </ul>
    </remark>
  </revision>
  <revision>
    <version>0.0.1</version>
    <date>2024-06-05</date>
    <initials>spw</initials>
    <remark><p>Initial version.</p></remark>
  </revision>
</header>
<section1 topic="Introduction" anchor="intro">
  <p><span class="ref"><link url="https://webxdc.org">WebXDC</link></span> <note>WebXDC docs: <link url="https://webxdc.org/docs/">https://webxdc.org/docs/</link></note> is a specification for sharing interactive embeddable widgets built with web-like technologies (HTML, JavaScript) via a chat platform, and sharing state between participants in the chat without allowing external network connections for the sandboxed web content. In order to provide support for <span class="ref"><link url="https://webxdc.org">WebXDC</link></span> <note>WebXDC docs: <link url="https://webxdc.org/docs/">https://webxdc.org/docs/</link></note> widgets, the host protocol (XMPP in our case) must define a way to transmit these widgets and the associated state updates.</p>
</section1>
<section1 topic="Glossary" anchor="glossary">
  <p>This specification uses some terminology defined below:</p>
  <ul>
    <li>widget: the WebXDC widget delivered in a zip container as defined by <span class="ref"><link url="https://webxdc.org">WebXDC</link></span> <note>WebXDC docs: <link url="https://webxdc.org/docs/">https://webxdc.org/docs/</link></note></li>
    <li>host application: the XMPP client embedding the widget</li>
    <li>peer: the chat partner in a 1:1 chat or one of the participants of a <span class="ref"><link url="https://xmpp.org/extensions/xep-0045.html">Multi-User Chat (XEP-0045)</link></span> <note>XEP-0045: Multi-User Chat &lt;<link url="https://xmpp.org/extensions/xep-0045.html">https://xmpp.org/extensions/xep-0045.html</link>&gt;.</note> or other group chat</li>
    <li>host protocol: the protocol used by the peers to communicate (XMPP in our case)</li>
  </ul>
</section1>
<section1 topic="Sending a Widget in a Message" anchor="send">
  <p>A widget may be attached to a message using any file-transfer mechanism supported by the client, such as <span class="ref"><link url="https://xmpp.org/extensions/xep-0066.html">Out-of-Band Data (XEP-0066)</link></span> <note>XEP-0066: Out of Band Data &lt;<link url="https://xmpp.org/extensions/xep-0066.html">https://xmpp.org/extensions/xep-0066.html</link>&gt;.</note> or <span class="ref"><link url="https://xmpp.org/extensions/xep-0385.html">Stateless Inline Media Sharing (XEP-0385)</link></span> <note>XEP-0385: Stateless Inline Media Sharing (SIMS) &lt;<link url="https://xmpp.org/extensions/xep-0385.html">https://xmpp.org/extensions/xep-0385.html</link>&gt;.</note>. The message MUST contain a <tt>&lt;thread/&gt;</tt> element with a new, unique id.  Note: including multiple file-transfer mechanisms in the same message may be beneficial for broader compatibility.</p>
<example caption="An example of sending a widget"><![CDATA[
<message to='romeo@montague.lit' type='chat'>
  <thread>018fe972-ea89-7f4b-90f8-729b85b7f32d</thread>
  <media-sharing xmlns='urn:xmpp:sims:1'>
    <file xmlns='urn:xmpp:jingle:apps:file-transfer:5'>
      <media-type>application/webxdc+zip</media-type>
      <name>Calendar</name>
      <size>3032449</size>
      <hash xmlns='urn:xmpp:hashes:2' algo='sha3-256'>2XarmwTlNxDAMkvymloX3S5+VbylNrJt/l5QyPa+YoU=</hash>
      <thumbnail xmlns='urn:xmpp:thumbs:1' uri='cid:sha1+ffd7c8d28e9c5e82afea41f97108c6b4@bob.xmpp.org' media-type='image/png' width='96' height='96'/>
    </file>
    <sources>
      <reference xmlns='urn:xmpp:reference:0' type='data' uri='https://download.montague.lit/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/calendar.xdc' />
    </sources>
  </media-sharing>
  <x xmlns='jabber:x:oob'>
    <url>https://download.montague.lit/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/calendar.xdc</url>
  </x>
</message>]]></example>
</section1>
<section1 topic="Sending a State Update" anchor="state">
  <p>When a widget needs to communicate an update to peers in a chat, this update may contain one or more of the following items as defined in <span class="ref"><link url="https://webxdc.org/docs/spec/sendUpdate.html">WebXDC</link></span> <note>WebXDC sendUpdate: <link url="https://webxdc.org/docs/spec/sendUpdate.html">https://webxdc.org/docs/spec/sendUpdate.html</link></note>.</p>
  <table caption="Data transmitted with a WebXDC update">
    <tr>
      <th>Item</th>
      <th>Description</th>
    </tr>
    <tr>
      <td>info</td>
      <td>Human readable message to send to the chat</td>
    </tr>
    <tr>
      <td>summary</td>
      <td>Text which may be shown next to the widget launcher</td>
    </tr>
    <tr>
      <td>document</td>
      <td>Title which may be shown next to the widget launcher</td>
    </tr>
    <tr>
      <td>payload</td>
      <td>Arbitrary JSON serializable value</td>
    </tr>
  </table>
  <p>These items are delivered in a message which MUST have the same <tt>&lt;thread&gt;</tt> as the message which originally <link url="#send">delivered the widget itself</link>. The stanza SHOULD contain a <tt>x</tt> child having the <tt>urn:xmpp:webxdc:0</tt> namespace, with these items (except for <tt>info</tt>) as children, as defined below.</p>
  <section2 topic="The Info Item" anchor="info">
    <p>The info item is human-readable and is not needed by the widget itself, thus it is appropriate to transmit it anywhere that it might be visible to all participants, such as in a message body. If this is the only item present, an empty <tt>&lt;x&gt;</tt> element SHOULD still be included in the message to signal this update came from the widget.</p>
    <example caption="An example of sending just info"><![CDATA[
<message to='romeo@montague.lit' type='chat'>
  <thread>018fe972-ea89-7f4b-90f8-729b85b7f32d</thread>
  <x xmlns='urn:xmpp:webxdc:0' />
  <body>Juliet has added an event.</body>
</message>]]></example>
  </section2>
  <section2 topic="The Document and Summary Items" anchor="summary">
    <p>These items are delivered as children of the <tt>&lt;x&gt;</tt> item, and in the same namespace. The document item using a <tt>&lt;document&gt;</tt> child and the summary item using a <tt>&lt;summary&gt;</tt> child.</p>
    <example caption="An example of sending document and summary"><![CDATA[
<message to='romeo@montague.lit' type='chat'>
  <thread>018fe972-ea89-7f4b-90f8-729b85b7f32d</thread>
  <x xmlns='urn:xmpp:webxdc:0'>
    <document>Our Calendar</document>
    <summary>12 events</summary>
  </x>
</message>]]></example>
  </section2>
  <section2 topic="The Payload Item" anchor="payload">
    <p>The payload item is delivered using <span class="ref"><link url="https://xmpp.org/extensions/xep-0335.html">JSON Containers (XEP-0335)</link></span> <note>XEP-0335: JSON Containers &lt;<link url="https://xmpp.org/extensions/xep-0335.html">https://xmpp.org/extensions/xep-0335.html</link>&gt;.</note> as a child of the <tt>&lt;x&gt;</tt> element</p>
    <example caption="An example of sending payload"><![CDATA[
<message to='romeo@montague.lit' type='chat'>
  <thread>018fe972-ea89-7f4b-90f8-729b85b7f32d</thread>
  <x xmlns='urn:xmpp:webxdc:0'>
    <json xmlns='urn:xmpp:json:0'>{}</json>
  </x>
</message>]]></example>
  </section2>
</section1>
<section1 topic="selfAddr" anchor="selfAddr">
  <p><span class="ref"><link url="https://webxdc.org/docs/spec/selfAddr_and_selfName.html">WebXDC</link></span> <note>WebXDC selfAddr and selfName: <link url="https://webxdc.org/docs/spec/selfAddr_and_selfName.html">https://webxdc.org/docs/spec/selfAddr_and_selfName.html</link></note> widgets get various data injected into them by the host application. One of these worth mentioning is the <tt>selfAddr</tt> property.</p>
	<ul>
		<li>When the chat is a 1:1 chat this property SHOULD be set to the XMPP URI for the local party's bare Jabber ID e.g. <tt>xmpp:juliet@capulet.lit</tt></li>
		<li>When the chat supports <span class="ref"><link url="https://xmpp.org/extensions/xep-0421.html">Anonymous unique occupant identifiers for MUCs (XEP-0421)</link></span> <note>XEP-0421: Anonymous unique occupant identifiers for MUCs &lt;<link url="https://xmpp.org/extensions/xep-0421.html">https://xmpp.org/extensions/xep-0421.html</link>&gt;.</note> this property SHOULD be set to the local party's <tt>occupant-id</tt>.</li>
		<li>Note that no other type of chat is specified here, and especially that a <span class="ref"><link url="https://xmpp.org/extensions/xep-0045.html">Multi-User Chat (XEP-0045)</link></span> <note>XEP-0045: Multi-User Chat &lt;<link url="https://xmpp.org/extensions/xep-0045.html">https://xmpp.org/extensions/xep-0045.html</link>&gt;.</note> chat without support for <span class="ref"><link url="https://xmpp.org/extensions/xep-0421.html">Anonymous unique occupant identifiers for MUCs (XEP-0421)</link></span> <note>XEP-0421: Anonymous unique occupant identifiers for MUCs &lt;<link url="https://xmpp.org/extensions/xep-0421.html">https://xmpp.org/extensions/xep-0421.html</link>&gt;.</note> SHOULD NOT use full Jabber ID or room nickname for the property, as it may case inconsistent behaviour in some widgets when the user changes their nickname.</li>
	</ul>
</section1>
<section1 topic="selfName" anchor="selfName">
  <p>The <tt>selfName</tt> property defined by <span class="ref"><link url="https://webxdc.org/docs/spec/selfAddr_and_selfName.html">WebXDC</link></span> <note>WebXDC selfAddr and selfName: <link url="https://webxdc.org/docs/spec/selfAddr_and_selfName.html">https://webxdc.org/docs/spec/selfAddr_and_selfName.html</link></note> is human readable and may be set to anything useful per that specification. It MAY be set to the local <span class="ref"><link url="https://xmpp.org/extensions/xep-0045.html">Multi-User Chat (XEP-0045)</link></span> <note>XEP-0045: Multi-User Chat &lt;<link url="https://xmpp.org/extensions/xep-0045.html">https://xmpp.org/extensions/xep-0045.html</link>&gt;.</note> nickname or <span class="ref"><link url="https://xmpp.org/extensions/xep-0172.html">User Nickname (XEP-0172)</link></span> <note>XEP-0172: User Nickname &lt;<link url="https://xmpp.org/extensions/xep-0172.html">https://xmpp.org/extensions/xep-0172.html</link>&gt;.</note> where relevant.</p>
</section1>
<section1 topic="Accessibility Considerations" anchor="access">
  <p>None</p>
</section1>
<section1 topic="Security Considerations" anchor="security">
  <p>It is assumed that an implementation of this XEP will be paired with an implementation of <span class="ref"><link url="https://webxdc.org">WebXDC</link></span> <note>WebXDC docs: <link url="https://webxdc.org/docs/">https://webxdc.org/docs/</link></note>. Please see <span class="ref"><link url="https://webxdc.org">WebXDC</link></span> <note>WebXDC docs: <link url="https://webxdc.org/docs/">https://webxdc.org/docs/</link></note> for sandboxing and security considerations for your WebXDC implementation.</p>
  <p>This XEP does not introduce any specific security considerations besides those present in any <span class="ref"><link url="https://webxdc.org">WebXDC</link></span> <note>WebXDC docs: <link url="https://webxdc.org/docs/">https://webxdc.org/docs/</link></note> implementation.</p>
</section1>
<section1 topic="Privacy Considerations" anchor="privacy">
  <p>It should be clear to users that their actions inside an embedded widget may be transmitted to other participants.</p>
</section1>
<section1 topic="IANA Considerations" anchor="iana">
  <p>This document requires no interaction with the <span class="ref"><link url="http://www.iana.org/">Internet Assigned Numbers Authority (IANA)</link></span> <note>The Internet Assigned Numbers Authority (IANA) is the central coordinator for the assignment of unique parameter values for Internet protocols, such as port numbers and URI schemes. For further information, see &lt;<link url="http://www.iana.org/">http://www.iana.org/</link>&gt;.</note>.</p>
</section1>
<section1 topic="XMPP Registrar Considerations" anchor="registrar">
  <section2 topic="Protocol Namespaces" anchor="registrar-ns">
    <p>This specification defines the following XML namespace: urn:xmpp:webxdc:0</p>
  </section2>
  <section2 topic="Protocol Versioning" anchor="registrar-versioning">
    <p>If the protocol defined in this specification undergoes a revision that is not fully backwards-compatible with an older version, the XMPP Registrar shall increment the protocol version number found at the end of the XML namespaces defined herein, as described in Section 4 of <cite>XEP-0053</cite>.</p>
  </section2>
</section1>
<section1 topic="XML Schema" anchor="schema">
  <code><![CDATA[
<?xml version='1.0' encoding='UTF-8'?>

<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='urn:xmpp:webxdc:0'
    xmlns='urn:xmpp:webxdc:0'
    xmlns:json='urn:xmpp:json:0'
    elementFormDefault='qualified'>

  <xs:annotation>
    <xs:documentation>
      The protocol documented by this schema is defined in
      XEP-]]>0491<![CDATA[: http://www.xmpp.org/extensions/xep-]]>0491<![CDATA[.html
    </xs:documentation>
  </xs:annotation>

  <xs:import namespace='urn:xmpp:json:0' schemaLocation='https://xmpp.org/schemas/json.xsd' />

  <xs:element name='x'>
    <xs:complexType>
      <xs:sequence>
        <xs:element name='summary' type='xsd:string' minOccurs='0' maxOccurs='1'/>
        <xs:element name='document' type='xsd:string' minOccurs='0' maxOccurs='1'/>
        <xs:element name='json' type='json:json' minOccurs='0' maxOccurs='1'/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
]]></code>
</section1>
<section1 topic="Acknowledgements" anchor="acks">
  <p>Thanks to NLNet foundation for funding the work on this specification.</p>
</section1>
</xep>
