fix for heroku

This commit is contained in:
Connor Turland 2016-10-18 12:56:30 -04:00
parent d004e98ada
commit 29913cd10b
2 changed files with 79 additions and 77 deletions

View file

@ -111,7 +111,7 @@ import {
updateMap updateMap
} from './sendable' } from './sendable'
const Realtime = { let Realtime = {
videoId: 'video-wrapper', videoId: 'video-wrapper',
socket: null, socket: null,
webrtc: null, webrtc: null,
@ -130,8 +130,6 @@ const Realtime = {
self.socket = new SocketIoConnection({ url: Metamaps.Erb['REALTIME_SERVER']}) self.socket = new SocketIoConnection({ url: Metamaps.Erb['REALTIME_SERVER']})
setupSendables(self)
self.socket.on('connect', function () { self.socket.on('connect', function () {
console.log('connected') console.log('connected')
subscribeToEvents(self, self.socket) subscribeToEvents(self, self.socket)
@ -498,31 +496,35 @@ const Realtime = {
} }
} }
const setupSendables = Realtime => { const sendables = [
[requestLiveMaps, ['requestLiveMaps',requestLiveMaps],
joinMap, ['joinMap',joinMap],
leaveMap, ['leaveMap',leaveMap],
checkForCall, ['checkForCall',checkForCall],
acceptCall, ['acceptCall',acceptCall],
denyCall, ['denyAll',denyCall],
denyInvite, ['denyInvite',denyInvite],
inviteToJoin, ['inviteToJoin',inviteToJoin],
inviteACall, ['inviteACall',inviteACall],
joinCall, ['joinCall',joinCall],
leaveCall, ['leaveCall',leaveCall],
sendMapperInfo, ['sendMapperInfo',sendMapperInfo],
sendCoords, ['sendCoords',sendCoords],
dragTopic, ['dragTopic',dragTopic],
createTopic, ['createTopic',createTopic],
updateTopic, ['updateTopic',updateTopic],
removeTopic, ['removeTopic',removeTopic],
deleteTopic, ['deleteTopic',deleteTopic],
createSynapse, ['createSynapse',createSynapse],
updateSynapse, ['updateSynapse',updateSynapse],
removeSynapse, ['removeSynapse',removeSynapse],
deleteSynapse, ['deleteSynapse',deleteSynapse],
updateMap].forEach(sendable => Realtime[sendable.name] = sendable(Realtime, Realtime.socket)) ['updateMap',updateMap]
} ]
sendables.forEach(sendable => {
console.log(sendable, sendable[0])
Realtime[sendable[0]] = sendable[1](Realtime)
})
const subscribeToEvents = (Realtime, socket) => { const subscribeToEvents = (Realtime, socket) => {
socket.on(INVITED_TO_CALL, invitedToCall(Realtime)) socket.on(INVITED_TO_CALL, invitedToCall(Realtime))

View file

@ -28,12 +28,12 @@ import {
UPDATE_MAP UPDATE_MAP
} from './events' } from './events'
export const requestLiveMaps = (self, socket) => () => { export const requestLiveMaps = self => () => {
socket.emit(REQUEST_LIVE_MAPS) self.socket.emit(REQUEST_LIVE_MAPS)
} }
export const joinMap = (self, socket) => () => { export const joinMap = self => () => {
socket.emit(JOIN_MAP, { self.socket.emit(JOIN_MAP, {
userid: Active.Mapper.id, userid: Active.Mapper.id,
username: Active.Mapper.get('name'), username: Active.Mapper.get('name'),
userimage: Active.Mapper.get('image'), userimage: Active.Mapper.get('image'),
@ -42,15 +42,15 @@ export const joinMap = (self, socket) => () => {
}) })
} }
export const leaveMap = (self, socket) => () => { export const leaveMap = self => () => {
socket.emit(LEAVE_MAP) self.socket.emit(LEAVE_MAP)
} }
export const checkForCall = (self, socket) => () => { export const checkForCall = self => () => {
socket.emit(CHECK_FOR_CALL, { room: self.room.room, mapid: Active.Map.id }) self.socket.emit(CHECK_FOR_CALL, { room: self.room.room, mapid: Active.Map.id })
} }
export const sendMapperInfo = (self, socket) => userid => { export const sendMapperInfo = self => userid => {
// send this new mapper back your details, and the awareness that you've loaded the map // send this new mapper back your details, and the awareness that you've loaded the map
var update = { var update = {
userToNotify: userid, userToNotify: userid,
@ -60,10 +60,10 @@ export const sendMapperInfo = (self, socket) => userid => {
userinconversation: self.inConversation, userinconversation: self.inConversation,
mapid: Active.Map.id mapid: Active.Map.id
} }
socket.emit(SEND_MAPPER_INFO, update) self.socket.emit(SEND_MAPPER_INFO, update)
} }
export const joinCall = (self, socket) => () => { export const joinCall = self => () => {
self.webrtc.off('readyToCall') self.webrtc.off('readyToCall')
self.webrtc.once('readyToCall', function () { self.webrtc.once('readyToCall', function () {
self.videoInitialized = true self.videoInitialized = true
@ -77,7 +77,7 @@ export const joinCall = (self, socket) => () => {
self.room.join() self.room.join()
}) })
self.inConversation = true self.inConversation = true
socket.emit(JOIN_CALL, { self.socket.emit(JOIN_CALL, {
mapid: Active.Map.id, mapid: Active.Map.id,
id: Active.Mapper.id id: Active.Mapper.id
}) })
@ -86,8 +86,8 @@ export const joinCall = (self, socket) => () => {
self.room.chat.mapperJoinedCall(Active.Mapper.id) self.room.chat.mapperJoinedCall(Active.Mapper.id)
} }
export const leaveCall = (self, socket) => () => { export const leaveCall = self => () => {
socket.emit(LEAVE_CALL, { self.socket.emit(LEAVE_CALL, {
mapid: Active.Map.id, mapid: Active.Map.id,
id: Active.Mapper.id id: Active.Mapper.id
}) })
@ -104,9 +104,9 @@ export const leaveCall = (self, socket) => () => {
} }
} }
export const acceptCall = (self, socket) => userid => { export const acceptCall = self => userid => {
self.room.chat.sound.stop(self.soundId) self.room.chat.sound.stop(self.soundId)
socket.emit(ACCEPT_CALL, { self.socket.emit(ACCEPT_CALL, {
mapid: Active.Map.id, mapid: Active.Map.id,
invited: Active.Mapper.id, invited: Active.Mapper.id,
inviter: userid inviter: userid
@ -116,9 +116,9 @@ export const acceptCall = (self, socket) => userid => {
GlobalUI.clearNotify() GlobalUI.clearNotify()
} }
export const denyCall = (self, socket) => userid => { export const denyCall = self => userid => {
self.room.chat.sound.stop(self.soundId) self.room.chat.sound.stop(self.soundId)
socket.emit(DENY_CALL, { self.socket.emit(DENY_CALL, {
mapid: Active.Map.id, mapid: Active.Map.id,
invited: Active.Mapper.id, invited: Active.Mapper.id,
inviter: userid inviter: userid
@ -126,9 +126,9 @@ export const denyCall = (self, socket) => userid => {
GlobalUI.clearNotify() GlobalUI.clearNotify()
} }
export const denyInvite = (self, socket) => userid => { export const denyInvite = self => userid => {
self.room.chat.sound.stop(self.soundId) self.room.chat.sound.stop(self.soundId)
socket.emit(DENY_INVITE, { self.socket.emit(DENY_INVITE, {
mapid: Active.Map.id, mapid: Active.Map.id,
invited: Active.Mapper.id, invited: Active.Mapper.id,
inviter: userid inviter: userid
@ -136,8 +136,8 @@ export const denyInvite = (self, socket) => userid => {
GlobalUI.clearNotify() GlobalUI.clearNotify()
} }
export const inviteACall = (self, socket) => userid => { export const inviteACall = self => userid => {
socket.emit(INVITE_A_CALL, { self.socket.emit(INVITE_A_CALL, {
mapid: Active.Map.id, mapid: Active.Map.id,
inviter: Active.Mapper.id, inviter: Active.Mapper.id,
invited: userid invited: userid
@ -146,8 +146,8 @@ export const inviteACall = (self, socket) => userid => {
GlobalUI.clearNotify() GlobalUI.clearNotify()
} }
export const inviteToJoin = (self, socket) => userid => { export const inviteToJoin = self => userid => {
socket.emit(INVITE_TO_JOIN, { self.socket.emit(INVITE_TO_JOIN, {
mapid: Active.Map.id, mapid: Active.Map.id,
inviter: Active.Mapper.id, inviter: Active.Mapper.id,
invited: userid invited: userid
@ -155,7 +155,7 @@ export const inviteToJoin = (self, socket) => userid => {
self.room.chat.invitationPending(userid) self.room.chat.invitationPending(userid)
} }
export const sendCoords = (self, socket) => coords => { export const sendCoords = self => coords => {
var map = Active.Map var map = Active.Map
var mapper = Active.Mapper var mapper = Active.Mapper
if (map.authorizeToEdit(mapper)) { if (map.authorizeToEdit(mapper)) {
@ -164,83 +164,83 @@ export const sendCoords = (self, socket) => coords => {
userid: Active.Mapper.id, userid: Active.Mapper.id,
mapid: Active.Map.id mapid: Active.Map.id
} }
socket.emit(SEND_COORDS, update) self.socket.emit(SEND_COORDS, update)
} }
} }
export const dragTopic = (self, socket) => positions => { export const dragTopic = self => positions => {
if (Active.Map) { if (Active.Map) {
positions.mapid = Active.Map.id positions.mapid = Active.Map.id
socket.emit(DRAG_TOPIC, positions) self.socket.emit(DRAG_TOPIC, positions)
} }
} }
export const updateTopic = (self, socket) => topic => { export const updateTopic = self => topic => {
var data = { var data = {
topicId: topic.id topicId: topic.id
} }
socket.emit(UPDATE_TOPIC, data) self.socket.emit(UPDATE_TOPIC, data)
} }
export const updateSynapse = (self, socket) => synapse => { export const updateSynapse = self => synapse => {
var data = { var data = {
synapseId: synapse.id synapseId: synapse.id
} }
socket.emit(UPDATE_SYNAPSE, data) self.socket.emit(UPDATE_SYNAPSE, data)
} }
export const updateMap = (self, socket) => map => { export const updateMap = self => map => {
var data = { var data = {
mapId: map.id mapId: map.id
} }
socket.emit(UPDATE_MAP, data) self.socket.emit(UPDATE_MAP, data)
} }
export const createMessage = (self, socket) => data => { export const createMessage = self => data => {
var message = data.attributes var message = data.attributes
message.mapid = Active.Map.id message.mapid = Active.Map.id
socket.emit(CREATE_MESSAGE, message) self.socket.emit(CREATE_MESSAGE, message)
} }
export const createTopic = (self, socket) => data => { export const createTopic = self => data => {
if (Active.Map) { if (Active.Map) {
data.mapperid = Active.Mapper.id data.mapperid = Active.Mapper.id
data.mapid = Active.Map.id data.mapid = Active.Map.id
socket.emit(CREATE_TOPIC, data) self.socket.emit(CREATE_TOPIC, data)
} }
} }
export const deleteTopic = (self, socket) => data => { export const deleteTopic = self => data => {
if (Active.Map) { if (Active.Map) {
socket.emit(DELETE_TOPIC, data) self.socket.emit(DELETE_TOPIC, data)
} }
} }
export const removeTopic = (self, socket) => data => { export const removeTopic = self => data => {
if (Active.Map) { if (Active.Map) {
data.mapid = Active.Map.id data.mapid = Active.Map.id
socket.emit(REMOVE_TOPIC, data) self.socket.emit(REMOVE_TOPIC, data)
} }
} }
export const createSynapse = (self, socket) => data => { export const createSynapse = self => data => {
if (Active.Map) { if (Active.Map) {
data.mapperid = Active.Mapper.id data.mapperid = Active.Mapper.id
data.mapid = Active.Map.id data.mapid = Active.Map.id
socket.emit(CREATE_SYNAPSE, data) self.socket.emit(CREATE_SYNAPSE, data)
} }
} }
export const deleteSynapse = (self, socket) => data => { export const deleteSynapse = self => data => {
if (Active.Map) { if (Active.Map) {
data.mapid = Active.Map.id data.mapid = Active.Map.id
socket.emit(DELETE_SYNAPSE, data) self.socket.emit(DELETE_SYNAPSE, data)
} }
} }
export const removeSynapse = (self, socket) => data => { export const removeSynapse = self => data => {
if (Active.Map) { if (Active.Map) {
data.mapid = Active.Map.id data.mapid = Active.Map.id
socket.emit(REMOVE_SYNAPSE, data) self.socket.emit(REMOVE_SYNAPSE, data)
} }
} }