Home Reference Source
import RemoteSession from 'remote-context/lib/RemoteSession.js'
public class | source

RemoteSession

Extends:

events~EventEmitterSession → RemoteSession

A remote context Session to another peer.

Example:

import { RemoteSession } from 'remote-context';

const session = new RemoteSession(objectStream, context);

Constructor Summary

Public Constructor
public

constructor(objectStream: Stream, context: Context, opts: options)

Create a session from an object stream.

Member Summary

Public Members
public get

Get the remote context

public get

True if the remote peer should see stack errors.

Method Summary

Public Methods
public

assign(value: *): ReferenceAction

Assign a remote or local reference to the given value and return the matching Action.

public

delete(reference: Reference): boolean

Delete a local reference from the local-context.

public

destroy(err: *)

public

dispatch(value: *): Action | null | number | boolean | string

Dispatch a value for the remote peer session.

public

exists(value: *): boolean

Check if the given value exists on the local-context.

public

get(reference: Reference): *

Get a local reference value from the local-context.

public

isWritable(value: *): boolean

Check if the given value is writable.

public

set(reference: Reference, value: *): RemoteSession

Set a local reference to the local-context.

Inherited Summary

From class Session
public get

True if the session is no longer readable.

public get

True if the session is open.

public get

The number of requests sent and waiting for response.

public

destroy(err: Error): void

Destroy this session and it's stream.

public

dispatch(value: *): *

Convert the given value to a value that can be send ove to the other peer.

public

End this session stream.

public

fetch(value: Action | *): *

Fetch an arbitrary value.

public

request(action: Action, opts: object, onFulfilled: function, onRejected: function): Session

Request from the other peer to fetch the given action and send back it's response value.

public

send(action: Action): Session

Send an action for execution to the other peer.

public

Return session constructor name.

Public Constructors

public constructor(objectStream: Stream, context: Context, opts: options) source

Create a session from an object stream.

Override:

Session#constructor

Params:

NameTypeAttributeDescription
objectStream Stream

an actions object stream

context Context

The main context

opts options
  • optional

Session options with extensions

opts.writable boolean
  • optional
  • default: false

True if this context is writable to the remote peer

opts.showStack boolean
  • optional
  • default: false

True if errors on this context should include full stack (The stack will be send to the remote peer as a string)

Public Members

public get remote: RemoteContext source

Get the remote context

public get showStack: boolean source

True if the remote peer should see stack errors.

Public Methods

public assign(value: *): ReferenceAction source

Assign a remote or local reference to the given value and return the matching Action. First check if the given value exists on the remote context and if so, return it's reference. Otherwise assign a new reference for the given value on the local context.

Params:

NameTypeAttributeDescription
value *

Return:

ReferenceAction

public delete(reference: Reference): boolean source

Delete a local reference from the local-context.

Params:

NameTypeAttributeDescription
reference Reference

The local reference

Return:

boolean

True if the reference has been removed

public destroy(err: *) source

Destroy this session and it's stream.

Override:

Session#destroy

Params:

NameTypeAttributeDescription
err *

public dispatch(value: *): Action | null | number | boolean | string source

Dispatch a value for the remote peer session. Objects and functions will convert to actions, other primitive values such as string or numbers will remain as-is.

Override:

Session#dispatch

Params:

NameTypeAttributeDescription
value *

Return:

Action | null | number | boolean | string

public exists(value: *): boolean source

Check if the given value exists on the local-context.

Params:

NameTypeAttributeDescription
value *

The given value

Return:

boolean

True if exists

public get(reference: Reference): * source

Get a local reference value from the local-context.

Params:

NameTypeAttributeDescription
reference Reference

The local reference

Return:

*

public isWritable(value: *): boolean source

Check if the given value is writable. A value is writable if the local-context own it (ie. the value created elusively for this peer) or if the context is writable and the main-context own it. Environment values are always readonly unless there are on the context.

Params:

NameTypeAttributeDescription
value *

The given value

Return:

boolean

public set(reference: Reference, value: *): RemoteSession source

Set a local reference to the local-context.

Params:

NameTypeAttributeDescription
reference Reference

The local reference

value *

The local value

Return:

RemoteSession