Remote
Defined in: internal/remote.ts:46
This class is used as a middleware for communication for a remote and proxy xjs. Receiving, Sending and Routing of messages is done here to make the calls reach their supposed methods, be processed and then returned to the caller as if it is just running locally.
Note that this class does not create/handle the connection used to send/receive messages and should be declared initially upon readying the xjs, together with what type it is (remote/proxy). You can use websockets, datachannnels, etc… for this.
Initial declaration on ready:
var xjs = require('xjs');
xjs.ready({ remote: { type: 'remote' // remote/proxy, default is local sendMessage: function(message) { myConnection.send(message) // this will be assigned to Remote.sendMessage } }})
// Then handle received messages(string) should be passed toxjs.Remote.receiveMessage(message)Once this is set up, you can already use xjs normally as if you are just making calls locally.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Remote():
Remote
Returns
Section titled “Returns”Remote
Properties
Section titled “Properties”remoteType
Section titled “remoteType”
staticremoteType:string='local'
Defined in: internal/remote.ts:63
Initial assignment should be done on xjs.ready() Types:
- local (default)
- remote
- proxy
sendMessage
Section titled “sendMessage”
staticsendMessage:any
Defined in: internal/remote.ts:54
Initial assignment should be done on xjs.ready() Assign preferred method of sending message.
Methods
Section titled “Methods”receiveMessage()
Section titled “receiveMessage()”
staticreceiveMessage(message):Promise<unknown>
Defined in: internal/remote.ts:110
param: (value: string)
Handles received messages to properly relay it to either the proxy and make the actual calls, or remote and return the results from proxy.
Parameters
Section titled “Parameters”message
Section titled “message”string
Returns
Section titled “Returns”Promise<unknown>
setRemoteType()
Section titled “setRemoteType()”
staticsetRemoteType(val):Promise<unknown>
Defined in: internal/remote.ts:73
param: (value: string) / remoteType
Allows user to set the remoteType. May be used for instances that the extension may need to call a method locally.
Note: This may break handling of calls if the type is not returned to its original assignment
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<unknown>
setSendMessage()
Section titled “setSendMessage()”
staticsetSendMessage(newSendMessage):Promise<unknown>
Defined in: internal/remote.ts:95
param: (value: connection)
Allows reassigning of Remote.sendMessage for instances when sending messages
is replaced.
Parameters
Section titled “Parameters”newSendMessage
Section titled “newSendMessage”any
Returns
Section titled “Returns”Promise<unknown>