Code Monkey home page Code Monkey logo

muni's Introduction

Muni

Chat framework

Feature ๐ŸŽŠ

โ˜‘๏ธ Serverless - Firebase Cloud Firestore
โ˜‘๏ธ Realtime
โ˜‘๏ธ Customizable
โ˜‘๏ธ Type Safe
โ˜‘๏ธ Multi Media

Media

  • Text
  • Image
  • Video
  • Audio
  • Location
  • Sticker
  • ImageMap

Installation โš™

pod 'Muni' add to your Podfile

pod install

GoogleService-Info.plist add to your Project

Usage

Prepare three documents for cloud firestore.

UserProtocol RoomProtocol TranscriptProtocol create document conforming to each protocol.

@objcMembers
class User: Object, UserProtocol {
    var name: String?
    var thumbnailImage: File?
}
@objcMembers
class Room: Object, RoomProtocol {
    typealias TranscriptType = Transcript
    dynamic var name: String?
    dynamic var thumbnailImage: File?
    dynamic var viewers: [String] = []
    dynamic var members: [String] = []
    dynamic var recentTranscript: [String: Any] = [:]
    dynamic var transcripts: NestedCollection<TranscriptType> = []
    dynamic var config: [String: Any] = [:]
    dynamic var isMessagingEnabled: Bool = true
    dynamic var isHidden: Bool = false
    dynamic var lastViewedTimestamps: [String : Timestamp] = [:]
}
@objcMembers
class Transcript: Object, TranscriptProtocol {
    dynamic var to: Relation<Room> = .init()
    dynamic var from: Relation<User> = .init()
    dynamic var text: String?
    dynamic var image: File?
    dynamic var video: File?
    dynamic var audio: File?
    dynamic var location: GeoPoint?
    dynamic var sticker: String?
    dynamic var imageMap: [File] = []
}

Override two ViewControllers

class MessageViewController: Muni<User, Room, Transcript>.MessagesViewController {

    var sendBarItem: ToolbarItem!

    override var senderID: String? {
        return Auth.auth().currentUser!.uid
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        self.sendBarItem = ToolbarItem(title: "Send", target: self, action: #selector(send))
        self.toolBar.setItems([ToolbarItem(customView: self.textView), self.sendBarItem], animated: false)
        
        // Start
        self.listen()
    }

    override func transcript(willSend transcript: Transcript) -> Bool {
        guard let text: String = self.textView.text else { return false }
        if text.isEmpty { return false }
        transcript.text = text
        self.textView.text = nil
        return true
    }
}
class BoxViewController: Muni<User, Room, Transcript>.InboxViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Start
        self.listen()
    }

    override func messageViewController(with room: Room) -> Muni<User, Room, Transcript>.MessagesViewController {
        return MessageViewController(roomID: room.id)
    }
}

Build

Muni internally uses Firestore Query. An error occurs if there is no Index in Firestore. You can create an Index by accessing the URL on the console.

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.