-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Takuya Murakami
committed
Aug 31, 2018
0 parents
commit 940c5f4
Showing
16 changed files
with
1,178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*~ | ||
*.bak | ||
node_modules/ | ||
package-lock.json | ||
|
||
.idea/ | ||
*.iml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
2018/06/20 : v7.0.3 | ||
|
||
* 機能追加・改善 | ||
- 送信者許可設定API追加 | ||
- Push受信待機完了通知追加 | ||
|
||
2018/05/16 : v7.0.2 | ||
|
||
* 機能追加・改善 | ||
- CONNECTメソッドの Host ヘッダ値修正 | ||
- tunnel モジュールを tunnel-fork に変更 | ||
- js-sdk v7.0.2の適用 | ||
|
||
2018/03/29 : v7.0.0 | ||
|
||
* js-sdk v7.0.1の適用 | ||
|
||
2018/03/09 : v7.0.0 rc1 | ||
|
||
* 機能追加・改善 | ||
- [8591] パッケージ名を @nec-baas/ssepush-node に変更 | ||
|
||
2017/12/13 : v7.0.0-beta1 | ||
|
||
* 不具合修正 | ||
- [7701] サーバ証明書検証が行われない問題を修正 (eventsource.js 側の不具合回避) | ||
|
||
2017/10/04 | ||
|
||
- Proxy 設定変更。HTTPS接続時は自動的に tunnel agent を使用する。 | ||
|
||
2017/09/21 : v1.0.1 | ||
|
||
- shutdown() 時に heart beat タイマを停止する処理を追加 | ||
- start() 時に古い eventSource を shutdown する処理を追加 | ||
- デバッグ用ログ追加 | ||
|
||
2017/07/14 : v1.0.0 | ||
|
||
- 初版 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
NEC Mobile Backend Platform: SSE Push SDK for Node.js | ||
|
||
Copyright (c) 2013-2018 NEC Corporation | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License | ||
|
||
Copyright (c) EventSource GitHub organisation | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
NECモバイルバックエンド基盤: Node.js 用 SSE Push SDK | ||
==================================================== | ||
|
||
NECモバイルバックエンド基盤(BaaS)の Node.js 向け SSE Push | ||
クライアントライブラリです。 | ||
|
||
本ライブラリは Node.js 専用です。ブラウザでは利用できません。 | ||
|
||
準備 | ||
---- | ||
|
||
本ライブラリを使用するアプリケーションディレクトリ(package.jsonが存在する | ||
ディレクトリ)に移動し、本ライブラリを npm install でインストールしてください。 | ||
|
||
$ npm install @nec-baas/ssepush-node --save | ||
|
||
使用方法 | ||
-------- | ||
|
||
サンプルが example/client.js にありますので、詳細はこちらを確認ください。 | ||
|
||
### インスタンスの生成 | ||
|
||
最初に、本ライブラリを require してください。 | ||
(BaaS ライブラリの require と初期化も必要です) | ||
|
||
const SsePush = require('@nec-baas/ssepush-node').SsePush; | ||
|
||
以下手順で SsePush インスタンスを生成します。 | ||
|
||
const ssePush = new SsePush(Nebula); | ||
// デバイストークン設定 | ||
ssePush.setDeviceToken(deviceToken); | ||
|
||
デバイストークンは、デバイスに固有の識別子です。UUIDなどを使用することを | ||
推奨します(SsePush.uuid()で生成可能)。デバイストークンは同一デバイス | ||
では原則変更しないように、適宜保存するなどしてください。 | ||
|
||
### 受信チャネル設定 | ||
|
||
受信チャネルを設定する場合は、setChannels で指定します。 | ||
|
||
ssePush.setChannels(['channel1', 'channel2']) | ||
|
||
### ハートビート間隔・監視設定 | ||
|
||
ハートビート間隔の設定は setHeartbeatInterval で行います。 | ||
値はサーバ側の設定に合わせてください。 | ||
|
||
ssePush.setHeartbeatInterval(30); | ||
|
||
ハートビート間隔の2倍の時間が経過してもハートビート受信ができない場合は、 | ||
onError でエラー通知されます。 | ||
|
||
なお、ハートビート間隔を設定しない場合は、ハートビート監視は行われません。 | ||
|
||
### 登録・受信開始 | ||
|
||
BaaSサーバへのインスタレーション登録と Push 待ち受けを開始します。 | ||
ユーザがログイン状態になっている場合は、インスタレーションは自動的にユーザ | ||
に紐づけされます。 | ||
|
||
// BaaSサーバへの登録と Push 待ち受けを開始 | ||
ssePush.start({ | ||
onMessage: (message) => { | ||
// 受信処理 | ||
}, | ||
onError: (error) => { | ||
// エラー処理 | ||
} | ||
}); | ||
|
||
SSE Push メッセージを受信するたびに onMessage が呼び出されます。 | ||
引数でメッセージが渡されます。メッセージは以下のような JSON object | ||
で、本文は "data" に格納されます。 | ||
|
||
{ | ||
"type": "message", | ||
"data": "This is a test.", | ||
"lastEventId": "", | ||
"origin": "https://baas.example.com" | ||
} | ||
|
||
エラー時は onError が呼び出されますので、適宜回復処理を行ってください。 | ||
ステータスコードは error.status に格納されます。 | ||
|
||
オプション | ||
--------- | ||
|
||
Proxy サーバを使用する場合は、SsePush コンストラクタの第二引数にオプション | ||
を指定してください (注: 認証付きの Proxy は使用できません) | ||
|
||
const options = { proxy: 'http://proxy.example.com:8080' } | ||
const ssePush = new SsePush(Nebula, options); | ||
|
||
HTTPS接続でかつサーバ側が自己署名証明書を使用している場合は、以下のオプションを指定します。 | ||
(非推奨) | ||
|
||
const options = { rejectUnauthorized: false } | ||
|
||
その他のオプションについては、[EventSource](https://github.com/EventSource/eventsource) | ||
の README を参照してください。 | ||
|
||
OSSライセンス | ||
------------- | ||
|
||
本モジュールは EventSource v1.0.5 を改造したものを含んでいます。 | ||
(lib/eventsource.js) | ||
https://github.com/EventSource/eventsource | ||
|
||
改造内容は以下のとおりです。 | ||
|
||
* oncomment コールバックを追加 | ||
* options に agent を追加 | ||
|
||
ライセンス条件は LICENSE.eventsource を参照してください。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const Nebula = require('@nec-baas/jssdk').Nebula; | ||
const SsePush = require('../lib/ssepush.js').SsePush; | ||
//const SsePush = require('baas-ssepush-nodejs').SsePush; | ||
|
||
const config = require('./config.js'); | ||
const proxy = config.proxy; | ||
|
||
// BaaS 初期化 | ||
if (proxy != null) { | ||
Nebula.setHttpProxy(proxy); | ||
Nebula.setHttpsProxy(proxy); | ||
} | ||
Nebula.initialize(config); | ||
|
||
// SSE Push インスタンス生成 | ||
const options = {}; | ||
if (proxy != null) { | ||
options.proxy = "http://" + proxy.host + ":" + proxy.port; | ||
} | ||
const ssePush = new SsePush(Nebula, options); | ||
|
||
// デバイストークン設定 | ||
ssePush.setDeviceToken(config.deviceToken); | ||
|
||
// ハートビート間隔設定 | ||
ssePush.setHeartbeatInterval(30); | ||
|
||
// 登録・受信開始 | ||
console.log("Start connect: deviceToken = " + config.deviceToken); | ||
ssePush.start({ | ||
onMessage: (message) => { | ||
console.log("push message: " + JSON.stringify(message)); | ||
}, | ||
onError: (error) => { | ||
console.log("ERROR: " + JSON.stringify(error)); | ||
} | ||
}); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
tenant: '', | ||
appId: '', | ||
appKey: '', | ||
baseUri: '', | ||
debugMode: true, | ||
/* | ||
proxy: { | ||
host: 'proxy.example.com', | ||
port: 8080 | ||
} | ||
*/ | ||
|
||
deviceToken: '214cd7f5-700a-6739-2adcbba14833', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ssepush.js | ||
*.js.map | ||
*.d.ts |
Empty file.
Oops, something went wrong.