Giter Site home page Giter Site logo

swordrpc's People

Contributors

azoy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

swordrpc's Issues

Add a disconnect method

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 ∆.

[SwordRPC] Discord not detected

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.