Skip to content

Commit

Permalink
fix: fixing ipc transport
Browse files Browse the repository at this point in the history
revert: node-fetch to v2
  • Loading branch information
brokenedtzjs committed Dec 6, 2024
1 parent 1043529 commit acbf0b7
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 61 deletions.
5 changes: 4 additions & 1 deletion packages/discord-rpc/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ coverage
junit.xml

# Generated files
typings/index.d.mts
typings/index.d.mts

# Ignored Tests
test-node.js
60 changes: 51 additions & 9 deletions packages/discord-rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
<a href="https://nodejs.org/" target="_blank" rel="noopener noreferrer"><img alt="node-current" src="https://img.shields.io/node/v/distube"></a>
<a href="https://www.npmjs.com/package/dc-rpc" target="_blank" rel="noopener noreferrer"><img alt="npm" src="https://img.shields.io/npm/dt/dc-rpc"></a>
<a href="https://www.npmjs.com/package/dc-rpc" target="_blank" rel="noopener noreferrer"><img alt="npm latest" src="https://img.shields.io/npm/v/dc-rpc/latest?color=blue&label=dc-rpc%40latest&logo=npm"></a>
<a href="https://github.com/skick1234/CyraTeam/discord-rpc" target="_blank" rel="noopener noreferrer"><img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/CyraTeam/discord-rpc"></a>
<a href="https://github.com/skick1234/SITCommunity/discord-rpc" target="_blank" rel="noopener noreferrer"><img alt="GitHub Repo stars" src="https://img.shields.io/github/stars/SITCommunity/discord-rpc"></a>
<a href="https://discord.gg/qpT2AeYZRN" target="_blank" rel="noopener noreferrer"><img alt="Discord" src="https://img.shields.io/discord/984857299858382908?label=EterNomm&logo=discord"></a>
<a href="https://discord.cyrateam.xyz" target="_blank" rel="noopener noreferrer"><img alt="Discord" src="https://img.shields.io/discord/984857299858382908?label=SITCommunity&logo=discord"></a>
<a href="https://github.com/CyraTeam/discord-rpc" target="_blank" rel="noopener noreferrer"><img alt="Visitor" src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%2FCyraTeam%2Fdiscord-rpc&countColor=%2337d67a&style=flat"></a>
<a href="https://github.com/CyraTeam/discord-rpc/issues" target="_blank" rel="noopener noreferrer"><img alt="Issues" src="https://img.shields.io/github/issues/CyraTeam/discord-rpc"></a>
<a href="https://github.com/CyraTeam/dc-rpc" target="_blank" rel="noopener noreferrer"><img alt="Commit" src="https://img.shields.io/github/commit-activity/y/CyraTeam/discord-rpc?label=Commit%20Activity&logo=github"></a>
<a href="https://github.com/SITCommunity/discord-rpc" target="_blank" rel="noopener noreferrer"><img alt="Visitor" src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%2FCyraTeam%2Fdiscord-rpc&countColor=%2337d67a&style=flat"></a>
<a href="https://github.com/SITCommunity/discord-rpc/issues" target="_blank" rel="noopener noreferrer"><img alt="Issues" src="https://img.shields.io/github/issues/SITCommunity/discord-rpc"></a>
<a href="https://github.com/SITCommunity/discord-rpc" target="_blank" rel="noopener noreferrer"><img alt="Commit" src="https://img.shields.io/github/commit-activity/y/SITCommunity/discord-rpc?label=Commit%20Activity&logo=github"></a>
</p>
</div>

