Mar 2026【隨筆】Clone a Meta Ray-ban Display glasses application|藍芽 L2CAP CoC 極致低延遲架構優化:實現 720p 智慧眼鏡流暢串流 👓(LIVE DEMO)

圖片
最近在做一些實驗性質的東西,記得去年短暫玩過 2023 年底上市的第二代 Ray-Ban Meta 智能眼鏡,雖然它主要還是依賴智慧型手機作為算力中心,但我們對它所使用的串流技術很感興趣,因為聽說他們是用藍芽做串流。 去年曾經有同事隨口問我:「我們的眼鏡做到跟他們一樣你覺得有可能嗎?」,因為我知道我們的硬體規格跟人家的相比並非等號,加上當時有其他事情在搞,所以隨口開玩笑回說:“可是聽說 Meta 有200個人在搞那個眼鏡捏(雖然不知道他們負責搞應用的有幾人),啊我如果一個人可以幹贏他們200人,那我還在這幹嘛???(笑)” 也記得更久以前,當我們還在研究那個眼鏡時,常聽到像是:『 他們不知道用了什麼黑科技 』,這類沒有建設性、不應該從 RD 嘴裡說出來的話,而我也是不以為然。坦白講,以前每次只要聽到某SW嘴砲部經理(暫且以H君稱之),沒事就把『 黑科技 』三個字掛在嘴上,當做無知的遮羞布,我就會感到倒胃口!同樣身為RD,我只覺得  Shame on you!(打嘴炮、作秀搶風頭、噁心帶風向、搞政治操作、把別人做事的成果搶去幫自己抬轎、有鍋直接推給下屬扛、散佈同事私生活謠言,還有職場霸凌,這些你他媽都頂級專業戶,除此之外沒啥洨用了!) 一件理論上可以做到的事情,外行人的認知被信息差,不懂加上沒實作能力去驗證,就什麼都變成黑科技了(多黑?比巴西黑鮑魚還黑嗎?)。反重力技術說不定也非啥黑科技,只是政府不讓你普通老百姓了解罷了。 Ray-ban Meta 的黑科技,講白了就是人家拉個百人團隊在搞那支眼鏡,然後把軟體技能和硬體規格點滿,再加上極致優化後的成果罷了! 某SW嘴砲部經理有多會帶風向?光是我印象比較深刻、跟現任or前同事有關的的就有三件,約莫兩年多前,有次我私底下跟他討論公事(已經忘了討論啥了)時,那廝跟我說:『 唉~你看像SDA那些老人,我可不想要以後變成跟他們一樣 』(我心想:你他媽的就只是一個打嘴炮的貨色而已,在那看不起別人,啊你是又多高尚?),還有更久的事,疫情發生前以前,當年我們SW處長(離職前好像升協理了,人稱J大),從這部門離開跳巢到另一間陸資企業,且帶了一批人一起走,那段時間有次我跟嘴砲部經理在公司用餐閒聊時,他跟我說:『 誒~有人說J大是現代吳三桂,你怎麼看? 』,我問他此話怎麼說?他說:『因為這個蘋果的產品供應鏈目前清一色台廠,他把陸資引...

Integrating Facebook Connect with your Rails Applications

Facebook Connect is a set of APIs from Facebook that enable Facebook members to log onto third-party websites, applications, mobile devices and gaming systems with their Facebook identity. While logged in, users can connect with friends via these mediums and post information and updates to their Facebook profile. Developers can use these services to help their users connect and share with their Facebook friends on and off of Facebook and increase engagement for their website or application.

Originally unveiled during Facebook’s developer conference, F8, in July 2008, Facebook Connect became generally available in December 2008. According to an article from The New York Times, "Some say the services are representative of surprising new thinking in Silicon Valley. Instead of trying to hoard information about their users, the Internet companies (including Facebook, Google, MySpace and Twitter) all share at least some of that data so people do not have to enter the same identifying information again and again on different sites."

Windows Live服務整合Facebook Connect功能的畫面:


