Giter Club home page Giter Club logo

wsexample's Introduction

wsExample

Demo of Websockets in react native

Basic test of react-native websocket polyfill https://github.com/badfortrains/react-native/tree/WebSocket

This is a very early demo, and the polyfill contains bug. Specifically, it leaks memory and does not handle errors correctly. Currently binary data is not supported.

Includes slightlty modified versions of Firebase-client and Socket.io-client.

##Firebase Loads firebase posts examples, and appends results as Text elements into page. Modeled after first example from https://www.firebase.com/docs/web/guide/retrieving-data.html. Data loaded from https://docs-examples.firebaseio.com/web/saving-data/fireblog/posts.

Note: In order for firebase to work, had to slightly modify the firebase client (firebase-debug)

  • Forced to always use websockets (JSONP breaks since the dom is not supported)
  • Changed how global scope handling
var goog = goog || {};
goog.global = this;

to

var goog = {};
window.goog =goog;

##Socket-io Simplified chat example. Includes chat server from https://github.com/rauchg/chat-example.
Start chat server with node chatServer.Navigate to http://localhost:5000 to open chat window, sent messages will be appended as text views in the react-native app.

Note:

  • JSONP polling will cause a crash since dom is not supported, need to pass {jsonp: false} on connect.
  • Socket.io expects window.navigator.userAgent to be a string, need to set
window.navigator.userAgent = "react-native"; //or any other string value

before including socket.io-client.

  • The react-native package manager does not build the socket.io-client library correctly (not sure why, may be based on us wanting the browser version and react-native ignoring the "browser" field in engine.io's package file). Luckily the socket.io-client includes a prebuilt verison of the library that we can include, albiet with a hacky relative include path var io = require("./node_modules/socket.io/node_modules/socket.io-client/socket.io");

wsexample's People

Contributors

badfortrains avatar rkho avatar

Watchers

James Cloos avatar Lauren Spiegel 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.