Skip to content

Instantly share code, notes, and snippets.

@alcides
Created April 7, 2011 18:46
Show Gist options
  • Save alcides/908411 to your computer and use it in GitHub Desktop.
Save alcides/908411 to your computer and use it in GitHub Desktop.
Atempt to make a browser through xmpp. DOES NOT WORK.
require 'rubygems'
require 'xmpp4r/client'
require 'open-uri'
require 'sanitize'
include Jabber
class ClientB < Client
def main_loop
keepalive_loop
end
end
# Login
jid = JID::new('[email protected]/web')
password = 'youwish'
cl = ClientB::new(jid)
cl.connect
cl.auth(password)
# Create a message
to = "[email protected]"
subject = "XMPP4R Rich-Text Test"
body = "Wow, I can do HTML now. But if you see this, your client doesn't support it"
m = Message::new(to, body).set_type(:normal).set_id('1').set_subject(subject)
# Create the html part
h = REXML::Element::new("html")
h.add_namespace('http://jabber.org/protocol/xhtml-im')
# The body part with the correct namespace
b = REXML::Element::new("body")
b.add_namespace('http://www.w3.org/1999/xhtml')
# The html itself
t = REXML::Text.new( "This is so <strong><span style='background: #003EFF; '><span style='font-size: large; '>COOL!!!</span></span></strong>. I can really do <strong>HTML</strong> now.", false, nil, true, nil, %r/.^/ )
# Add the html text to the body, and the body to the html element
b.add(t)
h.add(b)
# Add the html element to the message
m.add_element(h)
# Send it
cl.send m
k=0
cl.add_message_callback do |m|
if m.body != nil
k+=1
contents = URI.parse(m.body).read
contents = Sanitize.clean(contents, Sanitize::Config::BASIC)
m = Message::new(m.from.to_s, contents)
cl.send(m)
end
end
cl.main_loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment