Skip to content

Commit 32d6008

Browse files
committed
add plugin to connection
1 parent 8376364 commit 32d6008

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

dataforms/spec/strophe.x.coffee

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ describe "XMPP Data Forms (0004)", ->
1414
@errorHandler = jasmine.createSpy "errorHandler"
1515
@Sx = Strophe.x
1616

17+
it "is installed to the connection object", ->
18+
(expect typeof @con.x).toEqual "object"
19+
20+
it "can parse a result", ->
21+
22+
res = $build("command").c("x",{type:"result"}).c("title").t("My title").tree()
23+
form = @con.x.parseFromResult res
24+
25+
(expect form.type).toEqual "result"
26+
(expect form.title).toEqual "My title"
27+
1728
describe "Form", ->
1829

1930
it "has one of four possible type attributes", ->

dataforms/src/strophe.x.coffee

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,15 @@ Strophe.x =
424424
Field: Field
425425
Option:Option
426426
Item:Item
427+
428+
Strophe.addConnectionPlugin 'x',
429+
430+
init : (conn) ->
431+
Strophe.addNamespace 'DATA', 'jabber:x:data'
432+
conn.disco.addFeature Strophe.NS.DATA if conn.disco
433+
434+
parseFromResult: (result) ->
435+
if result.nodeName.toLowerCase() is "x"
436+
Form.fromXML result
437+
else
438+
Form.fromXML ($ result).find("x")?[0]

dataforms/src/strophe.x.js

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)