How to get data when redis publish

I create 2 server and use redis pub/sub to send message. It's fine, but i don't know how to detect or catch this event by webix.
Example:
I have two server build in NODEJS: 'Client' and 'Publisher'
When 'Publisher' send 'hello' to 'Client'. How to use webix to catch this message 'hello' to show into screen.

Thank you WEBIX !

Comments

  • Hey @duynq2197, could you please provide more details on the exact use case, as I don't have enough information to go off here? How are you sending this message from the server, are you sending a response object? Are you actually sending a request from the client in the first place, or is it an independant server message?

  • My tech: NODEJS, REDIS and WEBIX
    I have create 2 server name A and B.
    A and B both connect to a server port WS
    When A update key redis, B will detect that and told all user who connect to B server and client side (webix) will use webix.message() to popup text.

    My mean is like when we use Websocket and catch on('message') event fire on client when receive request from server

  • I think you might find this article helpful, as it extensively covers the usage of WebSockets in tandem with Webix widgets.

  • Oh yeah. Look at the title of this topic i know it's exactly what i'm finding.
    Thank you.

  • import { JetView } from "webix-jet"
    export default class rt extends JetView {

    config() {
    //all data widgets
    webix.proxy.socket = {
    $proxy:true,
    load:function(view) {
    this.socket = new WebSocket("ws:"+this.source);
    this.socket.onerror = (error) => {
    console.log("WebSocket Error", error);
    };

        this.socket.onmessage = (e) => {
          var update = webix.DataDriver.json.toObject(e.data);
          if(update.key != this.key) return;
    
          if(update.clientId == this.clientId){
            if(update.operation == "insert")
              view.data.changeId(update.id, update.data.id);
          }
          else{
            webix.dp(view).ignore(() => {
              if (update.operation == "delete")
                view.remove(update.data.id);
              else if (update.operation == "insert")
                view.add(update.data);
              else if (update.operation == "update"){
                view.updateItem(update.data.id, update.data);
              }
            });
          }
        };
    
        view.attachEvent("onDestruct", () => {
          this.socket.close();
        });
      },
      save:function(view, update) {
        update.clientId = this.clientId;
        update.key = this.key;
        this.socket.send(webix.stringify(update));
      }
    };
    //define a common proxy for loading and saving with unique clientId and key
    var data_proxy = webix.proxy("socket", "//localhost:1234", {
      key:"data", clientId:webix.uid()
    });
    //Comments widget
    webix.proxy.comments = {
      init:function(){
        webix.extend(this, webix.proxy.socket);
      },
      load:function(view){
        webix.proxy.socket.load.call(this, view.queryView("list"));
      }
    };
    const grid = {
      view:"datatable", id:"grid",
      columns:[
          { id:"title", editor:"text",  header:"Film title",  width:200},
          { id:"year",  editor:"text",  header:"Released" , width:100},
          { header:"",  template:"{common.trashIcon()}", width:50}
      ],
      select:"row", editable:true, editaction:"dblclick",
      data:[
        {title:'Title_1', year:"Year_1", data:"ok"},
        {title:'Title_2', year:"Year_2", data:"ok"},
        {title:'Title_3', year:"Year_3", data:"ok"},
      ],
      url:data_proxy,
      save:data_proxy
    

    }
    var imagePath = "https://docs.webix.com/samples/30_comments/common/imgs/";
    const user = {
    view:"comments",
    id:"comments",
    width: 450,
    currentUser:4,
    data: [
    {id: 1,user_id:1, text:'hello', date:new Date()}
    ],
    users: [
    { id:1, value:"Corvo Attano", image: imagePath + "corvo.jpg", status:"none" },
    { id:2, value:"Daisy Fitzroy", image: imagePath + "daisy.jpg", status:"busy" },
    { id:3, value:"Glenn Crake", image: imagePath + "glenn.jpg", status:"busy" },
    { id:4, value:"Me", image: imagePath + "tomek.jpg", status:"active" },
    { id:5, value:"Leia Organa", image: imagePath + "leia.jpg", status:"away" }
    ]
    }
    return {rows:[
    grid,user
    ]}
    }

    urlChange() {
    }
    init() {
    // $$("data").data.attachEvent("onStoreUpdated", (id, update, operation) => {
    // socket.send(webix.stringify(update));
    // });
    }
    }

  • when i run this code, when edit input, it told me error in this.socket.send()

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!