This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Server side | |
socket.on('message', (message) => { | |
// Save the message document in the `messages` collection. | |
db.collection('messages').insert(message); | |
// The `broadcast` allows us to send to all users but the sender. | |
socket.broadcast.emit('message', message); | |
}); | |
// Client side |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Client side | |
determineUser() { | |
AsyncStorage.getItem('userId') | |
.then((userId) => { | |
if (userId) { | |
this.socket.emit('i-dont-need-an-id'); | |
} else { | |
this.socket.emit('i-need-id'); | |
this.socket.on('here-is-your-id', (id) => { | |
AsyncStorage.setItem('userId', id); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import SocketIOClient from 'socket.io-client'; | |
class Main extends React.Component { | |
constructor(props) { | |
super(props); | |
// Creating the socket-client instance will automatically connect to the server. | |
this.socket = SocketIOClient('http://localhost:3000'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var http = require('http') | |
var socketio = require('socket.io'); | |
var app = express(); | |
var server = http.Server(app); | |
var websocket = socketio(server); | |
server.listen(3000, () => console.log('listening on *:3000')); | |
// The event will be called when a client is connected. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table'; | |
class Table extends React.Component { | |
constructor(props) { | |
super(props); | |
} | |
render() { | |
var products = [ | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
let defaults = NSUserDefaults.standardUserDefaults(); | |
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | |
window = UIWindow(frame: UIScreen.mainScreen().bounds) | |
storyboard = UIStoryboard(name: "Main", bundle: nil) | |
let leftView = storyboard?.instantiateViewControllerWithIdentifier("LeftMenuController") | |
let rightView = storyboard?.instantiateViewControllerWithIdentifier("RightMenuController") |
NewerOlder