Module: Hallon::Observable::Session

Included in:
Session
Defined in:
lib/hallon/observable/session.rb

Overview

Callbacks related to the Session object.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(other) ⇒ Object

Includes Hallon::Observable for you.


6
7
8
# File 'lib/hallon/observable/session.rb', line 6

def self.extended(other)
  other.send(:include, Hallon::Observable)
end

Instance Method Details

#connection_error_callback(pointer, error) {|error| ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:connection_error) do |error|
  puts "Oh noes: " + Hallon::Error.explain(error)
end

Yields:

  • (error)

Yield Parameters:

  • error (Symbol)

See Also:


61
62
63
# File 'lib/hallon/observable/session.rb', line 61

def connection_error_callback(pointer, error)
  trigger(pointer, :connection_error, error)
end

#connectionstate_updated_callback(pointer) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:connectionstate_updated) do
  puts "Yay! Connection state changed… hooray… wee… no?"
end

Yields:


239
240
241
# File 'lib/hallon/observable/session.rb', line 239

def connectionstate_updated_callback(pointer)
  trigger(pointer, :connectionstate_updated)
end

#credentials_blob_updated_callback(pointer, credentials) {|credentials| ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:credentials_blob_updated) do |credentials|
  File.open('.spotify-credentials', 'w') { |io| io.write(credentials) }
end

Yields:

  • (credentials)

Yield Parameters:

  • credentials (String)

229
230
231
# File 'lib/hallon/observable/session.rb', line 229

def credentials_blob_updated_callback(pointer, credentials)
  trigger(pointer, :credentials_blob_updated, credentials)
end

#end_of_track_callback(pointer) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:end_of_track) do
  puts "all your base are belong to us"
end

Yields:

  • []


131
132
133
# File 'lib/hallon/observable/session.rb', line 131

def end_of_track_callback(pointer)
  trigger(pointer, :end_of_track)
end

#get_audio_buffer_stats_callback(pointer, stats) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:get_audio_buffer_stats) do
  puts "que?"
end

Yields:

  • []

Yield Returns:

  • an integer pair, [samples, dropouts]


162
163
164
165
166
# File 'lib/hallon/observable/session.rb', line 162

def get_audio_buffer_stats_callback(pointer, stats)
  samples, dropouts = trigger(pointer, :get_audio_buffer_stats)
  stats[:samples]  = samples.to_i
  stats[:stutter] = dropouts.to_i
end

#initialize_callbacksSpotify::SessionCallbacks (protected)

Returns:

  • (Spotify::SessionCallbacks)

13
14
15
16
17
18
19
# File 'lib/hallon/observable/session.rb', line 13

def initialize_callbacks
  struct = Spotify::SessionCallbacks.new
  struct.members.each do |member|
    struct[member] = callback_for(member)
  end
  struct
end

#log_message_callback(pointer, message) {|message| ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:log_message) do |message|
  puts "for great justice: #{message}"
end

Yields:

  • (message)

Yield Parameters:

  • message (String)

196
197
198
# File 'lib/hallon/observable/session.rb', line 196

def log_message_callback(pointer, message)
  trigger(pointer, :log_message, message)
end

#logged_in_callback(pointer, error) {|error| ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:logged_in) do |error|
  puts "Logged in: " + Hallon::Error.explain(error)
end

Yields:

  • (error)

    logged_in

Yield Parameters:

  • error (Symbol)

See Also:


29
30
31
# File 'lib/hallon/observable/session.rb', line 29

def logged_in_callback(pointer, error)
  trigger(pointer, :logged_in, error)
end

#logged_out_callback(pointer) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:logged_out) do
  puts "AHHH!"
end

Yields:

  • []


39
40
41
# File 'lib/hallon/observable/session.rb', line 39

def logged_out_callback(pointer)
  trigger(pointer, :logged_out)
end

#message_to_user_callback(pointer, message) {|message| ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:message_to_user) do |message|
  puts "OH HAI: #{message}"
end

Yields:

  • (message)

Yield Parameters:

  • message (String)

72
73
74
# File 'lib/hallon/observable/session.rb', line 72

def message_to_user_callback(pointer, message)
  trigger(pointer, :message_to_user, message)
end

#metadata_updated_callback(pointer) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:metadata_updated) do
  puts "wut wut"
end

Yields:

  • []


49
50
51
# File 'lib/hallon/observable/session.rb', line 49

def (pointer)
  trigger(pointer, :metadata_updated)
end

