-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
46 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
App.tv = App.cable.subscriptions.create "TvChannel", | ||
connected: -> | ||
# Called when the subscription is ready for use on the server | ||
|
||
disconnected: -> | ||
# Called when the subscription has been terminated by the server | ||
|
||
received: (data) -> | ||
# Called when there's incoming data on the websocket for this channel | ||
console.info(data) | ||
|
||
put_message: () -> | ||
@perform("put_message") | ||
return |
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,4 +1,15 @@ | ||
module ApplicationCable | ||
class Connection < ActionCable::Connection::Base | ||
identified_by :current_user | ||
|
||
def connect | ||
self.current_user = find_verified_user | ||
end | ||
|
||
protected | ||
|
||
def find_verified_user # this checks whether a user is authenticated with devise | ||
env["warden"].user || reject_unauthorized_connection | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class TvChannel < ApplicationCable::Channel | ||
# クライアントと接続された時 | ||
def subscribed | ||
stream_from "tv:message" | ||
end | ||
|
||
# クライアントとの接続が解除された時 | ||
def unsubscribed | ||
# Any cleanup needed when channel is unsubscribed | ||
end | ||
|
||
def put_message | ||
TvChannel.broadcast_to("message", "hello") | ||
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 |
---|---|---|
|
@@ -6,4 +6,7 @@ def index | |
|
||
def dashboard | ||
end | ||
|
||
def tv | ||
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Pages#tv</h1> | ||
<p>Find me in app/views/pages/tv.html.erb</p> |
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