azoy / swordrpc Goto Github PK
View Code? Open in Web Editor NEWA Discord Rich Presence Library for Swift
License: MIT License
A Discord Rich Presence Library for Swift
License: MIT License
Currently one can only connect the socket. This is sufficient for programs that send RPC info about themselves.
However, there also exists the case where a program ∆ may provide RPC info for another program Ω. This may be done for a variety of reasons, including the original program not supporting Discord RPC.
∆ may run under a daemon-like paradigm, wherein it connects the RPC socket when Ω is run and disconnects it when Ω finishes/is killed. In this case, it is useful to have a disconnect method for the SwordRPC
class.
Alternatively, SwordRPC
's socket
could be made public and disconnected directly by ∆.
Hey there!
I recently started using SwordRPC for a project but keep getting the following error:
[SwordRPC] Error creating URL scheme: -54 [SwordRPC] Discord not detected error: Optional({ NSAppleScriptErrorBriefMessage = "A unknown token can\U2019t go here."; NSAppleScriptErrorMessage = "A unknown token can\U2019t go here."; NSAppleScriptErrorNumber = "-2740"; NSAppleScriptErrorRange = "NSRange: {0, 1}"; })
This is my ViewController.swift:
`
//
// ViewController.swift
// iTunes4Discord
//
// Created by Conor on 06/07/2018.
// Copyright © 2018 Conor Byrne. All rights reserved.
//
import Cocoa
import SwordRPC
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
let rpc = SwordRPC(appId: "464708073248915457")
rpc.onConnect { rpc in
var presence = RichPresence()
presence.details = "null"
presence.state = "In a Group"
presence.timestamps.start = Date()
presence.timestamps.end = Date() + 600 // 600s = 10m
presence.assets.largeImage = "itunes"
presence.assets.largeText = "iTunes v12.7.5.9"
presence.assets.smallImage = ""
presence.assets.smallText = ""
presence.party.max = 5
presence.party.size = 3
presence.party.id = "partyId"
presence.secrets.match = "matchSecret"
presence.secrets.join = "joinSecret"
rpc.setPresence(presence)
}
rpc.onDisconnect { rpc, code, msg in
print("It appears we have disconnected from Discord")
}
rpc.onError { rpc, code, msg in
print("It appears we have discovered an error!")
}
rpc.onJoinGame { rpc, secret in
print("We have found us a join game secret!")
}
rpc.onSpectateGame { rpc, secret in
print("Our user wants to spectate!")
}
rpc.onJoinRequest { rpc, request, secret in
print("Some user wants to play with us!")
rpc.reply(to: request, with: .no)
}
rpc.connect()
/*
let myAppleScript = "..."
var error: NSDictionary?
if let scriptObject = NSAppleScript(source: myAppleScript) {
if let output: NSAppleEventDescriptor = scriptObject.executeAndReturnError(
&error) {
print(output.stringValue)
} else if (error != nil) {
print("error: \(error)")
}
}
*/
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
extension ViewController: SwordRPCDelegate {
func swordRPCDidConnect(
_ rpc: SwordRPC
) {}
func swordRPCDidDisconnect(
_ rpc: SwordRPC,
code: Int?,
message msg: String?
) {}
func swordRPCDidReceiveError(
_ rpc: SwordRPC,
code: Int,
message msg: String
) {}
func swordRPCDidJoinGame(
_ rpc: SwordRPC,
secret: String
) {}
func swordRPCDidSpectateGame(
_ rpc: SwordRPC,
secret: String
) {}
func swordRPCDidReceiveJoinRequest(
_ rpc: SwordRPC,
request: JoinRequest,
secret: String
) {}
}
`
Running on macOS 10.13 with Xcode 9.4.1, also tried on Xcode 10 beta 3
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.