2016-11-07 15:25:08 -05:00
|
|
|
/* global $ */
|
|
|
|
|
2016-10-18 12:34:19 -04:00
|
|
|
import Active from '../Active'
|
2016-12-21 03:56:29 -05:00
|
|
|
import { ChatView } from '../Views'
|
2016-10-18 12:34:19 -04:00
|
|
|
import GlobalUI from '../GlobalUI'
|
|
|
|
|
|
|
|
import {
|
|
|
|
JOIN_MAP,
|
|
|
|
LEAVE_MAP,
|
|
|
|
CHECK_FOR_CALL,
|
|
|
|
ACCEPT_CALL,
|
|
|
|
DENY_CALL,
|
|
|
|
DENY_INVITE,
|
|
|
|
INVITE_TO_JOIN,
|
|
|
|
INVITE_A_CALL,
|
|
|
|
JOIN_CALL,
|
|
|
|
LEAVE_CALL,
|
|
|
|
SEND_MAPPER_INFO,
|
|
|
|
SEND_COORDS,
|
2017-01-03 16:12:58 -05:00
|
|
|
DRAG_TOPIC
|
2016-10-18 12:34:19 -04:00
|
|
|
} from './events'
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const joinMap = self => () => {
|
|
|
|
self.socket.emit(JOIN_MAP, {
|
2016-10-18 12:34:19 -04:00
|
|
|
userid: Active.Mapper.id,
|
|
|
|
username: Active.Mapper.get('name'),
|
2016-10-21 09:29:04 -04:00
|
|
|
avatar: Active.Mapper.get('image'),
|
2016-10-18 12:34:19 -04:00
|
|
|
mapid: Active.Map.id,
|
|
|
|
map: Active.Map.attributes
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const leaveMap = self => () => {
|
|
|
|
self.socket.emit(LEAVE_MAP)
|
2016-10-18 12:34:19 -04:00
|
|
|
}
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const checkForCall = self => () => {
|
2016-11-07 15:25:08 -05:00
|
|
|
self.socket.emit(CHECK_FOR_CALL, { room: self.room.room, mapid: Active.Map.id })
|
2016-10-18 12:34:19 -04:00
|
|
|
}
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const sendMapperInfo = self => userid => {
|
2016-10-18 12:34:19 -04:00
|
|
|
// send this new mapper back your details, and the awareness that you've loaded the map
|
|
|
|
var update = {
|
|
|
|
userToNotify: userid,
|
|
|
|
username: Active.Mapper.get('name'),
|
2016-10-21 09:29:04 -04:00
|
|
|
avatar: Active.Mapper.get('image'),
|
2016-10-18 12:34:19 -04:00
|
|
|
userid: Active.Mapper.id,
|
|
|
|
userinconversation: self.inConversation,
|
|
|
|
mapid: Active.Map.id
|
|
|
|
}
|
2016-10-18 12:56:30 -04:00
|
|
|
self.socket.emit(SEND_MAPPER_INFO, update)
|
2016-10-18 12:34:19 -04:00
|
|
|
}
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const joinCall = self => () => {
|
2016-10-18 12:34:19 -04:00
|
|
|
self.webrtc.off('readyToCall')
|
2016-11-07 15:25:08 -05:00
|
|
|
self.webrtc.once('readyToCall', function() {
|
2016-10-18 12:34:19 -04:00
|
|
|
self.videoInitialized = true
|
|
|
|
self.readyToCall = true
|
|
|
|
self.localVideo.view.manuallyPositioned = false
|
|
|
|
self.positionVideos()
|
|
|
|
self.localVideo.view.$container.show()
|
|
|
|
if (self.localVideo) {
|
|
|
|
$('#wrapper').append(self.localVideo.view.$container)
|
|
|
|
}
|
|
|
|
self.room.join()
|
2016-12-21 03:56:29 -05:00
|
|
|
ChatView.conversationInProgress(true)
|
2016-10-18 12:34:19 -04:00
|
|
|
})
|
|
|
|
self.inConversation = true
|
2016-10-18 12:56:30 -04:00
|
|
|
self.socket.emit(JOIN_CALL, {
|
2016-10-18 12:34:19 -04:00
|
|
|
mapid: Active.Map.id,
|
|
|
|
id: Active.Mapper.id
|
|
|
|
})
|
|
|
|
self.webrtc.startLocalVideo()
|
|
|
|
GlobalUI.clearNotify()
|
2016-12-21 03:56:29 -05:00
|
|
|
ChatView.mapperJoinedCall(Active.Mapper.id)
|
2016-10-18 12:34:19 -04:00
|
|
|
}
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const leaveCall = self => () => {
|
|
|
|
self.socket.emit(LEAVE_CALL, {
|
2016-10-18 12:34:19 -04:00
|
|
|
mapid: Active.Map.id,
|
|
|
|
id: Active.Mapper.id
|
|
|
|
})
|
|
|
|
|
2016-12-21 03:56:29 -05:00
|
|
|
ChatView.mapperLeftCall(Active.Mapper.id)
|
|
|
|
ChatView.leaveConversation() // the conversation will carry on without you
|
2016-10-18 12:34:19 -04:00
|
|
|
self.room.leaveVideoOnly()
|
|
|
|
self.inConversation = false
|
|
|
|
self.localVideo.view.$container.hide()
|
|
|
|
|
|
|
|
// if there's only two people in the room, and we're leaving
|
|
|
|
// we should shut down the call locally
|
|
|
|
if (self.countOthersInConversation() === 1) {
|
|
|
|
self.callEnded()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const acceptCall = self => userid => {
|
2016-12-21 03:56:29 -05:00
|
|
|
ChatView.sound.stop(self.soundId)
|
2016-10-18 12:56:30 -04:00
|
|
|
self.socket.emit(ACCEPT_CALL, {
|
2016-10-18 12:34:19 -04:00
|
|
|
mapid: Active.Map.id,
|
|
|
|
invited: Active.Mapper.id,
|
|
|
|
inviter: userid
|
|
|
|
})
|
2018-03-03 16:30:45 -05:00
|
|
|
$.post('/main/maps/' + Active.Map.id + '/events/conversation')
|
2016-10-18 12:34:19 -04:00
|
|
|
self.joinCall()
|
|
|
|
GlobalUI.clearNotify()
|
|
|
|
}
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const denyCall = self => userid => {
|
2016-12-21 03:56:29 -05:00
|
|
|
ChatView.sound.stop(self.soundId)
|
2016-10-18 12:56:30 -04:00
|
|
|
self.socket.emit(DENY_CALL, {
|
2016-10-18 12:34:19 -04:00
|
|
|
mapid: Active.Map.id,
|
|
|
|
invited: Active.Mapper.id,
|
|
|
|
inviter: userid
|
|
|
|
})
|
|
|
|
GlobalUI.clearNotify()
|
|
|
|
}
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const denyInvite = self => userid => {
|
2016-12-21 03:56:29 -05:00
|
|
|
ChatView.sound.stop(self.soundId)
|
2016-10-18 12:56:30 -04:00
|
|
|
self.socket.emit(DENY_INVITE, {
|
2016-10-18 12:34:19 -04:00
|
|
|
mapid: Active.Map.id,
|
|
|
|
invited: Active.Mapper.id,
|
|
|
|
inviter: userid
|
|
|
|
})
|
|
|
|
GlobalUI.clearNotify()
|
|
|
|
}
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const inviteACall = self => userid => {
|
|
|
|
self.socket.emit(INVITE_A_CALL, {
|
2016-10-18 12:34:19 -04:00
|
|
|
mapid: Active.Map.id,
|
|
|
|
inviter: Active.Mapper.id,
|
|
|
|
invited: userid
|
|
|
|
})
|
2016-12-21 03:56:29 -05:00
|
|
|
ChatView.invitationPending(userid)
|
2016-10-18 12:34:19 -04:00
|
|
|
GlobalUI.clearNotify()
|
|
|
|
}
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const inviteToJoin = self => userid => {
|
|
|
|
self.socket.emit(INVITE_TO_JOIN, {
|
2016-10-18 12:34:19 -04:00
|
|
|
mapid: Active.Map.id,
|
|
|
|
inviter: Active.Mapper.id,
|
|
|
|
invited: userid
|
|
|
|
})
|
2016-12-21 03:56:29 -05:00
|
|
|
ChatView.invitationPending(userid)
|
2016-10-18 12:34:19 -04:00
|
|
|
}
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const sendCoords = self => coords => {
|
2016-10-18 12:34:19 -04:00
|
|
|
var map = Active.Map
|
|
|
|
var mapper = Active.Mapper
|
2017-01-03 16:12:58 -05:00
|
|
|
if (map && map.authorizeToEdit(mapper)) {
|
2016-10-18 12:34:19 -04:00
|
|
|
var update = {
|
|
|
|
usercoords: coords,
|
|
|
|
userid: Active.Mapper.id,
|
|
|
|
mapid: Active.Map.id
|
|
|
|
}
|
2016-10-18 12:56:30 -04:00
|
|
|
self.socket.emit(SEND_COORDS, update)
|
2016-10-18 12:34:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-18 12:56:30 -04:00
|
|
|
export const dragTopic = self => positions => {
|
2016-10-18 12:34:19 -04:00
|
|
|
if (Active.Map) {
|
|
|
|
positions.mapid = Active.Map.id
|
2016-10-18 12:56:30 -04:00
|
|
|
self.socket.emit(DRAG_TOPIC, positions)
|
2016-10-18 12:34:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|