Facebook Connect是Facebook在2008年推出的功能,推出後馬上被許多大中小型網站所使用。透過Facebook Connect,用戶將可以在整個網路上使用Facebook的身份驗證資料,包括使用Facebook帳戶登入/註冊第三方網站,以及在其他網站分享他們的頭像照片、名稱、照片、朋友、群組、活動以及其他的資訊。這個是以前所做的東西,但Facebook已經在今年推出了新版的Open Graph API,若打算實作這個部份的話,建議還是使用新版的API會比較可靠!

Facebook Connect
http://developers.facebook.com/connect.php

Facebook Platform Wiki
http://en.wikipedia.org/wiki/Facebook_Platform


下面是實作Facebook Connect in Rails Application的過程:

1.首先我們需要給Rails project安裝Facebooker Plugin:
$ script/plugin install http://github.com/mmangino/facebooker/tree/master
安裝新版的facebooker插件必須將Rails升級到2.2版本以上.

2.你需要在Facebook註冊一個Developer測試帳戶,或是從下面網址讓你現有的Facebook帳戶成為Facebook Platform Developer Test Accounts(開發應用程式用的測試帳戶):
http://www.facebook.com/developers/become_test_account.php

登入Facebook Developer頁面註冊你的應用程式:
http://www.facebook.com/developers

步驟1. Add the Developer Application.
步驟2. Create a New Facebook Application.
步驟3. Update the Facebook Application settings to point to your publicly available host.

