Skip to content

Commit

Permalink
Removed token parameter which prevented the function from respecting …
Browse files Browse the repository at this point in the history
…custom parameter values (#792)

* Removed token parameter which prevented the function from respecting custom parameter values

* Fixed message type and name and added page number to return latest message

* Fixed issue with Roblox's Realtime API and added new signalr dependency

* Removed the console.log statement

* Added the @microsoft/signalr dependency
  • Loading branch information
AEW745 authored May 18, 2024
1 parent 17f4507 commit d626e6f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 33 deletions.
66 changes: 41 additions & 25 deletions lib/client/onNotification.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Dependencies
const SignalR = require('signalr-client').client
const signalR = require('@microsoft/signalr')
const events = require('events')

// Includes
Expand Down Expand Up @@ -36,34 +36,50 @@ exports.func = function (args) {
args.jar = { session: args.jar }
}
const session = getSession({ jar: args.jar })
const client = new SignalR('wss://realtime.roblox.com/notifications', ['usernotificationhub'], 3, true) // wss for https
client.headers.Cookie = '.ROBLOSECURITY=' + session + ';'
client.on('usernotificationhub', 'notification', function (name, message) {
notifications.emit('data', name, JSON.parse(message))
})
notifications.on('close', client.end)
client.serviceHandlers.connectFailed = function (err) {
notifications.emit('error', new Error('Connection failed: ' + err.message))
if (retries !== -1) {
if (retries > max) {
notifications.emit('close', new Error('Max retries reached'))
} else {
setTimeout(connect, 5000, retries + 1)
let userNotificationConnection = null;

Check failure on line 39 in lib/client/onNotification.js

View workflow job for this annotation

GitHub Actions / test

Extra semicolon

userNotificationConnection = new signalR.HubConnectionBuilder()
.withUrl('https://realtime-signalr.roblox.com/userhub', {
transport: signalR.HttpTransportType.WebSockets,
skipNegotiation: true,
headers: {
Cookie: '.ROBLOSECURITY=' + session + ';'
}
})
.build();

Check failure on line 49 in lib/client/onNotification.js

View workflow job for this annotation

GitHub Actions / test

Extra semicolon

userNotificationConnection.on('notification', function(name, message) {

Check failure on line 51 in lib/client/onNotification.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 4 spaces but found 6

Check failure on line 51 in lib/client/onNotification.js

View workflow job for this annotation

GitHub Actions / test

Missing space before function parentheses
notifications.emit('data', name, JSON.parse(message))

Check failure on line 52 in lib/client/onNotification.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 6 spaces but found 8
})

Check failure on line 53 in lib/client/onNotification.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 4 spaces but found 6

notifications.on('close', userNotificationConnection.stop)

Check failure on line 55 in lib/client/onNotification.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 4 spaces but found 6

userNotificationConnection.disconnected = function (err) {

Check failure on line 57 in lib/client/onNotification.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 4 spaces but found 6
notifications.emit('error', new Error('Connection failed: ' + err.message))

Check failure on line 58 in lib/client/onNotification.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 6 spaces but found 8
if (retries !== -1) {

Check failure on line 59 in lib/client/onNotification.js

View workflow job for this annotation

GitHub Actions / test

Expected indentation of 6 spaces but found 8
if (retries > max) {
notifications.emit('close', new Error('Max retries reached'))
} else {
setTimeout(connect, 5000, retries + 1)
}
}
}
}
client.serviceHandlers.onerror = function (err) {
notifications.emit('error', err)
}
client.serviceHandlers.connected = function (connection) {
notifications.emit('connect', connection)
}
client.serviceHandlers.reconnecting = function () {
setTimeout(connect, 5000, 0)

userNotificationConnection.error = function (err) {
notifications.emit('error', err)
}

userNotificationConnection.connected = function(connection) {
notifications.emit('connect', connection)
}

userNotificationConnection.reconnecting = function () {
setTimeout(connect, 5000, 0)
notifications.emit('error', new Error('Lost connection, reconnecting'))
return true // Abort reconnection
}
client.start()
}

userNotificationConnection.start()
}
connect(-1)
return notifications
Expand Down
4 changes: 2 additions & 2 deletions lib/privatemessages/getMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ exports.optional = ['pageNumber', 'pageSize', 'messageTab', 'jar']
**/

// Define
function getMessages (jar, token, pageNumber, pageSize, messageTab) {
function getMessages (jar, pageNumber, pageSize, messageTab) {
return new Promise((resolve, reject) => {
const httpOpt = {
url: `//privatemessages.roblox.com/v1/messages?pageNumber=${pageNumber}&pageSize=${pageSize}&messageTab=${messageTab}`,
options: {
method: 'GET',
jar,
jar: jar,
resolveWithFullResponse: true
}
}
Expand Down
11 changes: 6 additions & 5 deletions lib/privatemessages/onMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@ exports.func = function (args) {
const onMessage = new events.EventEmitter()
let waitingForRequest = false
let latest
getMessages({ jar, messageTab: 'Inbox', pageNumber: 0 })
getMessages({ jar: jar, messageTab: 'Inbox', pageNumber: 0, pageSize: 1 })
.then(function (initial) {
latest = initial.collection[0] ? initial.collection[0].id : 0
const notifications = onNotification({ jar })
const notifications = onNotification({ jar: jar })
notifications.on('data', function (name, message) {
if (name === 'NotificationStream' && message.Type === 'NewNotification') {
if (name === 'MessageNotification' && message.Type === 'Created') {
if (waitingForRequest) {
waitingForRequest = false
} else {
getMessages({
jar,
jar: jar,
messageTab: 'Inbox',
pageNumber: 0
pageNumber: 0,
pageSize: 1
})
.then(function (inbox) {
const messages = inbox.collection
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"clans"
],
"dependencies": {
"@microsoft/signalr": "^8.0.0",
"chalk": "^4.0.0",
"cheerio": "^1.0.0-rc.10",
"entities": "^4.3.0",
Expand All @@ -41,7 +42,6 @@
"homepage": "https://github.com/noblox/noblox.js",
"devDependencies": {
"@auto-it/conventional-commits": "^10.30.0",
"JSONStream": "^1.3.1",
"auto": "^10.30.0",
"better-docs": "2.7.2",
"dotenv": "16.0.3",
Expand All @@ -54,6 +54,7 @@
"jest": "^29.5.0",
"jest-extended": "^3.2.4",
"jsdoc": "3.6.10",
"JSONStream": "^1.3.1",
"progress": "^2.0.0",
"standard": "^17.0.0"
},
Expand Down

0 comments on commit d626e6f

Please sign in to comment.