All Projects → naqvis → cr-xmpp

naqvis / cr-xmpp

Licence: MIT License
XMPP/Jabber Library for Crystal

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to cr-xmpp

Smack
Smack is an open-source, highly modular, easy to use, XMPP client library written in Java for Java SE compatible JVMs and Android.
Stars: ✭ 2,267 (+14068.75%)
Mutual labels:  xmpp, jabber, xmpp-client-library
ejabberd mod gcm
Google Cloud Messaging API for Ejabberd (PUSH Messages)
Stars: ✭ 27 (+68.75%)
Mutual labels:  xmpp, jabber
ejabberd mod apns
An ejabberd module to send PUSH messages to iOS devices through APNS
Stars: ✭ 31 (+93.75%)
Mutual labels:  xmpp, jabber
xmpp
An implementation of the Extensible Messaging and Presence Protocol (XMPP) in Go.
Stars: ✭ 97 (+506.25%)
Mutual labels:  xmpp, jabber
Lurch4Adium
OMEMO Xtra for Adium (packaging the lurch and carbons libpurple plugins)
Stars: ✭ 38 (+137.5%)
Mutual labels:  xmpp, jabber
brotli.cr
Crystal bindings to the Google brotli compression library
Stars: ✭ 20 (+25%)
Mutual labels:  crystal-language, crystal-lang
ngx-chat
Angular XMPP Client & Chat UI
Stars: ✭ 30 (+87.5%)
Mutual labels:  xmpp, jabber
Lurch
XEP-0384: OMEMO Encryption for libpurple.
Stars: ✭ 245 (+1431.25%)
Mutual labels:  xmpp, jabber
xabber-web
Open source XMPP client for Web
Stars: ✭ 117 (+631.25%)
Mutual labels:  xmpp, jabber
vacuum-im
Cross-platform XMPP client
Stars: ✭ 90 (+462.5%)
Mutual labels:  xmpp, jabber
SharpXMPP
XMPP library for .NET/Xamarin/.NET Core
Stars: ✭ 17 (+6.25%)
Mutual labels:  xmpp, jabber
praetorian
A minimalist Crystal authorization system inspired by https://github.com/varvet/pundit.
Stars: ✭ 54 (+237.5%)
Mutual labels:  crystal-language, crystal-lang
triki
Mysql, PostgreSQL and SQL dump obfuscator aka anonimizer
Stars: ✭ 28 (+75%)
Mutual labels:  crystal-language, crystal-lang
stork
(M) Android XMPP Client
Stars: ✭ 51 (+218.75%)
Mutual labels:  xmpp, jabber
Converse.js
Web-based XMPP/Jabber chat client written in JavaScript
Stars: ✭ 2,745 (+17056.25%)
Mutual labels:  xmpp, jabber
xmpp-php
PHP client library for XMPP (Jabber) protocol
Stars: ✭ 33 (+106.25%)
Mutual labels:  xmpp, jabber
jaxmpp
Java XMPP client library
Stars: ✭ 19 (+18.75%)
Mutual labels:  xmpp, jabber
Openfire
Openfire is a real time collaboration (RTC) server licensed under the Open Source Apache License. It uses the only widely adopted open protocol for instant messaging, XMPP (also called Jabber). Openfire is incredibly easy to setup and administer, but offers rock-solid security and performance.
Stars: ✭ 2,423 (+15043.75%)
Mutual labels:  xmpp, jabber
isotoxin
Isotoxin source
Stars: ✭ 69 (+331.25%)
Mutual labels:  xmpp, jabber
snatch
An Erlang Lightweight XMPP Client library
Stars: ✭ 16 (+0%)
Mutual labels:  xmpp, xmpp-component

Crystal XMPP

CI GitHub release Docs

Pure Crystal XMPP Shard, focusing on simplicity, simple automation, and IoT.

The goal is to make simple to write simple XMPP clients and components. It features:

  • Fully OOP
  • Aims at being XMPP compliant
  • Event Based
  • Easy to extend
  • For automation (like for example monitoring of an XMPP service),
  • For building connected "things" by plugging them on an XMPP server,
  • For writing simple chatbot to control a service or a thing,
  • For writing XMPP servers components.

