Skip to content

Commit 6f43e0c

Browse files
docs: Updated readme content
Changed the structure and content of the readme.md file.
1 parent 403e14c commit 6f43e0c

15 files changed

+196
-277
lines changed

README.md

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,89 @@
77
[![Bower](https://img.shields.io/bower/v/pubnub.svg)]()
88
[![Known Vulnerabilities](https://snyk.io/test/npm/pubnub/badge.svg)](https://snyk.io/test/npm/pubnub)
99

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

13-
### PubNub for JavaScript Docs have been moved to:
14-
* [web](https://www.pubnub.com/docs/javascript/pubnub-javascript-sdk-v4)
15-
* [node](https://www.pubnub.com/docs/nodejs/pubnub-javascript-sdk-v4)
12+
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.
1613

17-
## Communication
14+
## Get keys
1815

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

21-
## CDN Links
18+
## Configure PubNub
2219

20+
1. Integrate the JavaScript SDK into your project:
21+
* use `npm`:
22+
```
23+
npm install pubnub
24+
```
25+
* or download one of our builds from our CDN:
26+
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.29.9.js
27+
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.29.9.min.js
2328
29+
2. Configure your keys:
2430
25-
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.29.9.min.js
26-
* https://cdn.pubnub.com/sdk/javascript/pubnub.4.29.9.js
31+
```javascript
32+
pubnub = new PubNub({
33+
publishKey : "myPublishKey",
34+
subscribeKey : "mySubscribeKey",
35+
uuid: "myUniqueUUID"
36+
})
37+
```
38+
39+
## Add event listeners
40+
41+
```javascript
42+
pubnub.addListener({
43+
message: function (m) {
44+
// handle messages
45+
},
46+
presence: function (p) {
47+
// handle presence
48+
},
49+
signal: function (s) {
50+
// handle signals
51+
},
52+
objects: (objectEvent) => {
53+
// handle pbjects
54+
},
55+
messageAction: function (ma) {
56+
// handle message actions
57+
},
58+
file: function (event) {
59+
// handle files
60+
},
61+
status: function (s) {
62+
// handle status
63+
},
64+
});
65+
```
66+
67+
## Publish/subscribe
68+
69+
```javascript
70+
var publishPayload = {
71+
channel : "hello_world",
72+
message: {
73+
title: "greeting",
74+
description: "This is my first message!"
75+
}
76+
}
77+
78+
pubnub.publish(publishPayload, function(status, response) {
79+
console.log(status, response);
80+
})
81+
82+
pubnub.subscribe({
83+
channels: ["hello_world"]
84+
});
85+
```
86+
87+
## Documentation
88+
89+
* [Build your first realtime JS app with PubNub](https://www.pubnub.com/docs/platform/quickstarts/javascript)
90+
* [API reference for JavaScript (web)](https://www.pubnub.com/docs/web-javascript/pubnub-javascript-sdk)
91+
* [API reference for JavaScript (Node.js)](https://www.pubnub.com/docs/nodejs-javascript/pubnub-javascript-sdk)
92+
93+
## Support
94+
95+
If you **need help** or have a **general question**, contact <[email protected]>.

dist/titanium/pubnub.js

Lines changed: 36 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! 4.29.9 / Consumer */
1+
/*! 4.29.8-rc1 / Consumer */
22
exports["PubNub"] =
33
/******/ (function(modules) { // webpackBootstrap
44
/******/ // The module cache
@@ -566,7 +566,7 @@ var _default = function () {
566566
}, {
567567
key: "getVersion",
568568
value: function getVersion() {
569-
return '4.29.9';
569+
return '4.29.8-rc1';
570570
}
571571
}, {
572572
key: "_addPnsdkSuffix",
@@ -756,8 +756,6 @@ Object.defineProperty(exports, "__esModule", {
756756
value: true
757757
});
758758
exports.createValidationError = createValidationError;
759-
exports.generatePNSDK = generatePNSDK;
760-
exports.signRequest = signRequest;
761759
exports["default"] = _default;
762760
exports.PubNubError = void 0;
763761

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

897-
if (httpMethod === 'GETFILE') {
898-
httpMethod = 'GET';
899-
}
900-
901895
var signInput = "".concat(httpMethod, "\n").concat(config.publishKey, "\n").concat(url, "\n").concat(_utils["default"].signPamFromParams(outgoingParams), "\n");
902896

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

76937687
var _endpoint = __webpack_require__(16);
76947688

7695-
var getErrorFromResponse = function getErrorFromResponse(response) {
7696-
return new Promise(function (resolve) {
7697-
var result = '';
7698-
response.on('data', function (data) {
7699-
result += data.toString('utf8');
7700-
});
7701-
response.on('end', function () {
7702-
resolve(result);
7703-
});
7704-
});
7705-
};
7706-
77077689
var sendFile = function sendFile(_ref) {
77087690
var generateUploadUrl = _ref.generateUploadUrl,
77097691
publishFile = _ref.publishFile,
@@ -7714,7 +7696,7 @@ var sendFile = function sendFile(_ref) {
77147696
networking = _ref$modules.networking;
77157697
return function () {
77167698
var _ref3 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(_ref2) {
7717-
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;
7699+
var channel, input, message, cipherKey, meta, ttl, storeInHistory, file, _yield$generateUpload, _yield$generateUpload2, url, formFields, _yield$generateUpload3, id, name, formFieldsWithMimeType, result, retries, wasSuccessful;
77187700

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

78727854
case 71:
7873-
_context.next = 80;
7855+
_context.next = 76;
78747856
break;
78757857

78767858
case 73:
78777859
_context.prev = 73;
78787860
_context.t16 = _context["catch"](21);
7879-
_context.next = 77;
7880-
return getErrorFromResponse(_context.t16.response);
7861+
throw new _endpoint.PubNubError('Upload to bucket failed', _context.t16);
78817862

7882-
case 77:
7883-
errorBody = _context.sent;
7884-
reason = /<Message>(.*)<\/Message>/gi.exec(errorBody);
7885-
throw new _endpoint.PubNubError(reason ? "Upload to bucket failed: ".concat(reason[1]) : 'Upload to bucket failed.', _context.t16);
7886-
7887-
case 80:
7863+
case 76:
78887864
if (!(result.status !== 204)) {
7889-
_context.next = 82;
7865+
_context.next = 78;
78907866
break;
78917867
}
78927868

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

7895-
case 82:
7871+
case 78:
78967872
retries = 5;
78977873
wasSuccessful = false;
7898-
publishResult = {
7899-
timetoken: '0'
7900-
};
79017874

7902-
case 85:
7875+
case 80:
79037876
if (!(!wasSuccessful && retries > 0)) {
7904-
_context.next = 98;
7877+
_context.next = 92;
79057878
break;
79067879
}
79077880

7908-
_context.prev = 86;
7909-
_context.next = 89;
7881+
_context.prev = 81;
7882+
_context.next = 84;
79107883
return publishFile({
79117884
channel: channel,
79127885
message: message,
@@ -7917,24 +7890,23 @@ var sendFile = function sendFile(_ref) {
79177890
ttl: ttl
79187891
});
79197892

7920-
case 89:
7921-
publishResult = _context.sent;
7893+
case 84:
79227894
wasSuccessful = true;
7923-
_context.next = 96;
7895+
_context.next = 90;
79247896
break;
79257897

7926-
case 93:
7927-
_context.prev = 93;
7928-
_context.t17 = _context["catch"](86);
7898+
case 87:
7899+
_context.prev = 87;
7900+
_context.t17 = _context["catch"](81);
79297901
retries -= 1;
79307902

7931-
case 96:
7932-
_context.next = 85;
7903+
case 90:
7904+
_context.next = 80;
79337905
break;
79347906

7935-
case 98:
7907+
case 92:
79367908
if (wasSuccessful) {
7937-
_context.next = 102;
7909+
_context.next = 96;
79387910
break;
79397911
}
79407912

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

7947-
case 102:
7919+
case 96:
79487920
return _context.abrupt("return", {
7949-
timetoken: publishResult.timetoken,
79507921
id: id,
79517922
name: name
79527923
});
79537924

7954-
case 103:
7925+
case 97:
79557926
case "end":
79567927
return _context.stop();
79577928
}
79587929
}
7959-
}, _callee, null, [[21, 73], [86, 93]]);
7930+
}, _callee, null, [[21, 73], [81, 87]]);
79607931
}));
79617932

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

87558726
var _endpoint = __webpack_require__(16);
87568727

8757-
var _default = function _default(modules, _ref) {
8758-
var channel = _ref.channel,
8759-
id = _ref.id,
8760-
name = _ref.name;
8761-
var config = modules.config;
8728+
var _default = function _default(_ref, _ref2) {
8729+
var config = _ref.config;
8730+
var channel = _ref2.channel,
8731+
id = _ref2.id,
8732+
name = _ref2.name;
87628733

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

8775-
var url = "/v1/files/".concat(config.subscribeKey, "/channels/").concat(channel, "/files/").concat(id, "/").concat(name);
8776-
var params = {};
8777-
params.uuid = config.getUUID();
8778-
params.pnsdk = (0, _endpoint.generatePNSDK)(config);
8779-
8780-
if (config.getAuthKey()) {
8781-
params.auth = config.getAuthKey();
8782-
}
8783-
8784-
if (config.secretKey) {
8785-
(0, _endpoint.signRequest)(modules, url, params, {}, {
8786-
getOperation: function getOperation() {
8787-
return 'PubNubGetFileUrlOperation';
8788-
}
8789-
});
8790-
}
8791-
8792-
var queryParams = Object.keys(params).map(function (key) {
8793-
return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(params[key]));
8794-
}).join('&');
8795-
8796-
if (queryParams !== '') {
8797-
return "https://".concat(config.origin).concat(url, "?").concat(queryParams);
8798-
}
8799-
8800-
return "https://".concat(config.origin).concat(url);
8746+
return "https://".concat(config.origin, "/v1/files/").concat(config.subscribeKey, "/channels/").concat(channel, "/files/").concat(id, "/").concat(name);
88018747
};
88028748

88038749
exports["default"] = _default;
@@ -8860,11 +8806,15 @@ var endpoint = {
88608806
forceBuffered: function forceBuffered() {
88618807
return true;
88628808
},
8809+
getAuthToken: function getAuthToken(_ref3) {
8810+
var tokenManager = _ref3.tokenManager;
8811+
return tokenManager.getToken('fileUpload');
8812+
},
88638813
prepareParams: function prepareParams() {
88648814
return {};
88658815
},
88668816
handleResponse: function () {
8867-
var _handleResponse = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(_ref3, res, params) {
8817+
var _handleResponse = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee(_ref4, res, params) {
88688818
var _res$response$name;
88698819

88708820
var PubNubFile, config, cryptography, body, _params$cipherKey;
@@ -8873,7 +8823,7 @@ var endpoint = {
88738823
while (1) {
88748824
switch (_context.prev = _context.next) {
88758825
case 0:
8876-
PubNubFile = _ref3.PubNubFile, config = _ref3.config, cryptography = _ref3.cryptography;
8826+
PubNubFile = _ref4.PubNubFile, config = _ref4.config, cryptography = _ref4.cryptography;
88778827
body = res.response.body;
88788828

88798829
if (!(PubNubFile.supportsEncryptFile && config.cipherKey)) {

dist/titanium/pubnub.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)