1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-14 02:06:29 +00:00

リアルタイム(SocketIO)実装 / Markdown style改善

This commit is contained in:
Rokt33r
2015-09-08 15:28:36 +09:00
parent 51bd12c6cf
commit a3847ce1c9
24 changed files with 176 additions and 110 deletions

View File

@@ -0,0 +1,64 @@
/* global localStorage */
var config = require('../../../config')
var UserStore = require('../Stores/UserStore')
var PlanetStore = require('../Stores/PlanetStore')
var io = require('socket.io-client')(config.apiUrl)
io.on('connected', function (data) {
console.log('connected by WS')
reconnect()
})
io.on('userUpdated', function (data) {
console.log('userUpdated')
UserStore.Actions.update(data)
})
// Planet
io.on('planetUpdated', function (data) {
console.log('planetUpdated')
PlanetStore.Actions.update(data)
})
io.on('planetDestroyed', function (data) {
console.log('planetDestroyed')
PlanetStore.Actions.destroy(data)
})
// Article
io.on('codeUpdated', function (data) {
console.log('codeUpdated')
PlanetStore.Actions.updateCode(data)
})
io.on('codeDestroyed', function (data) {
console.log('codeDestroyed')
PlanetStore.Actions.destroyCode(data)
})
io.on('noteUpdated', function (data) {
console.log('noteUpdated')
PlanetStore.Actions.updateNote(data)
})
io.on('noteDestroyed', function (data) {
console.log('noteDestroyed')
PlanetStore.Actions.destroyNote(data)
})
var reconnect = function (currentUser) {
if (currentUser == null) currentUser = JSON.parse(localStorage.getItem('currentUser'))
if (currentUser != null) {
var rooms = ['user:' + currentUser.id].concat(currentUser.Teams.map(function (team) {
return 'user:' + team.id
}))
io.emit('room:sync', {rooms: rooms})
} else {
io.emit('room:sync', {rooms: []})
}
}
module.exports = {
io: io,
reconnect: reconnect
}