You can basically do everything you want with cr-xmpp. It fully supports XMPP Client and components specification, and also a wide range of extensions (XEPs). And it's very easy to extend :)

This Shard does not have any other dependencies.

Supported specifications

Clients

Components

XEP Extensions

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      cr-xmpp:
        github: naqvis/cr-xmpp
  2. Run shards install

Usage

require "cr-xmpp"

config = XMPP::Config.new(
  host: "localhost",
  jid: "test@localhost",
  password: "test",
  log_file: STDOUT,   # Capture all out-going and in-coming messages
  # Order of SASL Authentication Mechanism, first matched method supported by server will be used
  # for authentication. Below is default order that will be used if `sasl_auth_order` param is not set.
  sasl_auth_order: [XMPP::AuthMechanism::SCRAM_SHA_512, XMPP::AuthMechanism::SCRAM_SHA_256,
                    XMPP::AuthMechanism::SCRAM_SHA_1, XMPP::AuthMechanism::DIGEST_MD5,
                    XMPP::AuthMechanism::PLAIN, XMPP::AuthMechanism::ANONYMOUS]
)

router = XMPP::Router.new

# router.on "presence" do |_, p|  # OR
router.presence do |_, p|
  if (msg = p.as?(XMPP::Stanza::Presence))
    puts msg
  else
    puts "Ignoring Packet: #{p}"
  end
end

# router.when "chat" do |s, p| # OR
router.message do |s, p|
  handle_message(s, p)
end

# OR
# router.on "message", ->handle_message(XMPP::Sender, XMPP::Stanza::Packet)

client = XMPP::Client.new config, router
# If you pass the client to a connection manager, it will handle the reconnect policy
# for you automatically
sm = XMPP::StreamManager.new client
sm.run


def handle_message(s : XMPP::Sender, p : XMPP::Stanza::Packet)
  if (msg = p.as?(XMPP::Stanza::Message))
    puts "Got message: #{msg.body}"
    reply = XMPP::Stanza::Message.new
    reply.to = msg.from
    reply.body = "#{msg.body}"
    s.send reply
  else
    puts "Ignoring Packet: #{p}"
  end
end

Refer to examples for more usage details.

Development

XMPP stanzas are basic and extensible XML elements. Stanzas (or sometimes special stanzas called 'nonzas') are used to leverage the XMPP protocol features. During a session, a client (or a component) and a server will be exchanging stanzas back and forth.

At a low-level, stanzas are XML fragments. However, this shard provides the building blocks to interact with stanzas at a high-level, providing a Crystal-friendly API.

The XMPP::Stanza module provides support for XMPP stream parsing, encoding and decoding of XMPP stanza. It is a bridge between high-level Crystal classes and low-level XMPP protocol.

Parsing, encoding and decoding is automatically handled by Crystal XMPP client shard. As a developer, you will generally manipulates only the high-level classes provided by the XMPP::Stanza module.

The XMPP protocol, as the name implies is extensible. If your application is using custom stanza extensions, you can implement your own extensions directly.

Custom Stanza Support

Below example show how to implement a custom extension for your own client, without having to modify or fork Crystal XMPP shard.

class CustomExtension < Extension
    include IQPayload
    class_getter xml_name : XMLName = XMLName.new("my:custom:payload query")
    property node : String = ""

    def self.new(node : XML::Node)
      raise "Invalid node(#{node.name}, expecting #{@@xml_name.to_s}" unless (node.namespace.try &.href == @@xml_name.space) &&
                                                                             (node.name == @@xml_name.local)
      cls = new()
      node.children.select(&.element?).each do |child|
      case child.name
        when "item" then cls.node = child.content
        end
      end
      cls
    end

    def to_xml(elem : XML::Builder)
      elem.element(@@xml_name.local, xmlns: @@xml_name.space) do
        elem.element("node") { elem.text node } unless node.blank?
      end
    end

    def namespace : String
      @@xml_name.space
    end

    def name : String
      @@xml_name.local
    end
  end

  Registry.map_extension(PacketType::IQ, XMLName.new("my:custom:payload", "query"), CustomExtension)

Contributing

  1. Fork it (https://github.com/naqvis/cr-xmpp/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].