websocket R6 inheritance of events from the websocket

Hi,

I am developing a live streaming R6 class for my package based on the standard R package for websockets [Github rstudio/websocket ](https://github.com/rstudio/websocket) as I would like to create a number of streams I thought it would be a good approach to inherit the websocket::WebSocket R6 class and then add my own parameters and public methods in a child websocket class.

I previously did not make a new class and run the code directly and then I was able to receive the messages and errors.

Since I created the child class I don't receive anymore feedback when messages or errors are received.
The line "Message received" was never printed.

I think that because the messages/events appear in the super/parent class and that somehow the messages/events are not passed through to the child. Any advice how I can make sure/check that events are passed through?

 child_Stream <- R6::R6Class( "OMM_Stream"
                                                          , inherit = websocket::WebSocket
                                                           , public = list( name = NULL
                                                                           ,  api = NULL
                                                                           ,  domain = "MarketPrice"
                                                                            ,  service = NULL
                                                                            ,  fields = NULL
                                                                            ,  extended_params = NULL
                                                                            ,  initialize = function(name = NULL
                                                                                                     ,  api = NULL
                                                                                                     , domain = "MarketPrice"
                                                                                                     , service = NULL
                                                                                                     , fields = NULL
                                                                                                     , extended_params = NULL
                                                                                                     , url = "ws://localhost:9000/v1/WebSocket"
                                                                                                     , protocols = "tr_json2"
                                                                                                     , headers = list( 'User-Agent' = "R")
                                                                                                     , autoConnect = FALSE){
                                           super$initialize(url, protocols, headers, autoConnect)
                                           self$name <- name
                                           self$api <- api
                                           self$domain <- domain
                                           self$service <- service
                                           self$fields <- fields
                                           self$extended_params <- extended_params
                                           self
                     }, get_stream = function(){
                               cat("selected get stream method")
                        },
                        open = function(){
                          self$connect()
                          Sys.sleep(3)
                          self$send(Create_login_request())
                          Sys.sleep(2)
                          super$send(Create_Stream_request(domain = self$domain, name = self$name, fields = self$fields, snapshot = FALSE))
                          print("stream requested")
                        },
                        onOpen = function(event) {
                          print("in onOpen")
                          super$send(Create_login_request())
                          Sys.sleep(2)
                          super$send(Create_Stream_request(domain = domain, name = name, fields = fields))
                        },
                        onMessage = function(event) {
                               print("Message received")
                               #cat(dput(jsonlite::fromJSON(event$data)), "\n")
                              }
                      , onError = function(event) {
                           cat("Client failed to connect: ", event$message, "\n")
                     })
                     , private = list( snapshot = FALSE)


)

when I ran the example

test_CS <- child_Stream()
test_CS$new()
test_CS_2 <- test_CS$new(name = "EUR=", fields = c("BID","ASK","OPEN_PRC"))
test_CS_2$open()

#only response received
[1] "stream requested"
 

This topic was automatically closed after 45 days. New replies are no longer allowed.


If you have a query related to it or one of the replies, start a new topic and refer back with a link.