mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
added locked state & use method to socket
This commit is contained in:
parent
9e2ec2951f
commit
7fcdf5aec2
@ -3,7 +3,5 @@ module.exports = {
|
||||
unsplash_secret: 'dh3UlgLTdunO7a_l_iKjotXbz0xB7w5EuDIBU8Pa8pA',
|
||||
g_recaptcha_key: '6Lc55uUUAAAAAEIACMVf3BUzAJSNCmI3RrjEirZ6',
|
||||
g_recaptcha_secret: '6Lc55uUUAAAAAOP4OgUa5DpqJC-70t53AmW0lyYf',
|
||||
// Global Server Key (Requiered for RS-YIBTP), Not autogenerated, must be included on. (Recommended not modify this constant)
|
||||
server_key:
|
||||
'f706b0a535b6c2d36545c4137a0a3a26853ea8b5-1223c9ba7923152cae28e5a2e7501b2b-50600768',
|
||||
server_key: 'f706b0a535b6c2d36545c4137a0a3a26853ea8b5-1223c9ba7923152cae28e5a2e7501b2b-50600768',
|
||||
};
|
||||
|
@ -25,6 +25,7 @@ export default class SocketConnection {
|
||||
connectionState: any;
|
||||
listeners: any;
|
||||
latency: any;
|
||||
locked: boolean;
|
||||
}
|
||||
props: any
|
||||
opts: any
|
||||
@ -39,8 +40,9 @@ export default class SocketConnection {
|
||||
this.then = props.then
|
||||
this.props = props.payload
|
||||
this.dispatcher = props.connector
|
||||
|
||||
|
||||
this.state = {
|
||||
locked: this.props.locked ?? false,
|
||||
latency: 0,
|
||||
listeners: {},
|
||||
connectionState: "init",
|
||||
@ -99,10 +101,14 @@ export default class SocketConnection {
|
||||
})
|
||||
|
||||
this.namespaceConnector = (namespace: string) => {
|
||||
this.createConnection(namespace).then(() => {
|
||||
this.ioConn.updateConnectionState(2)
|
||||
this.setConnectionListeners()
|
||||
})
|
||||
if (!this.state.locked) {
|
||||
this.createConnection(namespace).then(() => {
|
||||
this.ioConn.updateConnectionState(2)
|
||||
this.setConnectionListeners()
|
||||
})
|
||||
}else{
|
||||
verbosity(`[${this.ioConn.namespaceOrigin}] node is locked, cannot switch the namespace`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,6 +176,14 @@ export default class SocketConnection {
|
||||
return this.ioConn.emit(...context)
|
||||
}
|
||||
|
||||
this.ioConn.lock = () => {
|
||||
this.ioConn.updateState({ locked: true })
|
||||
}
|
||||
|
||||
this.ioConn.unlock = () => {
|
||||
this.ioConn.updateState({ locked: false })
|
||||
}
|
||||
|
||||
this.ioConn._close = () => {
|
||||
this.ioConn.disconnect()
|
||||
this.ioConn.updateConnectionState(0)
|
||||
|
@ -61,6 +61,33 @@ export default {
|
||||
*resetHeader({ }, { put }) {
|
||||
yield put({ type: "createNodeSocket" })
|
||||
},
|
||||
*use({ scope, invoke, query }, { put, select }) {
|
||||
const state = yield select(state => state)
|
||||
if (!scope || !invoke || !query) {
|
||||
verbosity(`some params is missing`)
|
||||
return false
|
||||
}
|
||||
if (!state.socket.nodes[scope] && scope !== state.socket.headerNode) {
|
||||
let opt = {
|
||||
namespaceOrigin: `/${scope}`,
|
||||
hostname: `${state.socket.socket_address}:${state.socket.socket_port}`,
|
||||
port: state.socket.socket_port,
|
||||
reconnectionAttempts: 10
|
||||
}
|
||||
|
||||
new SocketConnection({
|
||||
namespaceOrigin: opt.namespaceOrigin,
|
||||
connector: state.app.dispatcher,
|
||||
payload: opt,
|
||||
then: (socket) => {
|
||||
socket._emit(invoke, query.payload, query.callback)
|
||||
}
|
||||
})
|
||||
}else{
|
||||
state.socket.nodes[scope].ioConn._emit(invoke, query.payload, query.callback)
|
||||
}
|
||||
|
||||
},
|
||||
*break({ listener, node }, { select, put }) {
|
||||
if (!node || !listener) {
|
||||
verbosity(`cannot change a listener without declaring the node/listener`)
|
||||
|
Loading…
x
Reference in New Issue
Block a user