Skip to content

Commit

Permalink
Merge pull request #303 from skyway/staging
Browse files Browse the repository at this point in the history
Release v4.3.0
  • Loading branch information
d-matsui authored Jan 19, 2021
2 parents bff3a26 + 857b30b commit 4525e53
Show file tree
Hide file tree
Showing 13 changed files with 231 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ jobs:
- run:
name: Install extra deps for CI
command: npm install --no-save replace-in-file@3.0.0 aws-sdk@2.597.0 @octokit/rest@16.36.0 @slack/client@5.0.2
- add_ssh_keys:
fingerprints:
- "56:a2:ef:d1:41:dd:99:a2:95:cf:df:a0:15:0e:6b:f1"
- run: node ./scripts/release-master

workflows:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## release note

## [v4.3.0](https://github.com/skyway/skyway-js-sdk/releases/tag/v4.3.0) - 2021-01-19

### Fixed

- Fixed a connecting process to signaling server so that `Peer` would reconnect when a request to the dispatcher server failed. ([#297](https://github.com/skyway/skyway-js-sdk/pull/297))
- Remove unnecessary module settings in package.json.

## [v4.2.0](https://github.com/skyway/skyway-js-sdk/releases/tag/v4.2.0) - 2020-12-22

### Added
Expand Down
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,13 @@
Add the following script tag to your html file.

```html
<script type="text/javascript" src="https://cdn.webrtc.ecl.ntt.com/skyway-latest.js"></script>
<script type="text/javascript" src="https://cdn.webrtc.ecl.ntt.com/skyway-4.3.0.js"></script>
```

You can then use the `Peer` object to start connecting.
For more details, check out the [Tutorial](https://webrtc.ecl.ntt.com/en/js-tutorial.html). ([日本語](https://webrtc.ecl.ntt.com/js-tutorial.html))

#### How to specify version and minified
By changing the file name, you can use each version and minified version.

Example
- Using version 4.2.0: `skyway-4.2.0.js`.
- Using minified version 4.2.0 : `skyway-4.2.0.min.js`.
- Using the latest minified version: `skyway-latest.min.js`.

#### CAUTION
When using `skyway-latest.js` and `skyway-latest.min.js`, when a new version of the SDK is released, the latest version will automatically be applied to your application. This makes it easy to keep up with browser updates, but depending on the changes in the SDK, your application may be affected.

To use the compressed version, add `.min` to the end of the file name, like `skyway-4.3.0.min.js`.

### Installing using npm to use with a bundler (e.g. webpack or browserify)

Expand Down
2 changes: 1 addition & 1 deletion examples/p2p-data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h1 class="heading">P2P Data example</h1>
</div>
<p class="meta" id="js-meta"></p>
</div>
<script src="//cdn.webrtc.ecl.ntt.com/skyway-latest.js"></script>
<script src="//cdn.webrtc.ecl.ntt.com/skyway-4.3.0.js"></script>
<script src="../_shared/key.js"></script>
<script src="./script.js"></script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion examples/p2p-media/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1 class="heading">P2P Media example</h1>
</div>
<p class="meta" id="js-meta"></p>
</div>
<script src="//cdn.webrtc.ecl.ntt.com/skyway-latest.js"></script>
<script src="//cdn.webrtc.ecl.ntt.com/skyway-4.3.0.js"></script>
<script src="../_shared/key.js"></script>
<script src="./script.js"></script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion examples/room/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h1 class="heading">Room example</h1>
</div>
<p class="meta" id="js-meta"></p>
</div>
<script src="//cdn.webrtc.ecl.ntt.com/skyway-latest.js"></script>
<script src="//cdn.webrtc.ecl.ntt.com/skyway-4.3.0.js"></script>
<script src="../_shared/key.js"></script>
<script src="./script.js"></script>
</body>
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "skyway-js",
"version": "4.2.0",
"version": "4.3.0",
"description": "The official JavaScript SDK for SkyWay",
"main": "dist/skyway.js",
"module": "src/peer.js",
"types": "skyway-js.d.ts",
"scripts": {
"test": "karma start ./karma.conf.js",
Expand Down
7 changes: 7 additions & 0 deletions scripts/release-master/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const isReleaseReady = require('./is-release-ready');
const publishToNpm = require('./publish-to-npm');
const publishToGitHub = require('./publish-to-github');
const notifySlack = require('./notify-slack');
const execSync = require('child_process').execSync;

(async function() {
const {
Expand Down Expand Up @@ -59,6 +60,12 @@ const notifySlack = require('./notify-slack');
return process.exit(0);
}

console.log('## Change sdk version on website');
const stdout = execSync(
`bash ./scripts/release-master/update-website.sh ${version}`
);
console.log(`stdout: ${stdout.toString()}`);

console.log('## Publish to npm');
await publishToNpm({ NPM_TOKEN });
console.log('');
Expand Down
47 changes: 47 additions & 0 deletions scripts/release-master/is-release-ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ module.exports = async function isReleaseReady(version) {
console.log('=> Yes. continue release steps');
console.log('');

console.log(`Script tag for v${version} exists in each example file?`);
const cond2 = isAllExampleSdkVersionURLCorrect(version);
if (!cond2) {
console.log('=> No. abort release steps');
console.log('');
return false;
}
console.log('=> Yes. continue release steps');
console.log('');

console.log(`v${version} exists in README.md?`);
const cond3 = isReadmeVersionURLCorrect(version);
if (!cond3) {
console.log('=> No. abort release steps');
console.log('');
return false;
}
console.log('=> Yes. continue release steps');
console.log('');

return true;
};

Expand All @@ -34,3 +54,30 @@ async function hasChangeLog(version) {
rl.once('close', () => resolve(false));
});
}

function isSdkVersionURLCorrect(version, filepath) {
const data = fs.readFileSync(filepath, 'utf8');
const matches = data.match(
/cdn\.webrtc\.ecl\.ntt\.com\/skyway-([0-9]+\.[0-9]+\.[0-9]+)(\.min)?\.js/g
);
for (const match of matches) {
if (!match.includes(version)) return false;
}
return true;
}

function isAllExampleSdkVersionURLCorrect(version) {
const examplePaths = [
'./examples/p2p-data/index.html',
'./examples/p2p-media/index.html',
'./examples/room/index.html',
];
for (const path of examplePaths) {
if (!isSdkVersionURLCorrect(version, path)) return false;
}
return true;
}

function isReadmeVersionURLCorrect(version) {
return isSdkVersionURLCorrect(version, './README.md');
}
29 changes: 29 additions & 0 deletions scripts/release-master/update-website.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

version=$1
BRANCH_WEBSITE='master'

# setup git
git config --global user.email "webrtc.skyway@gmail.com"
git config --global user.name "skyway-ci-bot"

# clone website repo
echo -e "StrictHostKeyChecking no\n" >> ~/.ssh/config
git clone -b $BRANCH_WEBSITE git@github.com:nttcom-webcore/skyway-official-web-site.git

# update version
cat skyway-official-web-site/docs/documents/javascript-sdk.md | grep ${version}
if [ "$?" -eq 0 ]; then
echo "Website is up to date. Skip updating website."
exit 0
fi
sed -i -e "s/skyway-[0-9]\{0,\}\.[0-9]\{0,\}\.[0-9]\{0,\}/${version}/g" skyway-official-web-site/docs/documents/javascript-sdk.md
sed -i -e "s/skyway-[0-9]\{0,\}\.[0-9]\{0,\}\.[0-9]\{0,\}/${version}/g" skyway-official-web-site/docs/en/documents/javascript-sdk.md

# deploy
cd skyway-official-web-site
git add -A
git commit -m 'Update js-sdk version'
git push origin $BRANCH_WEBSITE
echo 'Successful deployment!!'
exit 0
56 changes: 30 additions & 26 deletions src/peer/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,12 @@ class Socket extends EventEmitter {
}

if (this._dispatcherUrl) {
let serverInfo;
try {
serverInfo = await this._getSignalingServer();
this.signalingServerUrl = await this._fetchSignalingServerUrlWithRetry();
} catch (err) {
this.emit('error', err);
return;
}
const httpProtocol = serverInfo.secure ? 'https://' : 'http://';
this.signalingServerUrl = `${httpProtocol}${serverInfo.host}:${serverInfo.port}`;
}

this._io = io(this.signalingServerUrl, {
Expand All @@ -115,49 +112,56 @@ class Socket extends EventEmitter {
}

/**
* Connect to "new" signaling server. Attempts up to 10 times before giving up and emitting an error on the socket.
* @param {number} [numAttempts=0] - Current number of attempts.
* Connect to "new" signaling server.
* @return {Promise<void>} A promise that resolves with new connection has done.
* @private
*/
async _connectToNewServer(numAttempts = 0) {
// max number of attempts to get a new server from the dispatcher.
const maxNumberOfAttempts = 10;
if (
numAttempts >= maxNumberOfAttempts ||
this._reconnectAttempts >= config.numberServersToTry
) {
async _connectToNewServer() {
if (this._reconnectAttempts >= config.numberServersToTry) {
this.emit('error', 'Could not connect to server.');
return;
}

// Keep trying until we connect to a new server because consul can take some time to remove from the active list.
let serverInfo;
try {
serverInfo = await this._getSignalingServer();
this.signalingServerUrl = await this._fetchSignalingServerUrlWithRetry();
} catch (err) {
this.emit('error', err);
return;
}
this._io.io.uri = this.signalingServerUrl;
this._io.connect();
this._reconnectAttempts++;
}

if (this.signalingServerUrl.indexOf(serverInfo.host) === -1) {
const httpProtocol = serverInfo.secure ? 'https://' : 'http://';
this.signalingServerUrl = `${httpProtocol}${serverInfo.host}:${serverInfo.port}`;

this._io.io.uri = this.signalingServerUrl;
this._io.connect();
this._reconnectAttempts++;
} else {
this._connectToNewServer(++numAttempts);
/**
* Return signaling server url. This attempts trying up to maxNumberOfAttempts times before giving up then throw error.
* @return {String} A string of signaling server url.
*/
async _fetchSignalingServerUrlWithRetry() {
for (let attempts = 0; attempts < config.maxNumberOfAttempts; attempts++) {
const serverInfo = await this._fetchSignalingServer().catch(err => {
logger.warn(err);
});
if (
serverInfo &&
serverInfo.port &&
serverInfo.host &&
(!this.signalingServerUrl ||
this.signalingServerUrl.indexOf(serverInfo.host) === -1)
) {
const httpProtocol = serverInfo.secure ? 'https://' : 'http://';
return `${httpProtocol}${serverInfo.host}:${serverInfo.port}`;
}
}
throw new Error('Could not get signaling server url.');
}

/**
* Return object including signaling server info.
* @return {Promise<Object>} A promise that resolves with signaling server info
and rejects if there's no response or status code isn't 200.
*/
_getSignalingServer() {
_fetchSignalingServer() {
return new Promise((resolve, reject) => {
const http = new XMLHttpRequest();

Expand Down
4 changes: 4 additions & 0 deletions src/shared/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const maxDataSize = 20 * 1024 * 1024;
// The minimum interval of using Room.send() is 100 ms
const minBroadcastIntervalMs = 100;

// max number of attempts to get a new server from the dispatcher.
const maxNumberOfAttempts = 10;

// Number of reconnection attempts to the same server before giving up
const reconnectionAttempts = 2;

Expand Down Expand Up @@ -88,6 +91,7 @@ export default {
maxChunkSize,
maxDataSize,
minBroadcastIntervalMs,
maxNumberOfAttempts,
reconnectionAttempts,
numberServersToTry,
sendInterval,
Expand Down
Loading

0 comments on commit 4525e53

Please sign in to comment.