-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for XMPP rosters on connect #65
Changes from 1 commit
ab19465
7cfd72c
0f31627
b454cc5
c0f33e7
582627d
d0255cd
7a9e91c
03053a4
520ec12
2df335e
7fbbab1
cac7fe0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,11 @@ class XmppBot extends Adapter | |
@connected = false | ||
@configClient(options) | ||
|
||
# Expose the XMPP client through the robot to allow third-party scripts | ||
# to send messages directly | ||
@robot.xmppClient = @client | ||
@robot.xmppRoster = [] | ||
|
||
configClient: (options) -> | ||
@client.connection.socket.setTimeout 0 | ||
@client.connection.socket.setKeepAlive true, options.keepaliveInterval | ||
|
@@ -152,6 +157,14 @@ class XmppBot extends Adapter | |
|
||
@robot.logger.debug "[sending pong] #{pong}" | ||
@client.send pong | ||
# Keep a record of the client's primarty roster after connecting, so that | ||
# scripts have the option of sending messages to all of the clients contacts | ||
else (stanza.attrs.id == 'roster_1' && stanza.children[0]['children']) | ||
roster_items = stanza.children[0]['children'] | ||
|
||
for item in roster_items | ||
jid = new Xmpp.JID(item.attrs.jid) | ||
@robot.xmppRoster.push(jid) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this result in duplicates if the bot sat in multiple rooms with the same people? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, I don't use rooms. Could certainly add some checking to ensure there are no dupes. |
||
|
||
readMessage: (stanza) => | ||
# ignore non-messages | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the robot had a reference to the adapter it was using. I could be wrong though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently there is a
robot.adapter
. I will make sure it works the same as what I'm doing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would need
robot.adapter.client
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed that
robot.adapter.client
works