# Discord RPC
- **[Discord-RPC](https://www.npmjs.com/package/dc-rpc) is a powerful library developed by CyraTeam that enables developers to seamlessly integrate Rich Presence functionality into Discord applications or from Client ID**
- **[Discord-RPC] is a powerful library developed by SITCommunity that enables developers to seamlessly integrate Rich Presence functionality into Discord applications or from Client ID**

## Install
- NPM
Expand All @@ -26,11 +26,48 @@ npm i dc-rpc

## Quick example
```js
// Importing Discord-RPC
const { RpcClient } = require('dc-rpc');

const rpc = new RpcClient({ transport: '...' }); // transport: ipc or websocket
// Create an instance of Discord-RPC
const client = new RpcClient({ transport: 'ipc' }); // currently websocket not supported

coming soon;
// ================================================================

// Your Client ID
const Id = 'Client ID';

// Login To Discord RPC
await client.login({ clientId: Id });

// ================================================================

// Function When Client Is Ready
client.on('ready', () => {
console.log('Logged in as', client.application); // Console: Logged in as brokenedtz
console.log('Authed for user', client.user);
/** Console:
* Authed for user {
* id: 'user_id',
* username: 'brokenedtz',
* discriminator: '0',
* global_name: 'リオ',
* avatar: 'avatar_id',
* avatar_decoration_data: null,
* bot: false,
* flags: flag_id,
* premium_type: 0
* }
*/

// Set Activity (Example)
client.setActivity({ state: 'it work!!!', details: 'Testing RPC', startTimestamp: Date.now() });
});

// ================================================================

// Destroying Or Disconnecting From RPC
client.destroy();
```

Join our Discord server [here](https://discord.gg/qpT2AeYZRN)
Expand All @@ -42,5 +79,10 @@ This Project under MIT License
© 2019 - 2024 SITCommunity. All Rights Reserved
```

## Original Repository
This Repository Is Forked from original [Discord-RPC](https://github.com/Senophyx/Discord-RPC) by [Senophyx](https://github.com/Senophyx).
## Credits
- Original: [Senophyx]
- Maintainer: [brokenedtz]

[Discord-RPC]: https://www.npmjs.com/package/dc-rpc
[Senophyx]: https://github.com/Senophyx
[brokenedtz]: https://github.com/brokenedtzjs
6 changes: 3 additions & 3 deletions packages/discord-rpc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dc-rpc",
"version": "1.5.8",
"version": "1.5.7",
"description": "Discord-RPC is a powerful library developed by SITCommunity that enables developers to seamlessly integrate Rich Presence functionality into Discord applications or from Client ID",
"contributors": [
"BrokenEdtz <brokenedtz@cyrateam.xyz>"
Expand All @@ -25,7 +25,7 @@
"scripts": {
"test": "pnpm run test:typescript && pnpm run test:jest",
"test:typescript": "tsc --noEmit && tsd",
"test:jest": "jest --coverage --passWithNoTests",
"test:jest": "jest --coverage",
"update": "pnpm --recursive update --interactive",
"update:latest": "pnpm --recursive update --interactive --latest",
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml"
Expand Down Expand Up @@ -57,7 +57,7 @@
},
"packageManager": "pnpm@9.8.0",
"dependencies": {
"node-fetch": "^3.3.2",
"node-fetch": "^2.7.0",
"tslib": "^2.7.0",
"ws": "^8.14.2"
},
Expand Down
70 changes: 28 additions & 42 deletions packages/discord-rpc/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/discord-rpc/src/functions/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class RpcClient extends EventEmitter {
},
}));
};

setVoiceSettings(args) {
return this.request(RPCCommands.SET_VOICE_SETTINGS, {
automatic_gain_control: args.automaticGainControl,
Expand Down
12 changes: 7 additions & 5 deletions packages/discord-rpc/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@

const util = require('./functions/util');

// Client classes
exports.RpcClient = require('./functions/client');
// Rpc Register & Client classes
module.exports = {
RpcClient: require('./functions/client'),
register(id) {
return util.register(`discord-${id}`);
},
};

// Errors
exports.AfkError = require('./error/errorBase').AfkError;
exports.AfkTypeError = require('./error/errorBase').AfkTypeError;
exports.errorCode = require('./error/errorCode');

// Rpc Register
exports.register(id) = util.register(`discord-${id}`);

// discord-rpc versions
exports.versions = `${require("../package.json").version}`;
36 changes: 36 additions & 0 deletions packages/discord-rpc/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

// Import module
const { RpcClient } = require('dc-rpc');

// Spy on console.log before test
beforeEach(() => {
jest.spyOn(console, 'log').mockImplementation(() => { });
});

// Reset all mock after test
afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
});

// Test code
describe('Discord RPC Tests', () => {
test('Test IPC RPC', async () => {
const Id = '1314548864682037259';
const client = new RpcClient({ transport: 'ipc' });

await client.login({ clientId: Id });

client.on('ready', () => {
console.log('Logged in as', client.application);
console.log('Authed for user', client.user);

client.setActivity({ state: 'it work!!!', details: 'Testing Strivo RPC', startTimestamp: Date.now() });
});

await new Promise(resolve => setTimeout(resolve, 3000));

client.destroy();
})
});

0 comments on commit acbf0b7

Please sign in to comment.