Skip to content

Commit

Permalink
Added ping & types
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamish-taylor committed Apr 17, 2024
1 parent f2be885 commit eb2bf8d
Show file tree
Hide file tree
Showing 6 changed files with 490 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Unused normalize.css file
-->
## [3.1.1]

### Added
- Moved the typescript types into the main raygun4js repo

## [3.0.1]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raygun4js",
"version": "2.28.0",
"version": "3.1.1",
"homepage": "http://raygun.com",
"authors": [
"Mindscape <[email protected]>"
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"name": "raygun4js",
"main": "dist/raygun.umd.js",
"files": [
"dist/*"
"dist/*",
"types/*"
],
"title": "Raygun4js",
"description": "Raygun.com plugin for JavaScript",
"version": "3.0.1",
"version": "3.1.1",
"homepage": "https://github.com/MindscapeHQ/raygun4js",
"author": {
"name": "MindscapeHQ",
Expand All @@ -16,6 +17,7 @@
"type": "git",
"url": "https://github.com/MindscapeHQ/raygun4js.git"
},
"types": "./types/index.d.ts",
"bugs": "https://github.com/MindscapeHQ/raygun4js/issues",
"license": "SEE LICENSE IN https://github.com/MindscapeHQ/raygun4js/blob/master/LICENSE",
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion raygun4js.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>raygun4js</id>
<version>2.28.0</version>
<version>3.1.1</version>
<title>Raygun4js</title>
<authors>Raygun Limited</authors>
<owners>Raygun Limited</owners>
Expand Down
43 changes: 42 additions & 1 deletion src/raygun.loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
options,
attach,
enablePulse,
sendPing = true,
noConflict,
captureUnhandledRejections;

window.Raygun.failedPings = 0;
var snippetOnErrorSignature = ['function (b,c,d,f,g){', '||(g=new Error(b)),a[e].q=a[e].q||[]'];

errorQueue = window[window['RaygunObject']].q;
Expand Down Expand Up @@ -51,6 +53,9 @@

if (key) {
switch (key) {
case 'sendPing':
sendPing = value;
break;
// React Native only
case 'boot':
onLoadHandler();
Expand All @@ -69,11 +74,14 @@
case 'attach':
case 'enableCrashReporting':
attach = value;
window.Raygun.crashReportingEnabled = true;
hasLoaded = true;
break;
case 'enableRealUserMonitoring':
case 'enableRUM':
case 'enablePulse':
enablePulse = value;
window.Raygun.realUserMonitoringEnabled = true;
hasLoaded = true;
break;
case 'detach':
Expand Down Expand Up @@ -218,6 +226,36 @@
}
};

function ping() {
if(window.Raygun.failedPings > 10) {
clearInterval(window.Raygun.pingIntervalId);
}

var apiKey = window.Raygun.Options._raygunApiKey;
var crashReportingEnabled = window.Raygun.crashReportingEnabled || false;
var realUserMonitoringEnabled = window.Raygun.realUserMonitoringEnabled || false;

var url = "https://api.raygun.io/ping?apiKey=" + apiKey;
var data = {
crashReportingEnabled: crashReportingEnabled,
realUserMonitoringEnabled: realUserMonitoringEnabled,
providerName: "raygun4js",
providerVersion: '{{VERSION}}'
};

fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.catch(function() {
window.Raygun.failedPings++;
});
}


var installGlobalExecutor = function() {
window[window['RaygunObject']] = function() {
return executor(arguments);
Expand All @@ -232,7 +270,7 @@
if (noConflict) {
rg = Raygun.noConflict();
}

if (apiKey) {
if (!options) {
options = {};
Expand Down Expand Up @@ -275,6 +313,9 @@
installGlobalExecutor();
}

if(sendPing) {
window.Raygun.pingIntervalId = setInterval(ping,1000);
}
window[window['RaygunObject']].q = errorQueue;
};

Expand Down
Loading

0 comments on commit eb2bf8d

Please sign in to comment.