Skip to content

Commit

Permalink
docs: Updated readme content
Browse files Browse the repository at this point in the history
Changed the structure and content of the readme.md file.
  • Loading branch information
client-engineering-bot committed Oct 20, 2020
1 parent 403e14c commit 6f43e0c
Show file tree
Hide file tree
Showing 15 changed files with 196 additions and 277 deletions.
89 changes: 79 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,89 @@
[![Bower](https://img.shields.io/bower/v/pubnub.svg)]()
[![Known Vulnerabilities](https://snyk.io/test/npm/pubnub/badge.svg)](https://snyk.io/test/npm/pubnub)

### Looking for Javascript V3 SDK?
please use the [master_3x](https://github.com/pubnub/javascript/tree/master_3x) branch
This is the official PubNub JavaScript SDK repository.

### PubNub for JavaScript Docs have been moved to:
* [web](https://www.pubnub.com/docs/javascript/pubnub-javascript-sdk-v4)
* [node](https://www.pubnub.com/docs/nodejs/pubnub-javascript-sdk-v4)
PubNub takes care of the infrastructure and APIs needed for the realtime communication layer of your application. Work on your app's logic and let PubNub handle sending and receiving data across the world in less than 100ms.

## Communication
## Get keys

- If you **need help** or have a **general question**, contact <support@pubnub.com>
You will need the publish and subscribe keys to authenticate your app. Get your keys from the [Admin Portal](https://dashboard.pubnub.com/login).

## CDN Links
## Configure PubNub

1. Integrate the JavaScript SDK into your project:
* use `npm`:
```
npm install pubnub
```
* or download one of our builds from our CDN:
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.29.9.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.29.9.min.js

2. Configure your keys:

* https://cdn.pubnub.com/sdk/javascript/pubnub.4.29.9.min.js
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.29.9.js
```javascript
pubnub = new PubNub({
publishKey : "myPublishKey",
subscribeKey : "mySubscribeKey",
uuid: "myUniqueUUID"
})
```

## Add event listeners

```javascript
pubnub.addListener({
message: function (m) {
// handle messages
},
presence: function (p) {
// handle presence
},
signal: function (s) {
// handle signals
},
objects: (objectEvent) => {
// handle pbjects
},
messageAction: function (ma) {
// handle message actions
},
file: function (event) {
// handle files
},
status: function (s) {
// handle status
},
});
```

## Publish/subscribe

```javascript
var publishPayload = {
channel : "hello_world",
message: {
title: "greeting",
description: "This is my first message!"
}
}
pubnub.publish(publishPayload, function(status, response) {
console.log(status, response);
})
pubnub.subscribe({
channels: ["hello_world"]
});
```

## Documentation

* [Build your first realtime JS app with PubNub](https://www.pubnub.com/docs/platform/quickstarts/javascript)
* [API reference for JavaScript (web)](https://www.pubnub.com/docs/web-javascript/pubnub-javascript-sdk)
* [API reference for JavaScript (Node.js)](https://www.pubnub.com/docs/nodejs-javascript/pubnub-javascript-sdk)

## Support

If you **need help** or have a **general question**, contact <support@pubnub.com>.
122 changes: 36 additions & 86 deletions dist/titanium/pubnub.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! 4.29.9 / Consumer */
/*! 4.29.8-rc1 / Consumer */
exports["PubNub"] =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
Expand Down Expand Up @@ -566,7 +566,7 @@ var _default = function () {
}, {
key: "getVersion",
value: function getVersion() {
return '4.29.9';
return '4.29.8-rc1';
}
}, {
key: "_addPnsdkSuffix",
Expand Down Expand Up @@ -756,8 +756,6 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createValidationError = createValidationError;
exports.generatePNSDK = generatePNSDK;
exports.signRequest = signRequest;
exports["default"] = _default;
exports.PubNubError = void 0;

Expand Down Expand Up @@ -894,10 +892,6 @@ function signRequest(modules, url, outgoingParams, incomingParams, endpoint) {
httpMethod = 'GET';
}

if (httpMethod === 'GETFILE') {
httpMethod = 'GET';
}

var signInput = "".concat(httpMethod, "\n").concat(config.publishKey, "\n").concat(url, "\n").concat(_utils["default"].signPamFromParams(outgoingParams), "\n");

if (httpMethod === 'POST') {
Expand Down Expand Up @@ -7692,18 +7686,6 @@ var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(22));

var _endpoint = __webpack_require__(16);

var getErrorFromResponse = function getErrorFromResponse(response) {
return new Promise(function (resolve) {
var result = '';
response.on('data', function (data) {
result += data.toString('utf8');
});
response.on('end', function () {
resolve(result);
});
});
};

var sendFile = function sendFile(_ref) {
var generateUploadUrl = _ref.generateUploadUrl,
publishFile = _ref.publishFile,
Expand All @@ -7714,7 +7696,7 @@ var sendFile = function sendFile(_ref) {
networking = _ref$modules.networking;
return function () {
var _ref3 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(_ref2) {
var channel, input, message, cipherKey, meta, ttl, storeInHistory, file, _yield$generateUpload, _yield$generateUpload2, url, formFields, _yield$generateUpload3, id, name, formFieldsWithMimeType, result, errorBody, reason, retries, wasSuccessful, publishResult;
var channel, input, message, cipherKey, meta, ttl, storeInHistory, file, _yield$generateUpload, _yield$generateUpload2, url, formFields, _yield$generateUpload3, id, name, formFieldsWithMimeType, result, retries, wasSuccessful;

return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
Expand Down Expand Up @@ -7870,43 +7852,34 @@ var sendFile = function sendFile(_ref) {
throw new Error('Unsupported environment');

case 71:
_context.next = 80;
_context.next = 76;
break;

case 73:
_context.prev = 73;
_context.t16 = _context["catch"](21);
_context.next = 77;
return getErrorFromResponse(_context.t16.response);
throw new _endpoint.PubNubError('Upload to bucket failed', _context.t16);

case 77:
errorBody = _context.sent;
reason = /<Message>(.*)<\/Message>/gi.exec(errorBody);
throw new _endpoint.PubNubError(reason ? "Upload to bucket failed: ".concat(reason[1]) : 'Upload to bucket failed.', _context.t16);

case 80:
case 76:
if (!(result.status !== 204)) {
_context.next = 82;
_context.next = 78;
break;
}

throw new _endpoint.PubNubError('Upload to bucket was unsuccessful', result);

case 82:
case 78:
retries = 5;
wasSuccessful = false;
publishResult = {
timetoken: '0'
};

case 85:
case 80:
if (!(!wasSuccessful && retries > 0)) {
_context.next = 98;
_context.next = 92;
break;
}

_context.prev = 86;
_context.next = 89;
_context.prev = 81;
_context.next = 84;
return publishFile({
channel: channel,
message: message,
Expand All @@ -7917,24 +7890,23 @@ var sendFile = function sendFile(_ref) {
ttl: ttl
});

case 89:
publishResult = _context.sent;
case 84:
wasSuccessful = true;
_context.next = 96;
_context.next = 90;
break;

case 93:
_context.prev = 93;
_context.t17 = _context["catch"](86);
case 87:
_context.prev = 87;
_context.t17 = _context["catch"](81);
retries -= 1;

case 96:
_context.next = 85;
case 90:
_context.next = 80;
break;

case 98:
case 92:
if (wasSuccessful) {
_context.next = 102;
_context.next = 96;
break;
}

Expand All @@ -7944,19 +7916,18 @@ var sendFile = function sendFile(_ref) {
name: name
});

case 102:
case 96:
return _context.abrupt("return", {
timetoken: publishResult.timetoken,
id: id,
name: name
});

case 103:
case 97:
case "end":
return _context.stop();
}
}
}, _callee, null, [[21, 73], [86, 93]]);
}, _callee, null, [[21, 73], [81, 87]]);
}));

return function (_x) {
Expand Down Expand Up @@ -8754,11 +8725,11 @@ exports["default"] = void 0;

var _endpoint = __webpack_require__(16);

var _default = function _default(modules, _ref) {
var channel = _ref.channel,
id = _ref.id,
name = _ref.name;
var config = modules.config;
var _default = function _default(_ref, _ref2) {
var config = _ref.config;
var channel = _ref2.channel,
id = _ref2.id,
name = _ref2.name;

if (!channel) {
throw new _endpoint.PubNubError('Validation failed, check status for details', (0, _endpoint.createValidationError)("channel can't be empty"));
Expand All @@ -8772,32 +8743,7 @@ var _default = function _default(modules, _ref) {
throw new _endpoint.PubNubError('Validation failed, check status for details', (0, _endpoint.createValidationError)("file name can't be empty"));
}

var url = "/v1/files/".concat(config.subscribeKey, "/channels/").concat(channel, "/files/").concat(id, "/").concat(name);
var params = {};
params.uuid = config.getUUID();
params.pnsdk = (0, _endpoint.generatePNSDK)(config);

if (config.getAuthKey()) {
params.auth = config.getAuthKey();
}

if (config.secretKey) {
(0, _endpoint.signRequest)(modules, url, params, {}, {
getOperation: function getOperation() {
return 'PubNubGetFileUrlOperation';
}
});
}

var queryParams = Object.keys(params).map(function (key) {
return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(params[key]));
}).join('&');

if (queryParams !== '') {
return "https://".concat(config.origin).concat(url, "?").concat(queryParams);
}

return "https://".concat(config.origin).concat(url);
return "https://".concat(config.origin, "/v1/files/").concat(config.subscribeKey, "/channels/").concat(channel, "/files/").concat(id, "/").concat(name);
};

exports["default"] = _default;
Expand Down Expand Up @@ -8860,11 +8806,15 @@ var endpoint = {
forceBuffered: function forceBuffered() {
return true;
},
getAuthToken: function getAuthToken(_ref3) {
var tokenManager = _ref3.tokenManager;
return tokenManager.getToken('fileUpload');
},
prepareParams: function prepareParams() {
return {};
},
handleResponse: function () {
var _handleResponse = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(_ref3, res, params) {
var _handleResponse = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(_ref4, res, params) {
var _res$response$name;

var PubNubFile, config, cryptography, body, _params$cipherKey;
Expand All @@ -8873,7 +8823,7 @@ var endpoint = {
while (1) {
switch (_context.prev = _context.next) {
case 0:
PubNubFile = _ref3.PubNubFile, config = _ref3.config, cryptography = _ref3.cryptography;
PubNubFile = _ref4.PubNubFile, config = _ref4.config, cryptography = _ref4.cryptography;
body = res.response.body;

if (!(PubNubFile.supportsEncryptFile && config.cipherKey)) {
Expand Down
4 changes: 2 additions & 2 deletions dist/titanium/pubnub.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 6f43e0c

Please sign in to comment.