Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 132 lines (96 sloc) 2.814 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
require 'pp'

class SiriPluginManager
attr_accessor :plugins

def initialize(pluginClasses=[])
self.plugins = []

pluginClasses.each { |pluginClass|
plugin = pluginClass.new
plugin.plugin_manager = self
self.plugins << plugin
}

@blockNextObjectsFromServer = 0
@blockNextObjectsFromClient = 0
@blockRestOfSessionFromServer = false
end

def object_from_guzzoni(object, connection)
if(@blockRestOfSessionFromServer)
if(connection.lastRefId == object["refId"])
puts "[Info - Dropping Object from Guzzoni] #{object["class"]}"
return nil
else
@blockRestOfSessionFromServer = false
end
end

if(@blockNextObjectsFromServer > 0)
puts "[Info - Dropping Object from Guzzoni] #{object["class"]}"
@blockNextObjectsFromServer -= 1
return nil
end

plugins.each { |plugin|
object = plugin.object_from_guzzoni(object, connection)
}

object
end

def object_from_client(object, connection)
if(@blockNextObjectsFromClient > 0)
puts "[Info - Dropping Object from iPhone] #{object["class"]}"
@blockNextObjectsFromClient -= 1
return nil
end

##Often this indicates a bug in OUR code. So let's not send it to Apple. :-)
if(object["class"] == "CommandIgnored")
pp object
return nil
end

plugins.each { |plugin|
object = plugin.object_from_client(object, connection)
}

# This is used for commands from phone that should not be sent back to Apple,
# and will be interpreted by plugins directly
if(object && object["properties"] && object['properties']['proxyOnly'])
puts "[Info - Not forwarding Object from iPhone because proxyOnly flag was set] #{object["class"]}"
return nil
end

object
end

def unknown_command(object, connection, command)
puts "[UnknownCommand] #{command}"

plugins.each { |plugin|
object = plugin.unknown_command(object, connection, command)
}

object
end

def speech_recognized(object, connection, phrase)
puts "[Recognized Speech] #{phrase}"

plugins.each { |plugin|
object = plugin.speech_recognized(object, connection, phrase)
}

object
end


def block_next_objects_from_server(count=1)
@blockNextObjectsFromServer += count
end

def block_next_objects_from_client(count=1)
@blockNextObjectsFromClient += count
end

#Blocks everything from server until a new refId is seen
def block_rest_of_session_from_server
@blockRestOfSessionFromServer = true
end
end

class SiriPlugin
attr_accessor :plugin_manager

def object_from_guzzoni(object, connection)

object
end


#Don't forget to return the object!
def object_from_client(object, connection)

object
end


def unknown_command(object, connection, command)

object
end

def speech_recognized(object, connection, phrase)

object
end

end
Something went wrong with that request. Please try again.