examples/oob.lua
changeset 111 5bcdb71ef2f2
parent 100 521c27baa387
equal deleted inserted replaced
110:bd9f24178d67 111:5bcdb71ef2f2
    42 local oob_pc_handler =
    42 local oob_pc_handler =
    43 	function ( args )
    43 	function ( args )
    44 		local connection = main.connection ()
    44 		local connection = main.connection ()
    45 		if connection then
    45 		if connection then
    46 			local conn = lm.connection.bless ( connection )
    46 			local conn = lm.connection.bless ( connection )
    47 			conn:handler ( oob_iq_handler, 'iq', 'normal' )
    47 			conn:handler ( oob_iq_handler,      'iq',       'normal' )
    48 			conn:handler ( oob_message_handler, 'message', 'normal' )
    48 			conn:handler ( oob_message_handler, 'message',  'normal' )
    49 			conn:handler ( oob_message_handler, 'presence', 'normal' )
    49 			conn:handler ( oob_message_handler, 'presence', 'normal' )
    50 			oob_handler_registered = true
    50 			oob_handler_registered = true
    51 		end
    51 		end
    52 	end
    52 	end
    53 main.hook ( 'hook-post-connect', oob_pc_handler )
    53 local oob_pd_handler = 
    54 main.hook ( 'hook-pre-disconnect',
       
    55 	function ( args )
    54 	function ( args )
    56 		if oob_handler_registered then
    55 		if oob_handler_registered then
    57 			local connection = main.connection ()
    56 			local connection = main.connection ()
    58 			if connection then
    57 			if connection then
    59 				local conn = lm.connection.bless ( connection )
    58 				local conn = lm.connection.bless ( connection )
    60 				conn:handler ( oob_iq_handler, 'iq' )
    59 				conn:handler ( oob_iq_handler,      'iq'       )
    61 				conn:handler ( oob_message_handler, 'message' )
    60 				conn:handler ( oob_message_handler, 'message'  )
    62 				conn:handler ( oob_message_handler, 'presence' )
    61 				conn:handler ( oob_message_handler, 'presence' )
    63 			end
    62 			end
    64 			oob_handler_registered = false
    63 			oob_handler_registered = false
    65 		end
    64 		end
    66 	end )
    65 	end
    67 
    66 main.hook ( 'hook-post-connect',   oob_pc_handler )
       
    67 main.hook ( 'hook-pre-disconnect', oob_pd_handler )
    68 
    68 
    69 main.hook ( 'hook-lua-start',
    69 main.hook ( 'hook-lua-start',
    70 	function ( args )
    70 	function ( args )
    71 		main.add_feature ( 'jabber:iq:oob' )
    71 		main.add_feature ( 'jabber:iq:oob' )
    72 		main.add_feature ( 'jabber:x:oob' )
    72 		main.add_feature ( 'jabber:x:oob'  )
    73 		oob_pc_handler ()
    73 		oob_pc_handler ()
    74 	end )
    74 	end )
    75 main.hook ( 'hook-lua-quit',
    75 main.hook ( 'hook-lua-quit',
    76 	function ( args )
    76 	function ( args )
    77 		main.del_feature ( 'jabber:iq:oob' )
    77 		main.del_feature ( 'jabber:iq:oob' )
    78 		main.del_feature ( 'jabber:x:oob' )
    78 		main.del_feature ( 'jabber:x:oob'  )
       
    79 		oob_pd_handler ()
    79 	end )
    80 	end )
    80 
    81 
    81 -- vim: se ts=4 sw=4: --
    82 -- vim: se ts=4 sw=4: --