-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: fanout * feat: CI * feat: bump version * feat: bump version js * feat: added server param in broadcast * fix: bump version
- Loading branch information
Showing
17 changed files
with
242 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
module Turbo::Train::StreamsHelper | ||
def turbo_train_from(*streamables, **attributes) | ||
attributes[:name] = Turbo::Train.signed_stream_name(streamables) | ||
attributes[:session] = Turbo::Train.encode({ platform: "web" }) | ||
attributes[:href] = Turbo::Train.configuration.url | ||
attributes[:href] = Turbo::Train.server(attributes[:server]&.to_sym).listen_url(streamables, platform: "web") | ||
tag.turbo_train_stream_source(**attributes) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
require "turbo/train/version" | ||
require "turbo/train/config" | ||
require 'turbo/train/broadcasts' | ||
require 'turbo/train/server' | ||
require 'turbo/train/base_server' | ||
require 'turbo/train/mercure_server' | ||
require 'turbo/train/fanout_server' | ||
require 'turbo/train/test_server' | ||
require 'turbo/train/test_helper' | ||
require "turbo/train/engine" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Turbo | ||
module Train | ||
class BaseServer | ||
attr_reader :configuration | ||
|
||
def initialize(configuration) | ||
@configuration = configuration | ||
end | ||
|
||
def publish(topics:, data:) | ||
raise NotImplementedError | ||
end | ||
|
||
def server_config | ||
raise NotImplementedError | ||
end | ||
|
||
def publish_url | ||
server_config.publish_url | ||
end | ||
|
||
def listen_url(topic, **options) | ||
server_config.listen_url(topic, **options) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Turbo | ||
module Train | ||
class FanoutServer < BaseServer | ||
def publish(topics:, data:) | ||
uri = URI(server_config.publish_url) | ||
req = Net::HTTP::Post.new(uri) | ||
req['Fastly-Key'] = server_config.fastly_key | ||
|
||
message = data[:data].gsub("\n", "") | ||
payload = {items: []} | ||
|
||
Array(topics).each do |topic| | ||
payload[:items] << {channel: topic, formats: { 'http-stream': { content: "event: message\ndata: #{message}\n\n" } } } | ||
end | ||
|
||
req.body = payload.to_json | ||
|
||
opts = { | ||
use_ssl: uri.scheme == 'https' | ||
} | ||
|
||
if configuration.skip_ssl_verification | ||
opts[:verify_mode] = OpenSSL::SSL::VERIFY_NONE | ||
end | ||
|
||
Net::HTTP.start(uri.host, uri.port, opts) do |http| | ||
http.request(req) | ||
end | ||
end | ||
|
||
def server_config | ||
configuration.fanout | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.