Comments (14)
@ScriptWorker @davidmoshal @FMRb: This is now available in version 6.0.0-beta.0.
https://github.com/elpheria/rpc-websockets/blob/v6.x/API.md
from rpc-websockets.
Hello! Can you just run both server and client instances on both sides? That would solve the case.
from rpc-websockets.
Hello! Unfortunately no, as the server can't connect to the client. Basically we can't guarantee, that the client won't be under the firewall protection or even to have an external ip address.
from rpc-websockets.
@ScriptWorker: Ok, I agree and I would gladly merge the feature if no current use cases break!
from rpc-websockets.
@ScriptWorker Any progress here, maybe?
from rpc-websockets.
This will be available in version 5.x. Currently in development.
from rpc-websockets.
@ScriptWorker
https://www.npmjs.com/package/jsonrpc-bidirectional
from rpc-websockets.
Any update on version 5.x? I would like the library to support this feature
from rpc-websockets.
@FMRb Unfortunately, no. Out of resources currently!
from rpc-websockets.
you really ought to make it clear in the ReadMe that this is one-way, browser running procedures on a remote server only, because it's such a huge limitation of this library.
from rpc-websockets.
from rpc-websockets.
@FMRb: btw, any initial feedback on this feature, maybe? :)
from rpc-websockets.
Due to positive feedback this will hit master soon. It’s currently released as 6.x in beta due to insufficient migration docs, but that should be available soon. Closing this one.
from rpc-websockets.
My solution is that the client calls the server method, registers a function A, and then the server returns promise.
Then when calling A, make Promise resolve
example:
const res = {}
res.websocket = {
makeUpServer(wsServer) {
// client 注册方法
wsServer.register('_calleeRegister', ({ methodName, namespace = '/', password = '' }) => {
const registerPassword = password
return new Promise((calleeResolve) => {
wsServer.register(
methodName,
function (params) {
return new Promise((callerResolve, callerReject) => {
const { password } = params
// 密码校验不通过
if (registerPassword && registerPassword != password) {
return callerReject({
state: 'fail',
code: 'le3t8gjp',
msg: `call password error`
})
}
// 删除密码
delete params.password
// 本次调用 id
const _callerCall = `${Date.now().toString(36)}-${Math.random()}`
// 转发 调用数据 给注册方
calleeResolve({
_callerCall,
params
})
// 缓存本次
_calleeReturn.value[_callerCall] = {
ms: Date.now(),
// 转发 返回数据 给调用方
callerResolve
}
})
},
namespace
)
})
})
// client 注册方法的返回
const _calleeReturnCache = {
// 清理超时的 callerResolve
timeout: 1000 * 10,
// 多久清理一次
detectInterval: 1000 * 20,
// 超时的 callerResolve
value: {
// _callerCall: {
// callerResolve: function () {},
// ms: Date.now(),
// }
}
}
// 定时检测超时的 _calleeReturnCache
setInterval(() => {
Object.keys(_calleeReturnCache.value).forEach((v) => {
if (Date.now() - _calleeReturnCache.value[v].ms >= _calleeReturnCache.timeout) {
delete _calleeReturnCache.value[v]
}
})
}, _calleeReturnCache.detectInterval)
wsServer.register('_calleeReturn', ({ _callerCall, returnValue }) => {
if (!_calleeReturnCache.value[_callerCall]) {
return {
state: 'fail',
code: 'le3wr8e1',
msg: `not found _calleeReturnCache by _callerCall ${_callerCall}`
}
}
_calleeReturnCache.value[_callerCall].callerResolve(returnValue)
delete _calleeReturnCache.value[_callerCall]
return 1
})
},
makeUpClient(wsClient) {
Object.assign(wsClient, {
async register(methodName, handler, password = '', namespace = '/') {
// 注册函数
const start = async () => {
// 通知 Server 注册一个方法
const res = await wsClient.call(`_calleeRegister`, {
methodName,
namespace,
password
})
const { _callerCall, params } = res
let returnValue = handler(params)
if (/promise/i.test(returnValue.toString())) {
returnValue = await returnValue
}
wsClient.notify('_calleeReturn', {
_callerCall,
returnValue: returnValue || {}
})
}
await start()
while (true) {
await start()
}
}
})
}
}
module.exports = res
from rpc-websockets.
Related Issues (20)
- Emit event with params HOT 1
- Rpc-websockets on heroku HOT 1
- Publish 7.4.13 to NPM HOT 1
- How to get the Emit response ?
- Dependency Vulnrabilities HOT 3
- Ignore null in result/error HOT 2
- Help! Run ws on the same port as a http Express? HOT 2
- Access connected clients HOT 4
- Is this the proper way to close the socket? HOT 1
- The Map type cannot be returned using the Server registration method HOT 2
- `fn` type bound in `Server.register` might be slightly off HOT 2
- Migrate from request
- Resolve tough-cookie vulnerability
- How to handle exceptions on server? HOT 3
- Q: namespaces HOT 1
- process is hanging after calling client.close HOT 3
- Whether there is an interest in providing an extensible encoder and decoder? HOT 5
- call results in -32602 Invalid params when no params are given cause it sents null HOT 3
- When sents message without params it is ignored HOT 1
- Any reason emit events on namespace level will be broadcasting instead of only to subscribers like on top level HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rpc-websockets.