|
@@ -9,41 +9,48 @@ for (let k in flowMut) { flow[k] = 'flow/' + k }
|
|
for (let k in chatMut) { chat[k] = 'chat/' + k }
|
|
for (let k in chatMut) { chat[k] = 'chat/' + k }
|
|
|
|
|
|
let targetws
|
|
let targetws
|
|
|
|
+// DEBUG PURPOSES
|
|
|
|
+window.dbgDisconnect = () => {
|
|
|
|
+ flowService.close()
|
|
|
|
+}
|
|
|
|
+window.dbgReconnect = () => {
|
|
|
|
+ flowService.connect(targetws)
|
|
|
|
+}
|
|
|
|
|
|
export default store => {
|
|
export default store => {
|
|
store.subscribe(mut => {
|
|
store.subscribe(mut => {
|
|
// console.log('I changed -- perform the connection somehow', mut)
|
|
// console.log('I changed -- perform the connection somehow', mut)
|
|
if (mut.type === 'route/ROUTE_CHANGED') {
|
|
if (mut.type === 'route/ROUTE_CHANGED') {
|
|
- let route = mut.payload.to
|
|
|
|
- let ctx = route.params.context
|
|
|
|
- let urlPath = [window.location.host]
|
|
|
|
- if (ctx) urlPath.push(ctx)
|
|
|
|
- urlPath.push('conn')
|
|
|
|
- targetws = 'ws://' + urlPath.join('/')
|
|
|
|
|
|
+ // let route = mut.payload.to
|
|
|
|
+ const urlParts = mut.payload.to.path.split('/')
|
|
|
|
+ urlParts[0] = window.location.host // Substitute '/' with host
|
|
|
|
+ urlParts[urlParts.length - 1] = 'conn' // 'substitute last with 'conn'
|
|
|
|
+ const urlPath = urlParts.join('/')
|
|
|
|
+
|
|
|
|
+ // Add protocol
|
|
|
|
+ targetws = 'ws://' + urlPath
|
|
if (window.location.protocol === 'https:') {
|
|
if (window.location.protocol === 'https:') {
|
|
- targetws = 'wss://' + urlPath.join('/')
|
|
|
|
|
|
+ targetws = 'wss://' + urlPath
|
|
}
|
|
}
|
|
flowService.connect(targetws)
|
|
flowService.connect(targetws)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- // DEBUG PURPOSES
|
|
|
|
- window.dbgDisconnect = () => {
|
|
|
|
- flowService.close()
|
|
|
|
- }
|
|
|
|
- window.dbgReconnect = () => {
|
|
|
|
- flowService.connect(targetws)
|
|
|
|
- }
|
|
|
|
|
|
|
|
// Connected
|
|
// Connected
|
|
flowService.connected(() => {
|
|
flowService.connected(() => {
|
|
|
|
+ const match = /.*\/s:(.*)/.exec(store.state.route.path)
|
|
|
|
+ let sessId
|
|
|
|
+ if (match != null) {
|
|
|
|
+ sessId = match[1]
|
|
|
|
+ }
|
|
// Make this in a service
|
|
// Make this in a service
|
|
- if (store.state.route.params.sessId === undefined) {
|
|
|
|
|
|
+ if (sessId === undefined) {
|
|
flowService.sessionNew()
|
|
flowService.sessionNew()
|
|
return
|
|
return
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ store.commit(flow.SESSID_UPDATE, sessId)
|
|
store.dispatch(flow.NOTIFICATION_ADD, 'Connected')
|
|
store.dispatch(flow.NOTIFICATION_ADD, 'Connected')
|
|
- flowService.sessionLoad(undefined, store.state.route.params.sessId)
|
|
|
|
|
|
+ flowService.sessionLoad(undefined, sessId)
|
|
})
|
|
})
|
|
|
|
|
|
flowService.on('document', (v) => {
|
|
flowService.on('document', (v) => {
|
|
@@ -77,11 +84,13 @@ export default store => {
|
|
store.dispatch(flow.NOTIFICATION_ADD, v.data)
|
|
store.dispatch(flow.NOTIFICATION_ADD, v.data)
|
|
})
|
|
})
|
|
flowService.on('sessionJoin', (v) => {
|
|
flowService.on('sessionJoin', (v) => {
|
|
|
|
+ const sessId = v.id
|
|
store.dispatch(chat.CHAT_JOIN, {
|
|
store.dispatch(chat.CHAT_JOIN, {
|
|
handle: store.state.chat.handle,
|
|
handle: store.state.chat.handle,
|
|
- sessId: store.state.route.params.sessId
|
|
|
|
|
|
+ sessId: sessId
|
|
})
|
|
})
|
|
store.commit(chat.EVENTS_UPDATE, [])
|
|
store.commit(chat.EVENTS_UPDATE, [])
|
|
|
|
+ store.commit(flow.SESSID_UPDATE, sessId)
|
|
})
|
|
})
|
|
|
|
|
|
/// // CHAT //////
|
|
/// // CHAT //////
|