All Projects → kamax-matrix → matrix-java-sdk

kamax-matrix / matrix-java-sdk

Licence: AGPL-3.0 license
Matrix Java SDK

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to matrix-java-sdk

matlib
Matrix Functions for Teaching and Learning Linear Algebra and Multivariate Statistics, http://friendly.github.io/matlib/
Stars: ✭ 55 (+175%)
Mutual labels:  matrix
instagram
A Matrix-Instagram DM puppeting bridge
Stars: ✭ 69 (+245%)
Mutual labels:  matrix
libQuotient
A Qt5 library to write cross-platform clients for Matrix
Stars: ✭ 101 (+405%)
Mutual labels:  matrix
TeamReference
Team reference for Competitive Programming. Algorithms implementations very used in the ACM-ICPC contests. Latex template to build your own team reference.
Stars: ✭ 29 (+45%)
Mutual labels:  matrix
matrix-appservice-bridge
Bridging infrastructure for Application Services
Stars: ✭ 119 (+495%)
Mutual labels:  matrix
matrex
A WIP toy Matrix server implementation in Elixir
Stars: ✭ 31 (+55%)
Mutual labels:  matrix
saddle
SADDLE: Scala Data Library
Stars: ✭ 23 (+15%)
Mutual labels:  matrix
Morpheus
A Matrix client written in Go-QT
Stars: ✭ 20 (+0%)
Mutual labels:  matrix
JOLI.jl
Julia Operators LIbrary
Stars: ✭ 14 (-30%)
Mutual labels:  matrix
matrix-email-bot
A bot that posts messages to rooms when an email is received.
Stars: ✭ 33 (+65%)
Mutual labels:  matrix
morpheus.js
JavaScript matrix visualization and analysis
Stars: ✭ 51 (+155%)
Mutual labels:  matrix
DPVideoMerger-Swift
Multiple videos merge in one video with manage scale & aspect ratio and also merge videos to grid matrix layout for Swift.
Stars: ✭ 49 (+145%)
Mutual labels:  matrix
Swiftish
A fully generic Swift vector & matrix library
Stars: ✭ 17 (-15%)
Mutual labels:  matrix
matrix-pstn-bridge
☎️ A Matrix Puppet bridge for the public telephone network that supports a number of VoIP providers (Twillo, Vonage, etc.). Sends and receives voice and SMS.
Stars: ✭ 25 (+25%)
Mutual labels:  matrix
matrix-registration
a token based matrix registration api
Stars: ✭ 182 (+810%)
Mutual labels:  matrix
vec-la-fp
↗️ A tiny (functional) 2d linear algebra library
Stars: ✭ 21 (+5%)
Mutual labels:  matrix
planar proj shadows
Demo of Planar Projected Shadows in regl
Stars: ✭ 31 (+55%)
Mutual labels:  matrix
MRSignalsSeqs
Stanford University Rad229 Class Code: MRI Signals and Sequences
Stars: ✭ 72 (+260%)
Mutual labels:  matrix
synadm
Command line admin tool for Synapse (Matrix reference homeserver)
Stars: ✭ 93 (+365%)
Mutual labels:  matrix
MD UISwitch
Uniformly encapsulate different types of switches as user input devices
Stars: ✭ 33 (+65%)
Mutual labels:  matrix

Matrix Client SDK for Java

Build Status


This project is no longer maintained.


Purpose

Matrix SDK in Java 1.8 for:

  • Client -> Homeserver
  • Client -> Identity Server
  • Application Server -> Homeserver

Use

Add to your project

Gradle

repositories {
    maven {
        url 'https://kamax.io/maven/releases/'
    }
}

dependencies {
    compile 'io.kamax:matrix-java-sdk:<USE_LATEST_TAG_WITHOUT_LEADING_V>'
}

Maven

<repositories>
  <repository>
    <id>kamax-io</id>
    <name>kamax-io</name>
    <url>https://kamax.io/maven/releases/</url>
  </repository>
</repositories>
<dependencies>
  <dependency>
    <groupId>io.kamax</groupId>
    <artifactId>matrix-java-sdk</artifactId>
    <version>USE_LATEST_TAG_WITHOUT_LEADING_V</version>
  </dependency>
</dependencies>

WARNING: This SDK was originally created to support Kamax.io projects and is therefore not necessarily complete. It will be built as the various projects evolve and grow. The SDK is therefore still in Alpha.

Getting started

Getting the client object

With .well-known auto-discovery:

_MatrixClient client = new MatrixHttpClient("example.org");
client.discoverSettings();

With C2S API Base URL:

URL baseUrl = new URL("https://example.org");
_MatrixClient client = new MatrixHttpClient(baseUrl);

Providing credentials

Access token:

client.setAccessToken(accessToken);

Log in:

client.login(new MatrixPasswordCredentials(username, password));

Sync

// We will update this after each sync call
String syncToken = null;

// We sync until the process is interrupted via Ctrl+C or a signal
while (!Thread.currentThread().isInterrupted()) {
    
    // We provide the next batch token, or null if we don't have one yet
    _SyncData data = client.sync(SyncOptions.build().setSince(syncToken).get());
    
    // We check the joined rooms
    for (JoinedRoom joinedRoom : data.getRooms().getJoined()) {
        // We get the relevant room object to act on it while we process
        _Room room = client.getRoom(joinedRoom.getId());
        
        for (_MatrixEvent rawEv : joinedRoom.getTimeline()) {
            // We only want to act on room messages
            if ("m.room.message".contentEquals(rawEv.getType())) {
                MatrixJsonRoomMessageEvent msg = new MatrixJsonRoomMessageEvent(rawEv.getJson());
                
                // Ping?
                if (StringUtils.equals("ping", msgg.getBody())) {
                    // Pong!
                    room.sendText("pong");
                }
            }
        }
    }
    
    // We check the invited rooms
    for (InvitedRoom invitedRoom : data.getRooms().getInvited()) {
        // We auto-join rooms we are invited to
        client.getRoom(invitedRoom.getId()).join());
    }
    
    // Done processing sync data. We save the next batch token for the next loop execution
    syncToken = data.nextBatchToken();
}

As an Application Service

Use MatrixApplicationServiceClient instead of MatrixHttpClient when creating the main client object.

To talk to the API as a virtual user, use the method createClient(localpart) on MatrixApplicationServiceClient, then processed normally.

Real-world usage

As a regular client

You can check the Send'n'Leave bot which make uses of this SDK in a more realistic fashion.
Direct link to the relevant code: here

As an Application Service

Contribute

Contributions and PRs are welcome to turn this into a fully fledged Matrix Java SDK.
Your code will be licensed under AGPLv3.

To ensure code formatting consistency, we use Spotless.
Before opening any PR, make sure you format the code:

./gradlew spotlessApply

Your code must pass all existing tests with and must provide tests for any new method/class/feature.
Make sure you run:

./gradlew test
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].