Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set stream protocol to HTTP 1.1 #219

Merged
merged 3 commits into from
Sep 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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