sample code for relaying local events out over xmpp?

26 views
Skip to first unread message

danbri

unread,
Oct 18, 2009, 12:59:12 PM10/18/09
to switchboard
Hi there

I'm learning my way around Switchboard. I've coded with XMPP before
but in other languages or toolkits.

I have some basic code (see http://svn.foaf-project.org/foaftown/buttons/osx/appleremote_buttons_wrapper.rb
) for reading OSX Apple Remote events. So I have a little bit of icky
ruby code which periodically wants to send something off across a
switchboard/xmpp connection. This means it's waiting mostly on the
local IR stuff. Can you recommend a pattern for integrating with
Switchboard?

cheers,

Dan

Seth Fitzsimmons

unread,
Oct 18, 2009, 1:06:10 PM10/18/09
to switc...@googlegroups.com

Your best bet is probably to start Switchboard in a different thread
before starting the event loop. You can hang on to a reference to the
client in your main thread and send messages with that in
`bubbleEvent`. This way Switchboard will be able to hang out and do
its own thing without interfering / blocking what you're doing.

seht

danbri

unread,
Oct 18, 2009, 1:15:16 PM10/18/09
to switchboard


On Oct 18, 7:06 pm, Seth Fitzsimmons <s...@mojodna.net> wrote:
> > I'm learning my way around Switchboard. I've coded with XMPP before
> > but in other languages or toolkits.
>
> > I have some basic code (seehttp://svn.foaf-project.org/foaftown/buttons/osx/appleremote_buttons_...
> > ) for reading OSX Apple Remote events. So I have a little bit of icky
> > ruby code which periodically wants to send something off across a
> > switchboard/xmpp connection. This means it's waiting mostly on the
> > local IR stuff. Can you recommend a pattern for integrating with
> > Switchboard?
>
> Your best bet is probably to start Switchboard in a different thread
> before starting the event loop. You can hang on to a reference to the
> client in your main thread and send messages with that in
> `bubbleEvent`.  This way Switchboard will be able to hang out and do
> its own thing without interfering / blocking what you're doing.

Thanks for the speedy response. I'll try that!

BTW is there a Web site planned? A random file I posted today is
already somehow 3rd google hit for 'switchboard ruby'...

I haven't dug into things very much yet but it seems a nice clean
toolkit and worth a bit of publicity.

cheers,

Dan


> seht

Dan Brickley

unread,
Oct 18, 2009, 2:01:50 PM10/18/09
to switc...@googlegroups.com

OK, very nearly there! I have a ref to a switchboard connection thread
passed in where I need it:

http://svn.foaf-project.org/foaftown/buttons/osx/buttonhole_surfer.rb

However I miss in the documentation an example for the simplest of
things: sending off a message. Is this because Switchboard uses other
libraries whose documentation I'm missing?

cheers,

Dan

Seth Fitzsimmons

unread,
Oct 18, 2009, 3:04:41 PM10/18/09
to switc...@googlegroups.com
> OK, very nearly there! I have a ref to a switchboard connection thread
> passed in where I need it:
>
> http://svn.foaf-project.org/foaftown/buttons/osx/buttonhole_surfer.rb
>
> However I miss in the documentation an example for the simplest of
> things: sending off a message. Is this because Switchboard uses other
> libraries whose documentation I'm missing?

Yup. Switchboard is essentially a wrapper around xmpp4r, so
`switchboard.client` will give you access to a `Jabber::Client`
object. Docs for that are here: http://home.gna.org/xmpp4r/rdoc/

seth

Reply all
Reply to author
Forward
0 new messages