1.0.10 • Published 3 years ago

firesocket-server v1.0.10

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Firesocket

Firesocket is a websocket connection library using firestore and cloud function.

Quick start

  1. Allow to read /documents/firesockets/{event} like this:

    rules_version = '2';
    service cloud.firestore {
      match /databases/{database}/documents {
        match /firesocket/{event} {
          allow read: if "*" in resource.data.to || request.auth.uid in resource.data.to;
          allow write: if false;
        }
      }
    }
  2. Create an index for firesocket collection as:

    KeyVal
    Collection idfiresocket
    Fieldsto arrays, at ascending
    Scopecollection
  3. Import firesocket-server to your cloud functions like this:

    const functions = require("firebase-functions");
    const { initializeApp } = require("firebase-admin/app");
    const { Firesocket } = require("firesocket-server");
    
    const app = initializeApp();
    
    // intialize firesocket
    const firesocket = new Firesocket(app);
    
    // register firesocket handler
    exports.firesocketHandler = functions.https.onCall(firesocket.handler);
    
    // define functions
    firesocket.on("broadcast-message", (data, uid) => {
      firesocket.emit("view-message", {
        message: data.message,
        from: uid,
      });
    });
    
    firesocket.on("broadcast-message", (data, uid) => {
      firesocket.emit(
        "view-message",
        {
          message: data.message,
          from: null,
        },
        [uid]
      );
    });

    Now, event listeners for broadcast-message and echo-message are activated.

firesocket options

const options = {
  collectionName: "firesocket" // name of collection used firesocket. if you change it, you also have to change collection name in rules and an index.
  documentRetentionTime: 0 // time of document retention(ms). if it's 0, all document will be cleared instantly. if it's -1, document will not be cleared.
}

// intialize firesocket
const firesocket = new Firesocket(app, options);

LISENCE

MIT

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago