Skip to content
ezyfox-react-native-client
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
android
ezy-client
ios
.gitignore
LICENSE
README.md
index.js
package.json

README.md

ezyfox-server-react-native-client

react-native client for ezyfox server

Synopsis

react-native client for ezyfox server

Code Example

1. Prepare to listen socket event

class App extends React.Component {
  constructor(args) {
    super(args);
    this.host = "192.168.51.103";
    this.clients = Ezy.Clients.getInstance();
    this.clients.processEvents();
  }

2. Setup socket client

setupClient(client) {
    var setup = client.setup;
    
    var handshakeHandler = new Ezy.HandshakeHandler();
    handshakeHandler.getLoginRequest = () => {
        return ["freechat", "dungtv", "123456", []];
    };

    var loginSuccessHandler = new Ezy.LoginSuccessHandler();
    loginSuccessHandler.handleLoginSuccess = data => {
        client.sendRequest(Ezy.Command.APP_ACCESS, ["freechat", []]);
    };

    var accessAppHandler = new Ezy.AppAccessHandler();
    accessAppHandler.postHandle = (app, data) => {
        app.sendRequest("5", {skip: 0, limit: 50});
    };

    setup.addDataHandler(Ezy.Command.HANDSHAKE, handshakeHandler);
    setup.addDataHandler(Ezy.Command.LOGIN, loginSuccessHandler);
    setup.addDataHandler(Ezy.Command.APP_ACCESS, accessAppHandler);
}

2. Connect to server

componentDidMount() {
    this.clients.newDefaultClient({zoneName: "freechat"}, client => {
      this.setupClient(client);
      client.connect(this.host, 3005);
    });
  }
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.