Constructor
new dConnectSDK(settings)
Parameters:
Name | Type | Description |
---|---|---|
settings |
Object | リクエストの設定値.以下の値が設定できる.値は省略可能. |
- Source:
Example
const sdk = new dConnectSDK({
sslEnabled: false,
uriSchemeName: 'gotapi',
host: '192.168.0.24',
port: 4035,
extendedOrigin: 'http://localhost:4035/',
isEnabledAntiSpoofing: false
});
sslEnabled: HTTPおよびWebSocket通信でSSLを使用するかどうかを指定するフラグ.
uriSchemeName: Manager起動用URIスキームの名前.
host: ホスト名.
port: ポート番号.
extendedOrigin: ハイブリッドアプリとしてのオリジン.
isEnabledAntiSpoofing: HMACによるサーバ認証を行うかどうかのフラグ.
appName: LocalOAuth用のアプリケーション名.
scopes: LocalOAuthで許可を得たいプロファイル名の配列.
Classes
Namespaces
Members
(static) HEADER_EXTENDED_ORIGIN
ハイブリッドアプリのオリジンを指定するリクエストヘッダ名.
- Source:
(static) HMAC_KEY_BYTES
Device Connect Managerへ送信するHMAC生成キーの長さ. 単位はバイト.
- Source:
(static) INIT_SCOPES
Device Connectでサポートしているすべてのプロファイル.
- Source:
(static) NONCE_BYTES
Device Connect Managerへ送信するリクエストのnonceの長さ. 単位はバイト.
- Source:
(inner) self
内部クラスで循環参照を防ぐ.
- Source:
Methods
(static) this.appendScope()
scopesにプロファイルを追加する.
- Source:
(static) this.authorization(scopes, applicationName) → {Promise.<object>}
dConnectManagnerに認可を求める.
Parameters:
Name | Type | Description |
---|---|---|
scopes |
使用するスコープの配列 | |
applicationName |
アプリ名 |
- Source:
Returns:
- Type
- Promise.<object>
Example
// 初期化
const sdk = new dConnectSDK({
host:"192.168.0.xx",
port: 4035
});
// アクセスするプロファイル一覧を定義
const scopes = Array('servicediscovery', 'sysytem', 'battery');
// 認可を実行
sdk.authorization(scopes, 'サンプル')
.then(accessToken => {
// accessTokenを保存して、プロファイルにアクセス
}).catch(e => {
alert('Failed to get accessToken.');
});
(static) this.checkDeviceConnect() → {Promise.<object>}
Device Connect Managerが起動しているチェックする。そもそもインストールされていなければ、インストール
画面へと進ませる。
- Source:
Returns:
- Type
- Promise.<object>
(static) this.combineScope(scopes)
スコープの配列を文字列に置換する.
Parameters:
Name | Type | Description |
---|---|---|
scopes |
Array.<String> | スコープ一覧 |
- Source:
Returns:
(static) this.connectWebSocket(cb) → {Promise.<object>}
WebSocketを開く.
WebSocketは、一つしか接続することができない。 sdk.isConnectedWebSocket()を用いて、接続確認はできるので、 接続されている場合には、一度、sdk.disconnectWebSocket()で 切断してから、再度接続処理を行って下さい。
Parameters:
Name | Type | Description |
---|---|---|
cb |
WebSocketの開閉イベントを受け取るコールバック関数 |
- Source:
Returns:
- Type
- Promise.<object>
Example
// Websocketを開く
sdk.connectWebSocket(s => {
// WebSocketの接続状態のオブジェクトが返ってくる.
}).catch(e => {
// エラーコードを返す.
});
(static) this.containsScope() → {Boolean}
scopesにすでに指定したプロファイルが追加されているか.
- Source:
Returns:
true:すでにscopesに指定したプロファイルが追加されている.
false: プロファイルが追加されていない.
false: プロファイルが追加されていない.
- Type
- Boolean
(static) this.converObjToUri() → {object}
オブジェクトの引数をURIBuilderに変換する.
- Source:
Returns:
パラメータ
- Type
- object
(static) this.createClient() → {Promise.<object>}
クライアントを作成する.
- Source:
Returns:
- Type
- Promise.<object>
Example
// 初期化
const sdk = new dConnectSDK({
host:"192.168.0.xx",
port: 4035
});
sdk.createClient()
.then(clientId => {
// clientIdを保存して、アクセストークンの取得に使用する
}).catch(e => {
}
);
(static) this.delete(request, header) → {Promise.<object>}
HTTPリクエストのDELETEメソッドへの簡易アクセスを提供する。
Parameters:
Name | Type | Description |
---|---|---|
request |
object | リクエストパラメータのJavaScriptのオブジェクト. |
header |
object | HTTPリクエストのヘッダーに含める項目 |
- Source:
Returns:
- Type
- Promise.<object>
Example
// 初期化
const sdk = new dConnectSDK({
host:"192.168.0.xx",
port: 4035
});
sdk.delete({
profile: "test",
interface: "test",
attribute: "test",
params : {
serviceId: "testId"
}
})
.then(json => {
}).catch(e => {
});
(static) this.disconnectWebSocket()
WebSocketを切断する.
- Source:
(static) this.discoverDevices() → {Promise.<object>}
Service Discovery APIへの簡易アクセスを提供する。
アクセストークンが取得されていない場合は自動で取得処理を行います。
- Source:
Returns:
- Type
- Promise.<object>
Example
// 初期化
const sdk = new dConnectSDK({
host:"192.168.0.xx",
port: 4035
});
sdk.discoverDevices()
.then(json => {
let devices = json.services;
}).catch(e => {
});
(static) this.discoverDevicesFromProfile(profileName) → {Promise.<object>}
プロファイル名からサービス一覧を取得するためのAPIを提供する。
Parameters:
Name | Type | Description |
---|---|---|
profileName |
String | プロファイル名 |
- Source:
Returns:
- Type
- Promise.<object>
Example
// 初期化
const sdk = new dConnectSDK({
host:"192.168.0.xx",
port: 4035
});
// サービスの検索
sdk.discoverDevicesFromProfile('battery')
.then(json => {
let services = json.services;
}.catch(e => {
});
(static) this.execute(method, uri, header, body) → {Promise.<object>}
REST API呼び出し.
Parameters:
Name | Type | Description |
---|---|---|
method |
String | HTTPメソッド |
uri |
String | URI |
header |
Object.<String, String> | HTTPリクエストヘッダー。Key-Valueマップで渡す。 |
body |
コンテンツデータ |
- Source:
- See:
-
- sendRequest
Returns:
- Type
- Promise.<object>
(static) this.get(request, header) → {Promise.<object>}
HTTPリクエストのGETメソッドへの簡易アクセスを提供する。
Parameters:
Name | Type | Description |
---|---|---|
request |
object | リクエストパラメータのJavaScriptのオブジェクト. |
header |
object | HTTPリクエストのヘッダーに含める項目 |
- Source:
Returns:
- Type
- Promise.<object>
Example
// デバイスの検索
const sdk = new dConnectSDK({
host:"192.168.0.xx",
port: 4035
});
sdk.get({
profile: "test",
interface: "test",
attribute: "test",
params: {
serviceId: "testId"
}
})
.then(json => {
}).catch(e => {
});
(static) this.getAccessToken() → {String}
アクセストークンを取得する.
- Source:
Returns:
アクセストークン
- Type
- String
(static) this.getBaseDomain() → {String}
ベースとなるドメイン名を取得する.
- Source:
Returns:
ドメイン名
- Type
- String
(static) this.getSystemDeviceInfo(serviceId) → {Promise.<object>}
Service Information APIへの簡易アクセスを提供する。
Parameters:
Name | Type | Description |
---|---|---|
serviceId |
String | サービスID |
- Source:
Returns:
- Type
- Promise.<object>
Example
// 初期化
const sdk = new dConnectSDK({
host:"192.168.0.xx",
port: 4035
});
sdk.getSystemDeviceInfo()
.then(json => {
}).catch(e => {
});
(static) this.getSystemInfo() → {Promise.<object>}
System APIへの簡易アクセスを提供する。
- Source:
Returns:
- Type
- Promise.<object>
Example
// 初期化
const sdk = new dConnectSDK({
host:"192.168.0.xx",
port: 4035
});
sdk.getSystemInfo()
.then(json => {
}).catch(e => {
});
(static) this.isEnabledAntiSpoofing()
サーバからのレスポンス受信時にサーバの認証を行うかどうかのフラグを取得する.
- Source:
Returns:
サーバの認証を行う場合はtrue、そうでない場合はfalse
(static) this.isSSLEnabled()
HTTPおよびWebSocket通信でSSLを使用するかどうかを取得する.
デフォルト設定ではSSLは使用しない。
- Source:
Returns:
SSLを使用する場合はtrue、使用しない場合はfalse
(static) this.post(request, header) → {Promise.<object>}
HTTPリクエストのPOSTメソッドへの簡易アクセスを提供する。
Parameters:
Name | Type | Description |
---|---|---|
request |
object | リクエストパラメータのJavaScriptのオブジェクト(URIにパラメータを付加する場合). |
header |
object | HTTPリクエストのヘッダーに含める項目 |
- Source:
Returns:
- Type
- Promise.<object>
Example
// デバイスの検索
const sdk = new dConnectSDK({
host:"192.168.0.xx",
port: 4035
});
sdk.post({
profile: "test",
interface: "test",
attribute: "test"
body: {
serviceId: "testId"
}
})
.then(json => {
}).catch(e => {
});
(static) this.put(request, header) → {Promise.<object>}
HTTPリクエストのPUTメソッドへの簡易アクセスを提供する。
Parameters:
Name | Type | Description |
---|---|---|
request |
object | リクエストパラメータのJavaScriptのオブジェクト(URIにパラメータを付加する場合). |
header |
object | HTTPリクエストのヘッダーに含める項目 |
- Source:
Returns:
- Type
- Promise.<object>
Example
// デバイスの検索
const sdk = new dConnectSDK({
host:"192.168.0.xx",
port: 4035
});
sdk.put({
profile: "test",
interface: "test",
attribute: "test"
body: {
serviceId: "testId"
}
})
.then(json => {
}).catch(e => {
});
(static) this.removeEventListener(request) → {Promise.<object>}
指定されたDevice Connect Event APIからイベントリスナーを削除する。
Parameters:
Name | Type | Description |
---|---|---|
request |
Object | 特定のDevice Connect Event APIを表すURI(オブジェクト) |
- Source:
Returns:
- Type
- Promise.<object>
Example
const sdk = new dConnectSDK({
host: '192.168.0.24',
port: 4035
});
sdk.removeEventListener({
profile: 'deviceorientation',
attribute: 'ondeviceorientation',
serviceId: 'Host.xxxxxxx.localhost.deviceconnect.org'
}).then(json => {
sdk.disconnectWebSocket(); //WebSocketの切断
}).catch (e => {
});
(static) this.requestAccessToken(clientId, scopes, applicationName) → {Promise.<object>}
アクセストークンを要求する.
Parameters:
Name | Type | Description |
---|---|---|
clientId |
クライアントID | |
scopes |
スコープ一覧(配列) | |
applicationName |
アプリ名 |
- Source:
Returns:
- Type
- Promise.<object>
Example
// 初期化
const sdk = new dConnectSDK({
host:"192.168.0.xx",
port: 4035
});
sdk.requestAccessToken(clientId, scopes, 'アプリ名')
.then(accessToken => {
// アクセストークンの保存して、プロファイルのアクセスを行う
}).catch(e => {
}
);
(static) this.sendRequest(method, request, header) → {Promise.<object>}
Device Connect RESTful APIを実行する.
+ レスポンスの受信に成功した場合でも、サーバの認証に失敗した場合はエラーコールバックを実行する.
Parameters:
Name | Type | Description |
---|---|---|
method |
String | メソッド |
request |
Object | リクエストパラメータのJavaScriptのオブジェクト. |
header |
Object.<String, String> | リクエストヘッダー。Key-Valueマップで渡す。 |
- Source:
Returns:
- Type
- Promise.<object>
(static) this.setAntiSpoofing(enable)
サーバからのレスポンス受信時にサーバの認証を行うかどうかを設定する.
Parameters:
Name | Type | Description |
---|---|---|
enable |
サーバの認証を行う場合はtrue、そうでない場合はfalse |
- Source:
(static) this.setExtendedOrigin(o)
オリジンを設定する.
ハイブリッドアプリとして動作させる場合には本メソッドでオリジンを設定する.
Parameters:
Name | Type | Description |
---|---|---|
o |
String | オリジン |
- Source:
(static) this.setLaunchListener(listener)
Device Connect Managerの起動通知を受信するリスナーを設定する.
注意: Device Connect Managerの起動はアプリケーションの表示状態が非表示から表示へ 遷移したタイミングで確認される.
Parameters:
Name | Type | Description |
---|---|---|
listener |
リスナー |
- Source:
(static) this.setPort(p)
ポート番号を設定する.
Parameters:
Name | Type | Description |
---|---|---|
p |
Number | ポート番号 |
- Source:
(static) this.setSSLEnabled(enabled)
HTTPおよびWebSocket通信でSSLを使用するかどうかを設定する.
デフォルト設定ではSSLは使用しない。
Parameters:
Name | Type | Description |
---|---|---|
enabled |
String | SSLを使用する場合はtrue、使用しない場合はfalse |
- Source:
(static) this.setURISchemeName(name)
Manager起動用URIスキームの名前を設定する.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | Manager起動用URIスキームの名前 |
- Source:
(static) this.startManager(state)
Device Connect Managerを起動する.
Parameters:
Name | Type | Description |
---|---|---|
state |
起動画面を出すか出さないか |
- Source:
(static) this.stopManager(state)
Device Connect Managerを停止する.
Parameters:
Name | Type | Description |
---|---|---|
state |
停止画面を出すか出さないか |
- Source: