Code Monkey home page Code Monkey logo

client-stream-chat-poc's Introduction

Stream Chat Client

Stream Chat Client is the official low-level Android SDK for Stream Chat, a service for building chat and messaging applications.

This library integrates directly with Stream Chat APIs and does not include UI; if you are interested in a SDK that includes UI components, you should check the stream-chat-android-core which comes with a collection of re-usable and customizable UI components.

Setup

dependencies {
    implementation 'com.github.getstream:stream-chat-android-client:<latest-version>'
}

Usage

  1. Create instance of client

    val client = StreamChatClient("api-key", "token")
  2. Set user

    client.setUser(ChatUser("id), { result ->
      if(result.isSuccess())
        getChannels()
      else
        showError(result.error())
    }
  3. Get channels

    fun getChannels() {
      client.getChannels().enqueue { result -> 
        if(result.isSuccess()
          showChannels(result.data())
        else
          showError(result.error())
      }
    }
  4. Send message

    client.sendMessage(channel, ChatMessage("hello"), { result -> 
      //handle result
    }
  5. Handle events

    val subscription = client.events().subscribe { event ->
    	if(event.type is ChatEvent.NEW_MESSAGE)
    	  showNewMessage(event.message)
    }
    subscription.unsubscribe()
    

Sync / Async

All methods of the library return Call object which allows to either execute request immediatly in the same thread or enqueue listener and get result in UI thread:

interface Call<T> {
    fun execute(): Result<T>
    fun enqueue(callback: (Result<T>) -> Unit)
    fun cancel()
}
//sync
val result = client.getChannels().execute()
//async
client.getChannels { result -> showChannels(result) }

More

  • Client life cycle
  • Push messages
  • Tokens
  • SDK architecture

Examples

client-stream-chat-poc's People

Contributors

elevenetc avatar tbarbugli avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.