#music_delivery_callback(pointer, format_struct, frames, num_frames) {|format, frames| ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:music_delivery) do |format, frames|
  puts ""
end

Yields:

  • (format, frames)

Yield Parameters:

  • format (Hash)

    (contains :type, :rate, :channels)

  • frames (Enumerator<[Integer...]>)

    (each frame is an array containing format[:channels] integers of format[:type])


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/hallon/observable/session.rb', line 94

def music_delivery_callback(pointer, format_struct, frames, num_frames)
  format = {
    rate: format_struct[:sample_rate],
    channels: format_struct[:channels],
    type: format_struct[:sample_type]
  }

  # read the frames of the given type
  frames = unless num_frames.zero?
    frames.public_send("read_array_of_#{format[:type]}", num_frames * format[:channels])
  else
    [] # when seeking, for example, num_frames will be zero and frames will be nil
  end

  # pass the frames to the callback, allowing it to do whatever
  consumed_frames = trigger(pointer, :music_delivery, format, frames.each_slice(format[:channels]))

  # finally return how many frames the callback reportedly consumed
  consumed_frames.to_i # very important to return something good here!
end

#notify_main_thread_callback(pointer) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:notify_main_thread) do
  puts "main thread turn on"
end

Yields:

  • []


82
83
84
# File 'lib/hallon/observable/session.rb', line 82

def notify_main_thread_callback(pointer)
  trigger(pointer, :notify_main_thread)
end

#offline_error_callback(pointer, error) {|error| ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:offline_error) do |error|
  puts "FAIL: " + Hallon::Error.explain(error)
end

Yields:

  • (error)

Yield Parameters:

  • error (Symbol)

217
218
219
# File 'lib/hallon/observable/session.rb', line 217

def offline_error_callback(pointer, error)
  trigger(pointer, :offline_error, error)
end

#offline_status_updated_callback(pointer) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:offline_status_updated) do |session|
  puts "All systems: #{session.status}"
end

Yields:

  • []


206
207
208
# File 'lib/hallon/observable/session.rb', line 206

def offline_status_updated_callback(pointer)
  trigger(pointer, :offline_status_updated)
end

#play_token_lost_callback(pointer) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:play_token_lost) do
  puts "another user set us up the bomb!"
end

Yields:

  • []


121
122
123
# File 'lib/hallon/observable/session.rb', line 121

def play_token_lost_callback(pointer)
  trigger(pointer, :play_token_lost)
end

#private_session_mode_changed_callback(pointer, enabled) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:private_session_mode_changed) do |enabled|
  if enabled
    puts "Private session enabled!"
  else
    puts "Private session disabled!"
  end
end

Yields:


263
264
265
# File 'lib/hallon/observable/session.rb', line 263

def private_session_mode_changed_callback(pointer, enabled)
  trigger(pointer, :private_session_mode_changed, enabled)
end

#scrobble_error_callback(pointer, error) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:scrobble_error) do |error|
  Hallon::Error.maybe_raise(error)
end

Yields:


249
250
251
# File 'lib/hallon/observable/session.rb', line 249

def scrobble_error_callback(pointer, error)
  trigger(pointer, :scrobble_error, error)
end

#start_playback_callback(pointer) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:start_playback) do
  puts "dum dum tiss"
end

Yields:

  • []


141
142
143
# File 'lib/hallon/observable/session.rb', line 141

def start_playback_callback(pointer)
  trigger(pointer, :start_playback)
end

#stop_playback_callback(pointer) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:stop_playback) do
  puts "dum dum tiss"
end

Yields:

  • []


151
152
153
# File 'lib/hallon/observable/session.rb', line 151

def stop_playback_callback(pointer)
  trigger(pointer, :stop_playback)
end

#streaming_error_callback(pointer, error) {|error| ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:streaming_error) do |error|
  puts "boo: " + Hallon::Error.explain(error)
end

Yields:

  • (error)

Yield Parameters:

  • error (Symbol)

175
176
177
# File 'lib/hallon/observable/session.rb', line 175

def streaming_error_callback(pointer, error)
  trigger(pointer, :streaming_error, error)
end

#userinfo_updated_callback(pointer) { ... } ⇒ Object (protected)

Examples:

listening to this event

session.on(:userinfo_updated) do
  puts "who am I?!"
end

Yields:

  • []


185
186
187
# File 'lib/hallon/observable/session.rb', line 185

def userinfo_updated_callback(pointer)
  trigger(pointer, :userinfo_updated)
end