Class: WampClient::Session
- Inherits:
-
Object
- Object
- WampClient::Session
- Includes:
- Check
- Defined in:
- lib/wamp_client/session.rb
Instance Attribute Summary collapse
-
#_defers ⇒ Object
Private attributes.
-
#_goodbye_sent ⇒ Object
Private attributes.
-
#_registrations ⇒ Object
Private attributes.
-
#_requests ⇒ Object
Private attributes.
-
#_subscriptions ⇒ Object
Private attributes.
-
#id ⇒ Object
Returns the value of attribute id.
-
#options ⇒ Object
Returns the value of attribute options.
-
#realm ⇒ Object
Returns the value of attribute realm.
-
#transport ⇒ Object
Returns the value of attribute transport.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#_error_to_hash(msg) ⇒ Object
Converts and error message to a hash.
-
#_generate_id ⇒ Object
Generates an ID according to the specification (Section 5.1.2).
-
#_process_CALL_error(msg) ⇒ Object
Processes an error from a call request.
-
#_process_EVENT(msg) ⇒ Object
Processes and event from the broker.
-
#_process_INVOCATION(msg) ⇒ Object
Processes and event from the broker.
-
#_process_PUBLISH_error(msg) ⇒ Object
Processes an error from a publish request.
-
#_process_PUBLISHED(msg) ⇒ Object
Processes the response to a publish request.
-
#_process_REGISTER_error(msg) ⇒ Object
Processes an error from a request.
-
#_process_REGISTERED(msg) ⇒ Object
Processes the response to a register request.
-
#_process_RESULT(msg) ⇒ Object
Processes the response to a publish request.
-
#_process_SUBSCRIBE_error(msg) ⇒ Object
Processes an error from a request.
-
#_process_SUBSCRIBED(msg) ⇒ Object
Processes the response to a subscribe request.
-
#_process_UNREGISTER_error(msg) ⇒ Object
Processes an error from a request.
-
#_process_UNREGISTERED(msg) ⇒ Object
Processes the response to a unregister request.
-
#_process_UNSUBSCRIBE_error(msg) ⇒ Object
Processes an error from a request.
-
#_process_UNSUBSCRIBED(msg) ⇒ Object
Processes the response to a unsubscribe request.
-
#_receive_message(msg) ⇒ Object
Processes received messages.
-
#_send_message(msg) ⇒ Object
Sends a message.
-
#call(procedure, args = nil, kwargs = nil, options = {}, &callback) ⇒ Object
Publishes and event to a topic.
-
#initialize(transport, options = {}) ⇒ Session
constructor
Constructor.
-
#is_open? ⇒ Boolean
Returns ‘true’ if the session is open.
-
#join(realm) ⇒ Object
Joins the WAMP Router.
-
#leave(reason = 'wamp.close.normal', message = 'user initiated') ⇒ Object
Leaves the WAMP Router.
- #on_challenge(&on_challenge) ⇒ Object
- #on_join(&on_join) ⇒ Object
- #on_leave(&on_leave) ⇒ Object
-
#publish(topic, args = nil, kwargs = nil, options = {}, &callback) ⇒ Object
Publishes and event to a topic.
-
#register(procedure, handler, options = {}, &callback) ⇒ Object
Register to a procedure.
-
#subscribe(topic, handler, options = {}, &callback) ⇒ Object
Subscribes to a topic.
-
#unregister(registration, &callback) ⇒ Object
Unregisters from a procedure.
-
#unsubscribe(subscription, &callback) ⇒ Object
Unsubscribes from a subscription.
Methods included from Check
Constructor Details
#initialize(transport, options = {}) ⇒ Session
Constructor
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/wamp_client/session.rb', line 166 def initialize(transport, ={}) # Parameters self.id = nil self.realm = nil self. = || {} self.verbose = self.[:verbose] # Outstanding Requests self._requests = { publish: {}, subscribe: {}, unsubscribe: {}, call: {}, register: {}, unregister: {} } # Init Subs and Regs in place self._subscriptions = {} self._registrations = {} self._defers = {} # Setup Transport self.transport = transport self.transport. do |msg| self.(msg) end # Other parameters self._goodbye_sent = false # Setup session callbacks @on_join = nil @on_leave = nil end |
Instance Attribute Details
#_defers ⇒ Object
Private attributes
159 160 161 |
# File 'lib/wamp_client/session.rb', line 159 def _defers @_defers end |
#_goodbye_sent ⇒ Object
Private attributes
159 160 161 |
# File 'lib/wamp_client/session.rb', line 159 def _goodbye_sent @_goodbye_sent end |
#_registrations ⇒ Object
Private attributes
159 160 161 |
# File 'lib/wamp_client/session.rb', line 159 def _registrations @_registrations end |
#_requests ⇒ Object
Private attributes
159 160 161 |
# File 'lib/wamp_client/session.rb', line 159 def _requests @_requests end |
#_subscriptions ⇒ Object
Private attributes
159 160 161 |
# File 'lib/wamp_client/session.rb', line 159 def _subscriptions @_subscriptions end |
#id ⇒ Object
Returns the value of attribute id.
156 157 158 |
# File 'lib/wamp_client/session.rb', line 156 def id @id end |
#options ⇒ Object
Returns the value of attribute options.
156 157 158 |
# File 'lib/wamp_client/session.rb', line 156 def @options end |
#realm ⇒ Object
Returns the value of attribute realm.
156 157 158 |
# File 'lib/wamp_client/session.rb', line 156 def realm @realm end |
#transport ⇒ Object
Returns the value of attribute transport.
156 157 158 |
# File 'lib/wamp_client/session.rb', line 156 def transport @transport end |
#verbose ⇒ Object
Returns the value of attribute verbose.
156 157 158 |
# File 'lib/wamp_client/session.rb', line 156 def verbose @verbose end |
Instance Method Details
#_error_to_hash(msg) ⇒ Object
Converts and error message to a hash
257 258 259 260 261 262 263 |
# File 'lib/wamp_client/session.rb', line 257 def _error_to_hash(msg) { error: msg.error, args: msg.arguments, kwargs: msg.argumentskw } end |
#_generate_id ⇒ Object
Generates an ID according to the specification (Section 5.1.2)
251 252 253 |
# File 'lib/wamp_client/session.rb', line 251 def _generate_id rand(0..9007199254740992) end |
#_process_CALL_error(msg) ⇒ Object
Processes an error from a call request
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 |
# File 'lib/wamp_client/session.rb', line 847 def _process_CALL_error(msg) # Remove the pending publish and inform the caller of the failure call = self._requests[:call].delete(msg.request_request) if call details = msg.details || {} details[:procedure] = call[:p] unless details[:procedure] details[:type] = 'call' c = call[:c] c.call(nil, self._error_to_hash(msg), details) if c end end |
#_process_EVENT(msg) ⇒ Object
Processes and event from the broker
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/wamp_client/session.rb', line 440 def _process_EVENT(msg) args = msg.publish_arguments || [] kwargs = msg.publish_argumentskw || {} s = self._subscriptions[msg.subscribed_subscription] if s details = msg.details || {} details[:publication] = msg.published_publication h = s.handler h.call(args, kwargs, details) if h end end |
#_process_INVOCATION(msg) ⇒ Object
Processes and event from the broker
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 |
# File 'lib/wamp_client/session.rb', line 651 def _process_INVOCATION(msg) request = msg.request args = msg.call_arguments || [] kwargs = msg.call_argumentskw || {} details = msg.details || {} details[:request] = request r = self._registrations[msg.registered_registration] if r h = r.handler if h begin value = h.call(args, kwargs, details) def send_error(request, error) if error.nil? error = CallError.new('wamp.error.runtime') elsif not error.is_a?(CallError) error = CallError.new('wamp.error.runtime', [error.to_s]) end error_msg = WampClient::Message::Error.new(WampClient::Message::Types::INVOCATION, request, {}, error.error, error.args, error.kwargs) self.(error_msg) end def send_result(request, result, ={}) if result.nil? result = CallResult.new elsif result.is_a?(CallError) # Do nothing elsif not result.is_a?(CallResult) result = CallResult.new([result]) end if result.is_a?(CallError) send_error(request, result) else yield_msg = WampClient::Message::Yield.new(request, , result.args, result.kwargs) self.(yield_msg) end end # If a defer was returned, handle accordingly if value.is_a? WampClient::Defer::CallDefer value.request = request # Store the defer self._defers[request] = value # On complete, send the result value.on_complete do |defer, result| send_result(defer.request, result) self._defers.delete(defer.request) end # On error, send the error value.on_error do |defer, error| send_error(defer.request, error) self._defers.delete(defer.request) end # For progressive, return the progress if value.is_a? WampClient::Defer::ProgressiveCallDefer value.on_progress do |defer, result| send_result(defer.request, result, {progress: true}) end end # Else it was a normal response else send_result(request, value) end rescue Exception => error send_error(request, error) end end end end |
#_process_PUBLISH_error(msg) ⇒ Object
Processes an error from a publish request
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
# File 'lib/wamp_client/session.rb', line 568 def _process_PUBLISH_error(msg) # Remove the pending publish and inform the caller of the failure s = self._requests[:publish].delete(msg.request_request) if s details = msg.details || {} details[:topic] = s[:t] unless details[:topic] details[:type] = 'publish' c = s[:c] c.call(nil, self._error_to_hash(msg), details) if c end end |
#_process_PUBLISHED(msg) ⇒ Object
Processes the response to a publish request
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
# File 'lib/wamp_client/session.rb', line 549 def _process_PUBLISHED(msg) # Remove the pending publish and alert the callback p = self._requests[:publish].delete(msg.publish_request) if p details = {} details[:topic] = p[:t] details[:type] = 'publish' details[:publication] = msg.publication c = p[:c] c.call(p, nil, details) if c end end |
#_process_REGISTER_error(msg) ⇒ Object
Processes an error from a request
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
# File 'lib/wamp_client/session.rb', line 633 def _process_REGISTER_error(msg) # Remove the pending registration and inform the caller of the failure r = self._requests[:register].delete(msg.request_request) if r details = msg.details || {} details[:procedure] = r[:p] unless details[:procedure] details[:type] = 'register' c = r[:c] c.call(nil, self._error_to_hash(msg), details) if c end end |
#_process_REGISTERED(msg) ⇒ Object
Processes the response to a register request
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
# File 'lib/wamp_client/session.rb', line 613 def _process_REGISTERED(msg) # Remove the pending subscription, add it to the registered ones, and inform the caller r = self._requests[:register].delete(msg.register_request) if r n_r = Registration.new(r[:p], r[:h], r[:o], self, msg.registration) self._registrations[msg.registration] = n_r details = {} details[:procedure] = r[:p] details[:type] = 'register' c = r[:c] c.call(n_r, nil, details) if c end end |
#_process_RESULT(msg) ⇒ Object
Processes the response to a publish request
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
# File 'lib/wamp_client/session.rb', line 826 def _process_RESULT(msg) details = msg.details || {} call = self._requests[:call][msg.call_request] # Don't remove if progress is true and the options had receive_progress true self._requests[:call].delete(msg.call_request) unless (details[:progress] and (call and call[:o][:receive_progress])) if call details[:procedure] = call[:p] unless details[:procedure] details[:type] = 'call' c = call[:c] c.call(CallResult.new(msg.yield_arguments, msg.yield_argumentskw), nil, details) if c end end |
#_process_SUBSCRIBE_error(msg) ⇒ Object
Processes an error from a request
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/wamp_client/session.rb', line 422 def _process_SUBSCRIBE_error(msg) # Remove the pending subscription and inform the caller of the failure s = self._requests[:subscribe].delete(msg.request_request) if s details = msg.details || {} details[:topic] = s[:t] unless details[:topic] details[:type] = 'subscribe' c = s[:c] c.call(nil, self._error_to_hash(msg), details) if c end end |
#_process_SUBSCRIBED(msg) ⇒ Object
Processes the response to a subscribe request
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/wamp_client/session.rb', line 402 def _process_SUBSCRIBED(msg) # Remove the pending subscription, add it to the registered ones, and inform the caller s = self._requests[:subscribe].delete(msg.subscribe_request) if s details = {} details[:topic] = s[:t] unless details[:topic] details[:type] = 'subscribe' n_s = Subscription.new(s[:t], s[:h], s[:o], self, msg.subscription) self._subscriptions[msg.subscription] = n_s c = s[:c] c.call(n_s, nil, details) if c end end |
#_process_UNREGISTER_error(msg) ⇒ Object
Processes an error from a request
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 |
# File 'lib/wamp_client/session.rb', line 779 def _process_UNREGISTER_error(msg) # Remove the pending subscription and inform the caller of the failure r = self._requests[:unregister].delete(msg.request_request) if r details = msg.details || {} details[:procedure] = r[:r].procedure unless details[:procedure] details[:type] = 'unregister' c = r[:c] c.call(nil, self._error_to_hash(msg), details) if c end end |
#_process_UNREGISTERED(msg) ⇒ Object
Processes the response to a unregister request
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 |
# File 'lib/wamp_client/session.rb', line 759 def _process_UNREGISTERED(msg) # Remove the pending unregistration, add it to the registered ones, and inform the caller r = self._requests[:unregister].delete(msg.unregister_request) if r r_s = r[:r] self._registrations.delete(r_s.id) details = {} details[:procedure] = r_s.procedure details[:type] = 'unregister' c = r[:c] c.call(r_s, nil, details) if c end end |
#_process_UNSUBSCRIBE_error(msg) ⇒ Object
Processes an error from a request
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/wamp_client/session.rb', line 502 def _process_UNSUBSCRIBE_error(msg) # Remove the pending subscription and inform the caller of the failure s = self._requests[:unsubscribe].delete(msg.request_request) if s details = msg.details || {} details[:topic] = s[:s].topic unless details[:topic] details[:type] = 'unsubscribe' c = s[:c] c.call(nil, self._error_to_hash(msg), details) if c end end |
#_process_UNSUBSCRIBED(msg) ⇒ Object
Processes the response to a unsubscribe request
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
# File 'lib/wamp_client/session.rb', line 481 def _process_UNSUBSCRIBED(msg) # Remove the pending unsubscription, add it to the registered ones, and inform the caller s = self._requests[:unsubscribe].delete(msg.unsubscribe_request) if s n_s = s[:s] self._subscriptions.delete(n_s.id) details = {} details[:topic] = s[:s].topic details[:type] = 'unsubscribe' c = s[:c] c.call(n_s, nil, details) if c end end |
#_receive_message(msg) ⇒ Object
Processes received messages
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/wamp_client/session.rb', line 274 def (msg) = WampClient::Message::Base.parse(msg) if self.verbose puts 'RX: ' + .to_s if puts 'RX(non-wamp): ' + msg.to_s unless end # WAMP Session is not open if self.id.nil? # Parse the welcome message if .is_a? WampClient::Message::Welcome self.id = .session @on_join.call(.details) unless @on_join.nil? elsif .is_a? WampClient::Message::Challenge if @on_challenge signature, extra = @on_challenge.call(.authmethod, .extra) else signature = nil extra = nil end signature ||= '' extra ||= {} authenticate = WampClient::Message::Authenticate.new(signature, extra) self.(authenticate) elsif .is_a? WampClient::Message::Abort @on_leave.call(.reason, .details) unless @on_leave.nil? end # Wamp Session is open else # If goodbye, close the session if .is_a? WampClient::Message::Goodbye # If we didn't send the goodbye, respond unless self._goodbye_sent goodbye = WampClient::Message::Goodbye.new({}, 'wamp.error.goodbye_and_out') self.(goodbye) end # Close out session self.id = nil self.realm = nil self._goodbye_sent = false @on_leave.call(.reason, .details) unless @on_leave.nil? else # Process Errors if .is_a? WampClient::Message::Error if .request_type == WampClient::Message::Types::SUBSCRIBE self._process_SUBSCRIBE_error() elsif .request_type == WampClient::Message::Types::UNSUBSCRIBE self._process_UNSUBSCRIBE_error() elsif .request_type == WampClient::Message::Types::PUBLISH self._process_PUBLISH_error() elsif .request_type == WampClient::Message::Types::REGISTER self._process_REGISTER_error() elsif .request_type == WampClient::Message::Types::UNREGISTER self._process_UNREGISTER_error() elsif .request_type == WampClient::Message::Types::CALL self._process_CALL_error() else # TODO: Some Error?? Not Implemented yet end # Process Messages else if .is_a? WampClient::Message::Subscribed self._process_SUBSCRIBED() elsif .is_a? WampClient::Message::Unsubscribed self._process_UNSUBSCRIBED() elsif .is_a? WampClient::Message::Published self._process_PUBLISHED() elsif .is_a? WampClient::Message::Event self._process_EVENT() elsif .is_a? WampClient::Message::Registered self._process_REGISTERED() elsif .is_a? WampClient::Message::Unregistered self._process_UNREGISTERED() elsif .is_a? WampClient::Message::Invocation self._process_INVOCATION() elsif .is_a? WampClient::Message::Result self._process_RESULT() else # TODO: Some Error?? Not Implemented yet end end end end end |
#_send_message(msg) ⇒ Object
Sends a message
267 268 269 270 |
# File 'lib/wamp_client/session.rb', line 267 def (msg) puts 'TX: ' + msg.to_s if self.verbose self.transport.(msg.payload) end |
#call(procedure, args = nil, kwargs = nil, options = {}, &callback) ⇒ Object
Publishes and event to a topic
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 |
# File 'lib/wamp_client/session.rb', line 805 def call(procedure, args=nil, kwargs=nil, ={}, &callback) unless is_open? raise RuntimeError, "Session must be open to call 'call'" end self.class.check_uri('procedure', procedure) self.class.check_dict('options', ) self.class.check_list('args', args, true) self.class.check_dict('kwargs', kwargs, true) # Create a new call request request = self._generate_id self._requests[:call][request] = {p: procedure, a: args, k: kwargs, o: , c: callback} # Send the message call = WampClient::Message::Call.new(request, , procedure, args, kwargs) self.(call) end |
#is_open? ⇒ Boolean
Returns ‘true’ if the session is open
205 206 207 |
# File 'lib/wamp_client/session.rb', line 205 def is_open? !self.id.nil? end |
#join(realm) ⇒ Object
Joins the WAMP Router
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/wamp_client/session.rb', line 211 def join(realm) if is_open? raise RuntimeError, "Session must be closed to call 'join'" end self.class.check_uri('realm', realm) self.realm = realm details = {} details[:roles] = WAMP_FEATURES details[:agent] = "Ruby-WampClient-#{WampClient::VERSION}" details[:authid] = self.[:authid] if self.[:authid] details[:authmethods] = self.[:authmethods] if self.[:authmethods] # Send Hello message hello = WampClient::Message::Hello.new(realm, details) self.(hello) end |
#leave(reason = 'wamp.close.normal', message = 'user initiated') ⇒ Object
Leaves the WAMP Router
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/wamp_client/session.rb', line 233 def leave(reason='wamp.close.normal', ='user initiated') unless is_open? raise RuntimeError, "Session must be opened to call 'leave'" end self.class.check_uri('reason', reason, true) self.class.check_string('message', , true) details = {} details[:message] = # Send Goodbye message goodbye = WampClient::Message::Goodbye.new(details, reason) self.(goodbye) self._goodbye_sent = true end |
#on_challenge(&on_challenge) ⇒ Object
152 153 154 |
# File 'lib/wamp_client/session.rb', line 152 def on_challenge(&on_challenge) @on_challenge = on_challenge end |
#on_join(&on_join) ⇒ Object
134 135 136 |
# File 'lib/wamp_client/session.rb', line 134 def on_join(&on_join) @on_join = on_join end |
#on_leave(&on_leave) ⇒ Object
142 143 144 |
# File 'lib/wamp_client/session.rb', line 142 def on_leave(&on_leave) @on_leave = on_leave end |
#publish(topic, args = nil, kwargs = nil, options = {}, &callback) ⇒ Object
Publishes and event to a topic
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
# File 'lib/wamp_client/session.rb', line 528 def publish(topic, args=nil, kwargs=nil, ={}, &callback) unless is_open? raise RuntimeError, "Session must be open to call 'publish'" end self.class.check_uri('topic', topic) self.class.check_dict('options', ) self.class.check_list('args', args, true) self.class.check_dict('kwargs', kwargs, true) # Create a new publish request request = self._generate_id self._requests[:publish][request] = {t: topic, a: args, k: kwargs, o: , c: callback} if [:acknowledge] # Send the message publish = WampClient::Message::Publish.new(request, , topic, args, kwargs) self.(publish) end |
#register(procedure, handler, options = {}, &callback) ⇒ Object
Register to a procedure
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 |
# File 'lib/wamp_client/session.rb', line 593 def register(procedure, handler, ={}, &callback) unless is_open? raise RuntimeError, "Session must be open to call 'register'" end self.class.check_uri('procedure', procedure) self.class.check_dict('options', ) self.class.check_nil('handler', handler, false) # Create a new registration request request = self._generate_id self._requests[:register][request] = {p: procedure, h: handler, o: , c: callback} # Send the message register = WampClient::Message::Register.new(request, , procedure) self.(register) end |
#subscribe(topic, handler, options = {}, &callback) ⇒ Object
Subscribes to a topic
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/wamp_client/session.rb', line 382 def subscribe(topic, handler, ={}, &callback) unless is_open? raise RuntimeError, "Session must be open to call 'subscribe'" end self.class.check_uri('topic', topic) self.class.check_dict('options', ) self.class.check_nil('handler', handler, false) # Create a new subscribe request request = self._generate_id self._requests[:subscribe][request] = {t: topic, h: handler, o: , c: callback} # Send the message subscribe = WampClient::Message::Subscribe.new(request, , topic) self.(subscribe) end |
#unregister(registration, &callback) ⇒ Object
Unregisters from a procedure
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
# File 'lib/wamp_client/session.rb', line 741 def unregister(registration, &callback) unless is_open? raise RuntimeError, "Session must be open to call 'unregister'" end self.class.check_nil('registration', registration, false) # Create a new unsubscribe request request = self._generate_id self._requests[:unregister][request] = { r: registration, c: callback } # Send the message unregister = WampClient::Message::Unregister.new(request, registration.id) self.(unregister) end |
#unsubscribe(subscription, &callback) ⇒ Object
Unsubscribes from a subscription
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/wamp_client/session.rb', line 463 def unsubscribe(subscription, &callback) unless is_open? raise RuntimeError, "Session must be open to call 'unsubscribe'" end self.class.check_nil('subscription', subscription, false) # Create a new unsubscribe request request = self._generate_id self._requests[:unsubscribe][request] = { s: subscription, c: callback } # Send the message unsubscribe = WampClient::Message::Unsubscribe.new(request, subscription.id) self.(unsubscribe) end |