Merge pull request #929 from metamaps/fix/develop-bugs
fix some develop bugs, merge master, and move realtime port to .env
This commit is contained in:
commit
51d5d77629
13 changed files with 54 additions and 21 deletions
|
@ -1,10 +1,14 @@
|
|||
# Node JS env
|
||||
export NODE_REALTIME_PORT='5000' # should match REALTIME_SERVER, below
|
||||
|
||||
# Rails env
|
||||
export DB_USERNAME='postgres'
|
||||
export DB_PASSWORD='3112'
|
||||
export DB_HOST='localhost'
|
||||
export DB_PORT='5432'
|
||||
export DB_NAME='metamap002'
|
||||
|
||||
export REALTIME_SERVER='http://localhost:5001'
|
||||
export REALTIME_SERVER='http://localhost:5000'
|
||||
export MAILER_DEFAULT_URL='localhost:3000'
|
||||
export DEVISE_MAILER_SENDER='team@metamaps.cc'
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class AccessController < ApplicationController
|
|||
|
||||
# POST maps/:id/access
|
||||
def access
|
||||
user_ids = params[:access] || []
|
||||
user_ids = params[:access].to_a.map(&:to_i) || []
|
||||
|
||||
@map.add_new_collaborators(user_ids).each do |user_id|
|
||||
# add_new_collaborators returns array of added users,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# frozen_string_literal: true
|
||||
# bad code that should be checked over before entering one of the
|
||||
# nice files from the right side of this repo
|
||||
class HacksController < ApplicationController
|
||||
|
@ -11,7 +12,7 @@ class HacksController < ApplicationController
|
|||
response, url = get_with_redirects(url)
|
||||
title = get_encoded_title(response)
|
||||
render json: { success: true, title: title, url: url }
|
||||
rescue StandardError => e
|
||||
rescue StandardError
|
||||
render json: { success: false }
|
||||
end
|
||||
|
||||
|
@ -28,7 +29,13 @@ class HacksController < ApplicationController
|
|||
end
|
||||
|
||||
def get_encoded_title(http_response)
|
||||
title = http_response.body.sub(/.*<title>(.*)<\/title>.*/m, '\1')
|
||||
# ensure there's actually an html title tag
|
||||
title = http_response.body.sub(%r{.*(<title>.*</title>).*}m, '\1')
|
||||
return '' unless title.starts_with?('<title>')
|
||||
return '' unless title.ends_with?('</title>')
|
||||
title = title.sub('<title>', '').sub(%r{</title>$}, '')
|
||||
|
||||
# encode and trim the title to 140 usable characters
|
||||
charset = http_response['content-type'].sub(/.*charset=(.*);?.*/, '\1')
|
||||
charset = nil if charset == 'text/html'
|
||||
title = title.force_encoding(charset) if charset
|
||||
|
|
|
@ -93,10 +93,10 @@ server to see what problems show up:
|
|||
#### Realtime server:
|
||||
|
||||
sudo npm install -g forever
|
||||
(crontab -u metamaps -l 2>/dev/null; echo "@reboot $(which forever) --append -l /home/metamaps/logs/forever.realtime.log start /home/metamaps/metamaps/realtime/realtime-server.js") | crontab -u metamaps -
|
||||
(crontab -u metamaps -l 2>/dev/null; echo "@reboot env NODE_REALTIME_PORT=5000 $(which forever) --append -l /home/metamaps/logs/forever.realtime.log start /home/metamaps/metamaps/realtime/realtime-server.js") | crontab -u metamaps -
|
||||
|
||||
mkdir -p /home/metamaps/logs
|
||||
forever --append \
|
||||
env NODE_REALTIME_PORT=5000 forever --append \
|
||||
-c /home/metamaps/metamaps/node_modules/.bin/babel-node \
|
||||
-l /home/metamaps/logs/forever.realtime.log \
|
||||
start /home/metamaps/metamaps/realtime/realtime-server.js
|
||||
|
|
|
@ -38,6 +38,7 @@ const Synapse = Backbone.Model.extend({
|
|||
|
||||
newOptions.success = function(model, response, opt) {
|
||||
if (s) s(model, response, opt)
|
||||
model.set('calculated_permission', model.get('permission'))
|
||||
model.trigger('saved')
|
||||
|
||||
if (permBefore === 'private' && model.get('permission') !== 'private') {
|
||||
|
|
|
@ -37,8 +37,8 @@ const Topic = Backbone.Model.extend({
|
|||
|
||||
newOptions.success = function(model, response, opt) {
|
||||
if (s) s(model, response, opt)
|
||||
model.trigger('saved')
|
||||
model.set('calculated_permission', model.get('permission'))
|
||||
model.trigger('saved')
|
||||
|
||||
if (permBefore === 'private' && model.get('permission') !== 'private') {
|
||||
model.trigger('noLongerPrivate')
|
||||
|
|
|
@ -375,6 +375,7 @@ const Import = {
|
|||
$.get('/hacks/load_url_title', {
|
||||
url
|
||||
}, function success(data, textStatus) {
|
||||
if (data.trim() === '') return
|
||||
var selector = '#showcard #topic_' + topic.get('id') + ' .best_in_place'
|
||||
if ($(selector).find('form').length > 0) {
|
||||
$(selector).find('textarea, input').val(data.title)
|
||||
|
|
|
@ -25,7 +25,7 @@ const PasteInput = {
|
|||
self.handleFile(e.dataTransfer.files[0], coords)
|
||||
}
|
||||
// OMG import bookmarks 😍
|
||||
if (e.dataTransfer.items.length > 0) {
|
||||
if (e.dataTransfer.items && e.dataTransfer.items.length > 0) {
|
||||
e.dataTransfer.items[0].getAsString(function(text) {
|
||||
if (text.match(self.URL_REGEX)) {
|
||||
self.handle(text, coords)
|
||||
|
|
|
@ -172,7 +172,11 @@ let Realtime = {
|
|||
room: 'global',
|
||||
$video: self.localVideo.$video,
|
||||
myVideoView: self.localVideo.view,
|
||||
config: { DOUBLE_CLICK_TOLERANCE: 200 }
|
||||
config: { DOUBLE_CLICK_TOLERANCE: 200 },
|
||||
soundUrls: [
|
||||
serverData['sounds/MM_sounds.mp3'],
|
||||
serverData['sounds/MM_sounds.ogg']
|
||||
]
|
||||
})
|
||||
self.room.videoAdded(self.handleVideoAdded)
|
||||
|
||||
|
|
|
@ -226,7 +226,7 @@ var Handlers = {
|
|||
}
|
||||
}
|
||||
|
||||
const ChatView = function(messages, mapper, room) {
|
||||
const ChatView = function(messages, mapper, room, opts = {}) {
|
||||
this.room = room
|
||||
this.mapper = mapper
|
||||
this.messages = messages // backbone collection
|
||||
|
@ -243,7 +243,7 @@ const ChatView = function(messages, mapper, room) {
|
|||
Private.attachElements.call(this)
|
||||
Private.addEventListeners.call(this)
|
||||
Private.initialMessages.call(this)
|
||||
Private.initializeSounds.call(this, room.soundUrls)
|
||||
Private.initializeSounds.call(this, opts.soundUrls)
|
||||
this.$container.css({
|
||||
right: '-300px'
|
||||
})
|
||||
|
|
|
@ -26,10 +26,11 @@ const Room = function(opts = {}) {
|
|||
|
||||
this.messages = new Backbone.Collection()
|
||||
this.currentMapper = new Backbone.Model({ name: opts.username, image: opts.image })
|
||||
this.chat = new ChatView(this.messages, this.currentMapper, this.room)
|
||||
this.chat = new ChatView(this.messages, this.currentMapper, this.room, {
|
||||
soundUrls: opts.soundUrls
|
||||
})
|
||||
|
||||
this.videos = {}
|
||||
this.soundUrls = opts.soundUrls
|
||||
|
||||
this.init()
|
||||
}
|
||||
|
|
|
@ -15,4 +15,4 @@ signalling(io, stunservers, store)
|
|||
junto(io, store)
|
||||
map(io, store)
|
||||
|
||||
io.listen(5001)
|
||||
io.listen(parseInt(process.env.NODE_REALTIME_PORT) || 5000)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const { omit, omitBy, isNil, mapValues } = require('lodash')
|
||||
const { find, omit, mapValues, values } = require('lodash')
|
||||
const {
|
||||
JOIN_MAP,
|
||||
LEAVE_MAP,
|
||||
|
@ -9,7 +9,16 @@ const {
|
|||
const NOT_IN_CONVERSATION = 0
|
||||
const IN_CONVERSATION = 1
|
||||
|
||||
const addMapperToMap = (map, userId) => { return Object.assign({}, map, { [userId]: NOT_IN_CONVERSATION }) }
|
||||
const addMapperToMap = (map, userId) => Object.assign({}, map, { [userId]: NOT_IN_CONVERSATION })
|
||||
const userStillPresent = (userId, liveMaps) => {
|
||||
if (!userId) return false
|
||||
let stillPresent = false
|
||||
const userIdString = userId.toString()
|
||||
values(liveMaps).forEach(presentUsers => {
|
||||
if (find(Object.keys(presentUsers), id => id === userIdString)) stillPresent = true
|
||||
})
|
||||
return stillPresent
|
||||
}
|
||||
|
||||
const reducer = (state = { connectedPeople: {}, liveMaps: {} }, action) => {
|
||||
const { type, payload } = action
|
||||
|
@ -37,10 +46,13 @@ const reducer = (state = { connectedPeople: {}, liveMaps: {} }, action) => {
|
|||
const newLiveMaps = mapWillEmpty
|
||||
? omit(liveMaps, payload.mapid)
|
||||
: Object.assign({}, liveMaps, { [payload.mapid]: omit(map, payload.userid) })
|
||||
delete newLiveMaps[undefined]
|
||||
delete newLiveMaps[null]
|
||||
const updateConnectedPeople = userStillPresent(payload.userid, newLiveMaps) ? connectedPeople : omit(connectedPeople, payload.userid)
|
||||
|
||||
return {
|
||||
connectedPeople: omit(connectedPeople, payload.userid),
|
||||
liveMaps: omitBy(newLiveMaps, isNil)
|
||||
connectedPeople: updateConnectedPeople,
|
||||
liveMaps: newLiveMaps
|
||||
}
|
||||
case JOIN_CALL:
|
||||
// update the user (payload.id is user id) in the given map to be marked in the conversation
|
||||
|
@ -57,15 +69,18 @@ const reducer = (state = { connectedPeople: {}, liveMaps: {} }, action) => {
|
|||
: Object.assign({}, map, { [payload.userid]: NOT_IN_CONVERSATION })
|
||||
|
||||
return Object.assign({}, state, {
|
||||
liveMaps: Object.assign({}, liveMaps, { map: newMap })
|
||||
liveMaps: Object.assign({}, liveMaps, { [payload.mapid]: newMap })
|
||||
})
|
||||
case 'DISCONNECT':
|
||||
const mapWithoutUser = omit(map, payload.userid)
|
||||
const newMapWithoutUser = callWillFinish ? mapValues(mapWithoutUser, () => NOT_IN_CONVERSATION) : mapWithoutUser
|
||||
const newLiveMapsWithoutUser = mapWillEmpty ? omit(liveMaps, payload.mapid) : Object.assign({}, liveMaps, { [payload.mapid]: newMapWithoutUser })
|
||||
delete newLiveMapsWithoutUser[undefined]
|
||||
delete newLiveMapsWithoutUser[null]
|
||||
const newConnectedPeople = userStillPresent(payload.userid, newLiveMapsWithoutUser) ? connectedPeople : omit(connectedPeople, payload.userid)
|
||||
return {
|
||||
connectedPeople: omit(connectedPeople, payload.userid),
|
||||
liveMaps: omitBy(newLiveMapsWithoutUser, isNil)
|
||||
connectedPeople: newConnectedPeople,
|
||||
liveMaps: newLiveMapsWithoutUser
|
||||
}
|
||||
default:
|
||||
return state
|
||||
|
|
Loading…
Reference in a new issue