# Web SDK 1.0

The Web SDK APIs are split into two main categories: [Express](/content/docs/sdk_ref/web/express/index.html) and [Low-Level](/content/docs/sdk_ref/web/low-level/index.html). We recommend that you start with the Express API as this:

1. Simplifies integration
2. Automatically recovers from stream failures
3. Handles edge cases such as network reconnects

Our Express APIs provide a simple, single-step API for the easiest integration of streaming into your application. Common use cases include:

- Channel (one to many) -> Channel
- Group Broadcast (few to many) -> Room
- Group Chat (many to many) -> Room
- One to One Chat -> Room

If you find that the Express API doesn't work for you, take a look at our [Lower Level API](/content/docs/sdk_ref/web/low-level/index.html).

## Latest Release

Please refer to [npmjs.org](https://www.npmjs.com/package/phenix-web-sdk) for the latest available version.

## Bundling in your app

The Web SDK is available at [npmjs.org](https://www.npmjs.com/package/phenix-web-sdk) and can be installed as a pre-built universal module using several dependency management tools. The Web SDK may be included directly in the browser or bundled using your favorite bundling tool such as Webpack or Rollup. For a full list of browser support see [Browser Support](/content/docs/sdk_ref/web/overview/#browser-support/index.html).

**Yarn**

```bash
   yarn add phenix-web-sdk
```

**NPM**

```bash
   npm install -S phenix-web-sdk
```

**Bower**

```bash
   bower install -S phenix-web-sdk
```

### Bundles

The universal module is available uncompressed and minified.

_phenix-web-sdk.js_

_phenix-web-sdk.min.js_

### Including with a bundler

Use your favorite bundling tool such as Webpack or Rollup.

#### ES6 Modules

```javascript
import * as sdk from 'phenix-web-sdk';
// Or Import just what you need
import { express, utils, net } from 'phenix-web-sdk';
```

#### Common JS

```javascript
const sdk = require('phenix-web-sdk');
```

#### AMD

```javascript
define(['phenix-web-sdk'], function (sdk) {
  // use sdk
});
```

### Loading Directly in the Browser

Load it directly in the browser in a script tag.

```javascript
var sdk = window['phenix-web-sdk'];
```

### Initializing With Ember.js

If you are using [ember.js](http://emberjs.com/) for your frontend, then you can add the Web SDK by generating a vendor shim:

`ember generate vendor-shim phenix-web-sdk`

Then modify ember-cli-build.js as shown:

#### Add the following imports in your ember-cli-build.js:

```javascript
app.import({
  development: 'bower_components/phenix-web-sdk/dist/phenix-web-sdk.js',
  production: 'bower_components/phenix-web-sdk/dist/phenix-web-sdk.min.js',
});
app.import('vendor/shims/phenix-web-sdk.js');
```

#### After that you can use the Web SDK in your code:

```javascript
import sdk from 'phenix-web-sdk';
// use sdk
```

### Production

We recommend that you include the minified version of the web-sdk in your production app or bundle(s). We optimize this bundle for size using smart transformations.

#### Alias with webpack

You can alias phenix-web-sdk in your webpack production config to use the minified version.

```json
{
    resolve: {
        alias: {
            'phenix-web-sdk': path.resolve(__dirname, '../node_modules', 'phenix-web-sdk/dist/phenix-web-sdk.min.js'),
        }
    }
}
```

## Observable

Observe value changes. Similar to the RxJS [Behavior Subject](https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/subjects/behaviorsubject.md)

#### [object Observable]

| Name | Signature | Returns | Description |
| --- | --- | --- | --- |
| subscribe | (callback, options) | [object Subscription] | See [Subscribe to an Observable](/content/docs/sdk_ref/web/overview/#subscribe-to-an-observable/index.html) |
| getValue | () | any | See [Get Observable Value](/content/docs/sdk_ref/web/overview/#get-observable-value/index.html) |
| setValue | (value) | void | See [Set Observable Value](/content/docs/sdk_ref/web/overview/#set-observable-value/index.html) |

### Subscribe to an Observable

Receive a notification every time the observable value changes.

```javascript
var subscription = observable.subscribe(function (newValue) {
  // Do something with newValue
}, options);
setTimeout(function () {
  // Stop listening to notifications after 1 second
  subscription.dispose();
}, 1000);
```

#### Parameters

| Name | Type | Description |
| --- | --- | --- |
| callback _(required)_ | Function | Function to call when value changes |
| options _(optional)_ | Object | Options for subscription. |

#### Options

| Name | Type | Default Value | Description |
| --- | --- | --- | --- |
| initial _(optional)_ | String |  | What to do when the subscription starts. Pass in 'notify' to be notified of initial value |

#### [object Subscription]

| Name | Signature | Returns | Description |
| --- | --- | --- | --- |
| dispose | () | void | Stop listening to notifications |

### Get Observable Value

Value may be of any supported [javascript type](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures)

```javascript
observable.getValue(value);
```

### Set Observable Value

Change the observable value. This will trigger notifications on all subscribers.

```javascript
observable.setValue(value);
```
