examples/remote.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Sat, 28 Mar 2009 19:43:12 +0200
changeset 67 d33ca5572e91
parent 66 542f61e113cb
child 68 742878c74b8e
permissions -rw-r--r--
Fully object forms interface (untested)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     1
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     2
-- REMOTE CONTROLLING CLIENTS (XEP-0146)
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     3
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     4
-- library
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     5
67
d33ca5572e91 Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
     6
local iq     = require 'iq'
d33ca5572e91 Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
     7
local x_data = require 'x_data'
d33ca5572e91 Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
     8
local disco  = require 'disco'
44
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     9
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    10
-- public
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    11
67
d33ca5572e91 Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    12
local F = { }
44
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    13
67
d33ca5572e91 Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    14
function F.list ( conn, to, success, fail )
44
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    15
	disco.items ( conn, to, success, fail, 'http://jabber.org/protocol/commands' )
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    16
end
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    17
67
d33ca5572e91 Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    18
function F.command ( conn, to, command, success, fail )
44
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    19
	iq.send ( conn, to, 'set',
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    20
		{
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    21
			command = { xmlns = 'http://jabber.org/protocol/commands', action = 'execute', node = command },
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    22
		},
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    23
		function ( mess )
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    24
			local c = mess:child ( 'command' )
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    25
			if c then
49
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    26
				local status = c:attribute ( 'status' )
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    27
				if status == 'completed' then
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    28
					success ()
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    29
				else
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    30
					local x = c:child ( 'x' )
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    31
					if x then
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    32
						local sid = c:attribute ( 'sessionid' )
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    33
						success ( x_data.parse ( x ),
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    34
							function ( form, success, fail )
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    35
								iq.send ( conn, to, 'set',
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    36
									{
67
d33ca5572e91 Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    37
										command = form:format ( { xmlns = 'http://jabber.org/protocol/commands', node = command, sessionid = sid }, 'submit' ),
44
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    38
									},
49
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    39
									function ( mess )
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    40
										local c = mess:child ( 'command' )
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    41
										if c and c:attribute ( 'status' ) == 'completed' then
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    42
											success ()
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    43
										else
67
d33ca5572e91 Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    44
											fail ( mess:xml () ) -- XXX more forms? results?
49
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    45
										end
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    46
									end, fail )
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    47
							end,
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    48
							function ( form, success, fail )
51
a95a3a73482c Pubsub uses new forms
Myhailo Danylenko <isbear@ukrpost.net>
parents: 49
diff changeset
    49
								iq.send ( conn, to, 'set',
a95a3a73482c Pubsub uses new forms
Myhailo Danylenko <isbear@ukrpost.net>
parents: 49
diff changeset
    50
									{
67
d33ca5572e91 Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    51
										command = form:format ( { xmlns = 'http://jabber.org/protocol/commands', node = command, sessionid = sid }, 'cancel' ),
51
a95a3a73482c Pubsub uses new forms
Myhailo Danylenko <isbear@ukrpost.net>
parents: 49
diff changeset
    52
									}, success, fail )
49
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    53
							end )
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    54
					else
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    55
						fail ( mess:xml () ) -- XXX
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    56
					end
44
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    57
				end
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    58
			end
49
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 44
diff changeset
    59
		end, fail )
44
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    60
end
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    61
67
d33ca5572e91 Fully object forms interface (untested)
Myhailo Danylenko <isbear@ukrpost.net>
parents: 66
diff changeset
    62
return F
44
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    63
bd66956cd397 Disco and remote in new way
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    64
-- vim: se ts=4: --