Home Reference Source
import Core from '@osjs/client/src/core.js'
public class | source

Core

Extends:

@osjs/common~CoreBase → Core

Main Core class for OS.js service providers and bootstrapping.

Constructor Summary

Public Constructor
public

constructor(config: CoreConfig, options: CoreOptions)

Create core instance

Member Summary

Public Members
public

$contents: Element

Windows etc DOM element

public

$resourceRoot: Element

Resource script container DOM element

public

$root: Element

Main DOM element

public

Ping (stay alive) interval

public

Default fetch request options

public

Splash instance

public

Url Resolver TODO: typedef

public

Current user data

public

Websocket connection

Method Summary

Public Methods
public

Boots up OS.js

public

broadcast(pkg: string | Function, name: string): string[]

Sends a 'broadcast' event with given arguments to all applications matching given filter

public

Destroy core instance

public

Gets the current user

public

kill(match: string | number)

Kills the specified application

public

middleware(group: string, callback: Function): *

Add middleware function to a group

public

off(name: string, callback: Function, force: boolean): Core

Removes an event handler

public

open(file: VFSFile, options: CoreOpenOptions): Boolean | Application

Spawns an application based on the file given

public

request(url: string, options: Options, type: string, force: boolean): *

Make a HTTP request

public

run(name: string, args: {foo: *}, options: PackageLaunchOptions): Promise<Application>

Create an application from a package

public

send(name: string): *

Sends a signal to the server over websocket.

public

Set the internal fetch/request options

public

Starts all core services

public

url(endpoint: string, options: object, metadata: PackageMetadata): string

Creates an URL based on configured public path

Private Methods
private

Attaches some internal events

private

Creates the main connection to server

private

Creates event listeners*

private

_openApplicationDialog(options: *, compatible: *, file: *, run: *)

Wrapper method to create an application choice dialog

Public Constructors

public constructor(config: CoreConfig, options: CoreOptions) source

Create core instance

Params:

NameTypeAttributeDescription
config CoreConfig
  • optional
  • default: {}

Configuration tree

options CoreOptions
  • optional
  • default: {}

Options

Public Members

public $contents: Element source

Windows etc DOM element

public $resourceRoot: Element source

Resource script container DOM element

public $root: Element source

Main DOM element

public ping: number source

Ping (stay alive) interval

public requestOptions: Object source

Default fetch request options

public splash: Splash source

Splash instance

public urlResolver: function(): string source

Url Resolver TODO: typedef

public user: CoreUserData source

Current user data

public ws: Websocket source

Websocket connection

Public Methods

public boot(): Promise<boolean> source

Boots up OS.js

Return:

Promise<boolean>

public broadcast(pkg: string | Function, name: string): string[] source

Sends a 'broadcast' event with given arguments to all applications matching given filter

Params:

NameTypeAttributeDescription
pkg string | Function

The filter

name string

The event name

...args *

Arguments to pass to emit

Return:

string[]

List of application names emitted to

public destroy(): boolean source

Destroy core instance

Return:

boolean

public getUser(): CoreUserData source

Gets the current user

Return:

CoreUserData

User object

public kill(match: string | number) source

Kills the specified application

Params:

NameTypeAttributeDescription
match string | number

Application name or PID

public middleware(group: string, callback: Function): * source

Add middleware function to a group

Params:

NameTypeAttributeDescription
group string

Middleware group

callback Function

Middleware function to add

Return:

*

public off(name: string, callback: Function, force: boolean): Core source

Removes an event handler

Params:

NameTypeAttributeDescription
name string
callback Function
  • optional
  • default: null
force boolean
  • optional
  • default: false

Return:

Core

this

public open(file: VFSFile, options: CoreOpenOptions): Boolean | Application source

Spawns an application based on the file given

Params:

NameTypeAttributeDescription
file VFSFile

A file object

options CoreOpenOptions
  • optional

Options

Return:

Boolean | Application

public request(url: string, options: Options, type: string, force: boolean): * source

Make a HTTP request

This is a wrapper for making a 'fetch' request with some helpers and integration with OS.js

Params:

NameTypeAttributeDescription
url string

The endpoint

options Options
  • optional

fetch options

type string
  • optional

Request / Response type

force boolean
  • optional
  • default: false

Force request even when in standalone mode

Return:

*

public run(name: string, args: {foo: *}, options: PackageLaunchOptions): Promise<Application> source

Create an application from a package

Params:

NameTypeAttributeDescription
name string

Package name

args {foo: *}
  • optional

Launch arguments

options PackageLaunchOptions
  • optional

Launch options

Return:

Promise<Application>

See:

public send(name: string): * source

Sends a signal to the server over websocket. This will be interpreted as an event in the server core.

Params:

NameTypeAttributeDescription
name string

Event name

...params *

Event callback parameters

Return:

*

public setRequestOptions(options: object) source

Set the internal fetch/request options

Params:

NameTypeAttributeDescription
options object

Request options

public start(): Promise<boolean> source

Starts all core services

Return:

Promise<boolean>

public url(endpoint: string, options: object, metadata: PackageMetadata): string source

Creates an URL based on configured public path

If you give a options.type, the URL will be resolved to the correct resource.

Params:

NameTypeAttributeDescription
endpoint string
  • optional
  • default: /

Endpoint

options object
  • optional

Additional options for resolving url

options.prefix boolean
  • optional
  • default: false

Returns a full URL complete with scheme, etc. (will always be true on websocket)

options.type string
  • optional

Optional URL type (websocket)

metadata PackageMetadata
  • optional

A package metadata

Return:

string

Private Methods

private _attachEvents() source

Attaches some internal events

private _createConnection(cb: Function): boolean source

Creates the main connection to server

Params:

NameTypeAttributeDescription
cb Function

Callback function

Return:

boolean

private _createListeners() source

Creates event listeners*

private _openApplicationDialog(options: *, compatible: *, file: *, run: *) source

Wrapper method to create an application choice dialog

Params:

NameTypeAttributeDescription
options *
compatible *
file *
run *