Skip to content

Commit

Permalink
Set stream protocol to HTTP 1.1 (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyu authored Sep 17, 2020
1 parent 0725ccd commit d6bb6ff
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/tesla_api/stream.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
module TeslaApi
module Stream
def stream(&receiver)
def self.streaming_endpoint_url
'wss://streaming.vn.teslamotors.com/streaming/'
end

def self.streaming_endpoint
Async::HTTP::Endpoint.parse(streaming_endpoint_url, alpn_protocols: Async::HTTP::Protocol::HTTP11.names)
end

def stream(endpoint: Stream.streaming_endpoint, &receiver)
Async do |task|
Async::WebSocket::Client.connect(streaming_endpoint) do |connection|
Async::WebSocket::Client.connect(endpoint) do |connection|
on_timeout = ->(subtask) do
subtask.sleep TIMEOUT
task.stop
Expand Down Expand Up @@ -46,14 +54,6 @@ def stream(&receiver)

TIMEOUT = 30

def streaming_endpoint
Async::HTTP::Endpoint.parse(streaming_endpoint_url)
end

def streaming_endpoint_url
'wss://streaming.vn.teslamotors.com/streaming/'
end

def streaming_connect_message
{
msg_type: 'data:subscribe',
Expand Down

0 comments on commit d6bb6ff

Please sign in to comment.