Example settings(假設域名是:http://www.example.com):

Authentication Tab:
  Enter Post-Authorize Callback URL, e.g. http://www.example.com/fb/post_authorize
  Canvas Tab:
Enter Canvas Page URL, e.g. run_example_com
Enter Canvas Callback URL, e.g. http://www.example.com/fb/connect
  Connect Tab:
Enter Connect URL, http://www.example.com/fb/connect
  Advanced Tab:
Set Application Type as Web.

將facebooker plugin裡的facebooker.yml文件放在/config目錄下,並編輯其內容:

Set api_key, secret_key, canvas_page_name (copy the last part of the Canvas Page URL from the Canvas tab), callback_url (that's Canvas Callback URL from FB settings), and set set_asset_host_to_callback_url to false.

下面是一個facebooker.yml範例內容:

然後執行xd_receiver generator來產生cross domain scripting bridge,用來讓你的應用程式可以和Facebook溝通:

$ script/generate xd_receiver

預設之下它會在/public目錄下建立xd_receiver.html和xd_receiver_ssl.html兩個檔案,我們將它們放置到/public/fb/connect目錄下,因為這個路徑會對映到我們稍候建立的FbController的connect方法中,而我們也會在/config/route.rb中定義這個路徑。

接下來將facebooker plugin目錄下的facebooker.js複製到/public/javascript目錄下,並新增一個facebook_require.js檔案,內容如下:

編輯/public/javascript/application.js新增下面內容:

編輯app/vews/layout/application.html.erb新增內容:

我們還要在適當的樣板中新增一個藉由Facebook Session登入的"登出"連結,用來區別和一般帳戶登入的不同,點擊'從Facebook登出'將會刪除現階段的Facebook Session並將使用者導向/logout來登出網站

編輯/config/environment.rb,新增環境變數:


典型的方式是使用網站資料庫裡現有的Users資料表中的DB Record來和Facebook帳戶整合, 我們將在users table中新增fb_uid(facebook uid)和email_hash(to contain a hashed version of the user's email address)欄位。

A typical case for integration is to add Facebook Connect as an alternative way of authenticating for existing users. To achieve this, add fields fb_uid (facebook uid) and email_hash (to contain a hashed version of the user's email address) to the users table.

接下來新增一個Run Publisher模型:
$ script/generate model RunPublisher

Publishing is handled by the RunPublisher class in app/models/run_publisher.rb. Every feed template needs to be registered with Facebook before it can be used and this is done via migrations.

編輯/app/models/run_publisher.rb的內容:

然後建立新的Database遷移檔:
$ script/generate migration CreateFacebookTemplates

編輯/db/migrate/xxxxx_create_facebook_templates.rb遷移檔內容:

然後還需要建立一個遷移檔,在users資料表添加一些新的欄位:
$script/generate migration AddFacebookConnectToUsers

編輯/db/migrate/xxxxx_add_facebook_connect_to_users.rb內容:

最後執行rake db:migrate建立資料表!

接下來編輯/config/route.rb新增下面的路徑映射:

在/bin目錄下新增fb_preconnect.rb內容如下:

接下來在/bin目錄下新增register_templates.rb內容如下:

現在我們可以執行 script bin/fb_preconnect.rb 來預先連結資料庫中的所有使用者,這樣將能夠讓Facebook知道我們資料庫中的使用者可能會在將來使用Facebook Connect連結他們的帳戶。Facebook會預先連結使用者的 email_hash 來配對帳號。若不執行preconnect動作,Facebook將不會去包含 email hash 的值,將來使用者過Facebook Connect連結時,將需要輸入他們的Email地址!

稍候我們在/app/models/user.rb中建立的after_create callback可以讓將來任何新建立的使用者帳號都會自動和Facebook去做預先連結。

藉由Users資料表中的 fb_uid 欄位,使用者將可以透過正常的登入機制(帳號/密碼) 或是Facebook Connect 按鈕來登入,而我們會在/app/controllers/fb_connect_controller.rb建立Facebook Connect主要的驗證機制。


現在新增一個FBConnect Controller並編輯其內容如下:
$ script/generate controller FbConnect

下面是我們的FbConnect Controller處理Facebook Session Login的簡單流程圖:


在Application Controller新增方法,用來處理Facebook Session以及Session Expired:

然後需要修改用來處理登入驗證機制的/lib/login_system.rb的內容:

接下來要修改/app/controllers/account_controller.rb中用來處理登出的logout方法:

登出Rails網站並同時登出Facebook


接下來修改Users Controller中的New和Create方法(這是用來建立使用者的):

在new方法添加這些過濾內容是為了防止使用者直接在網址攔輸入fb_user=1的參數來欺騙應用程式,正確的作法是必須透過Application_Controller中的facebook_user方法來驗證使用者是真正透過Facebook Session來註冊帳號。我們同樣也可以在create方法中添加這條過濾!

然後編輯User Model內容,修改password_required?方法:

上面的before_update是為了在使用者變更Email地址之後,建立新的Facebook Session和變更email_hash的值。其中的email_changed?是在Rails 2.1版本之後開始內建的方法,可以直接調用

接下來修改/app/views/users/new.html.erb視圖的內容:

然後修改/app/views/users/edit.html.erb視圖,編輯密碼修改的欄位部份:

並在users的edit和show視圖中新增下面的判斷內容:

然後在/app/views/shared目錄下建立_fbconnect_button.html.erb和_fbpublish.html.erb兩個樣板檔:

其中_fbconnect_button.html.erb內容如下:

另外_fbpublish.html.erb內容如下:

然後將貼到需要添加Facebook登入按鈕的視圖頁面即可(如首頁,Signup頁面和Login頁面)


接下來我們可以編輯相關的視圖,讓透過Facebook Session登入的使用者可以在頁面上直接顯示他們的Facebook頭像圖片和Facebook用戶名稱(點擊圖片可以連結至他們的Facebook頁面),而不再是我們網站上的頭像圖片。

PS.從這邊開始的部份都是我自己的Rails Project的內容,看不懂的請不要亂複製到你的Project,我這裡只是提供一個概念作為參考!

首先修改users_helper.rb中的user_link方法:

然後修改users/_status_update.html.erb的視圖內容,這是使用者首頁的狀態發佈器。

接著修改users/_current_status.html.erb視圖:

最後將下面內容加到/app/controllers/users/status_update_controller.rb的Create方法中:



另外我們還可以修改/app/views/wall_comments底下的_form.html.erb和_comment.html.erb視圖,讓透過Facebook Session登入的使用者可以在Profile頁面的塗鴉牆看到自己的Facebook頭像和名字:

修改/app/views/wall_comments/_form.html.erb視圖:

修改/app/views/wall_comments/_comment.html.erb視圖:

OK搞定了!而其他需要顯示Facebook頭像的頁面也可以用同樣的邏輯來作修改,非常簡單!


接下來我們要將Rails網站裡面的一些功能和Facebook做進一步的整合,首先我們要將使用者首頁的狀態更新和Facebook塗鴉牆整合,讓使用者在網站上更新狀態時,訊息可以同時發佈到使用者的Facebook塗鴉牆上。

首先在users/status_update_controller.rb中新增一個fbpublish方法:

然後編輯/public/javascript/application.js新增下面的內容,其中的Ajax Request路徑會指向Users::StatusUpdatesController中的fbpublish方法,它會執行一些Ajax動作:

接著我們在users/status_update_controller.rb的Create方法中添加下面的內容:

然後在建立/app/views/shared目錄下建立_fbpublish.html.erb樣板:

並修改users/_status_update.html.erb樣板內容:

另外,視圖中jQuery的部份也需要修改:


使用者尚未授權Facebook帳戶可以透過第三方網站張貼內容至Facebook塗鴉牆


授權Facebook帳戶畫面,授權之後我們的應用程式會去呼叫Users::StatusUpdatesController中的fbpublish方法執行Ajax動作。


已授權Facebook帳戶可以從第三方網站張貼內容至Facebook塗鴉牆


訊息已透過我們的應用程式發佈到使用者的Facebook塗鴉牆上


最後我們可以在使用者的首頁和個人檔案頁面顯示該使用者Facebook帳號上的朋友,首先在首頁和個人檔案頁面載入部份樣板:

最後建立/app/views/shared/_fbfriends.html.erb樣板:




下面是一些Facebook Connect的相關資源以及Tutorial:

Facebook Connect on Facebook Developers
http://developers.facebook.com/connect.php

Using Ruby on Rails with Facebook Platform
http://wiki.developers.facebook.com/index.php/Using_Ruby_on_Rails_with_Facebook_Platform

Facebooker Tutorial
http://apps.facebook.com/facebooker_tutorial/

Tutorial for restful_authentication on Rails with Facebook Connect in 15 minutes
http://www.madebymany.co.uk/tutorial-for-restful_authentication-on-rails-with-facebook-connect-in-15-minutes-00523

Tutorial on developing a Facebook platform application with Ruby On Rails
http://www.liverail.net/articles/2007/6/29/tutorial-on-developing-a-facebook-platform-application-with-ruby-on-rails

Integrating Facebook Connect with Rails Applications
http://nws.applicake.com/blog/index.php/2009/07/02/integrating-facebook-connect-with-rails-applications/

Using Facebooker to make a Rails site with Facebook Connect (Part 1)
http://blog.moove-it.com/using-facebooker-to-make-a-rails-site-with-facebook-connect-part-1/

Using Facebooker to make a Rails site with Facebook Connect (Part 2)
http://blog.moove-it.com/using-facebooker-to-make-a-rails-site-with-facebook-connect-part-2/

Using Facebooker to make a Rails site with Facebook Connect (Part 3)
http://blog.moove-it.com/using-facebooker-to-make-a-rails-site-with-facebook-connect-part-3/

Rails app on Facebook Connect
http://www.rubyflow.com/items/1322

Star in a Porno with Facebook Connect and Rails
http://spongetech.wordpress.com/2008/11/17/star-in-a-porno-with-facebook-connect-and-rails/

How to Facebook-Connect a Rails app
http://passthehash.com/hash/2009/05/how-to-facebook-connect-your-rails-app.html

Getting Started with Facebooker
http://www.pathf.com/blogs/2008/07/getting-started-with-facebooker/

文章列表

Contact

名稱

以電子郵件傳送 *

訊息 *