星期五, 2月 22, 2013

使用BigBlueButton API


使用BigBlueButton API 文件 written by Max

官方wiki
https://code.google.com/p/bigbluebutton/wiki/API


測試主機
http://x.y.z.w/

測試主機的salt : dfc658adec2de8a5d56b06ea51089883

Step 1:
建立會議的方式

舉例來說
http://x.y.z.w/bigbluebutton/api/create?name=Test&meetingID=test01&moderatorPW=mp&attendeePW=ap&checksum=5bb1dd0a153abffedb7abd96825fbecb32fef020

要建立會議, 要給建立聊天室的資料
create?name=Test&meetingID=test01&moderatorPW=mp&attendeePW=ap 取出
拿掉?號
createname=Test&meetingID=test01&moderatorPW=mp&attendeePW=ap

name=Test 會議名稱, 如果有空白字元使用+來串聯
meetingID 會議ID
moderatorPW 主持人密碼
attendeePW 參加人密碼

createname=Test&meetingID=test01&moderatorPW=mp&attendeePW=ap 加上 salt

結果為
createname=Test&meetingID=test01&moderatorPW=mp&attendeePW=apdfc658adec2de8a5d56b06ea51089883

將此一字串藉由SHA1演算法產生雜湊值
可以使用網頁的方式來產生雜湊值
將上面的 createname=Test&meetingID=test01&moderatorPW=mp&attendeePW=apdfc658adec2de8a5d56b06ea51089883  
貼入 http://pajhome.org.uk/crypt/md5/ 網頁內的 Input 欄位
點選 SHA1 按鈕, 產生雜湊值

結果如下
5bb1dd0a153abffedb7abd96825fbecb32fef020
createname=Test&meetingID=test01&moderatorPW=mp&attendeePW=apdfc658adec2de8a5d56b06ea51089883  

去除 salt , 結果為
createname=Test&meetingID=test01&moderatorPW=mp&attendeePW=ap

加上剛剛產生的雜湊值 &checksum=5bb1dd0a153abffedb7abd96825fbecb32fef020

結果為
createname=Test&meetingID=test01&moderatorPW=mp&attendeePW=ap&checksum=5bb1dd0a153abffedb7abd96825fbecb32fef020

將這串字串貼於BigBlueButton 主機 URL /bigbluebutton/api 下, 並加上 ?

create?name=Test&meetingID=test01&moderatorPW=mp&attendeePW=ap&checksum=5bb1dd0a153abffedb7abd96825fbecb32fef020


完整URL 如下

http://
x.y.z.w/bigbluebutton/api/create?name=Test&meetingID=test01&moderatorPW=mp&attendeePW=ap&checksum=5bb1dd0a153abffedb7abd96825fbecb32fef020

此時Server 會回應 建立成功

<response>

<returncode>SUCCESS</returncode>
<meetingID>test01</meetingID>
<attendeePW>ap</attendeePW>
<moderatorPW>mp</moderatorPW>
<createTime>1359709413228</createTime>
<hasBeenForciblyEnded>false</hasBeenForciblyEnded>
<messageKey>duplicateWarning</messageKey>
<message>
This conference was already in existence and may currently be in progress.
</message>
</response>

Step 2:
接下來加入聊天室

http://
x.y.z.w/bigbluebutton/api/join?meetingID=test01&password=mp&fullName=John&checksum=091148f421ce895dcd333fbe34f514050f9adaca

給入加入聊天室的資料
joinmeetingID=test01&password=mp&fullName=John
meetingID 加入聊天室的ID
password 進入聊天室的密碼
fullName 人員姓名

joinmeetingID=test01&password=mp&fullName=John 加上 salt

結果為 joinmeetingID=test01&password=mp&fullName=Johndfc658adec2de8a5d56b06ea51089883

將此一字串藉由SHA1演算法產生雜湊值
可以使用網頁的方式來產生雜湊值
將上面的 joinmeetingID=test01&password=mp&fullName=Johndfc658adec2de8a5d56b06ea51089883  
貼入 http://pajhome.org.uk/crypt/md5/ 網頁內的 Input 欄位
點選 SHA1 按鈕, 產生雜湊值

結果如下
091148f421ce895dcd333fbe34f514050f9adaca

joinmeetingID=test01&password=mp&fullName=Johndfc658adec2de8a5d56b06ea51089883

去除 salt 部分

結果為
joinmeetingID=test01&password=mp&fullName=John  

加上剛剛產生的雜湊值 &checksum=091148f421ce895dcd333fbe34f514050f9adaca

結果為

joinmeetingID=test01&password=mp&fullName=John&checksum=091148f421ce895dcd333fbe34f514050f9adaca

將這串字串貼於BigBlueButton 主機 URL /bigbluebutton/api 下, 並加上 ?

http://
x.y.z.w/bigbluebutton/api/join?meetingID=test01&password=mp&fullName=John&checksum=091148f421ce895dcd333fbe34f514050f9adaca

即可開啟聊天室參加會議

星期一, 1月 14, 2013

EasyRTC install with openSUSE 12.2 小記

EasyRTC install log
Date:  20130103
OS:  openSUSE 12.2

參考  https://github.com/priologic/easyrtc/blob/master/docs/easyrtc_installing.md


透過 One Click install 安裝 nodejs  nodejs-devel
#OneClickInstallCLI   http://software.opensuse.org/ymp/openSUSE:12.2/standard/nodejs.ymp
#zypper   install  nodejs-devel

建立相關目錄
# mkdir   -p   /var/nodes/easyrtc

確認 www (apache)執行使用者
# grep   www  /etc/passwd
wwwrun:x:30:8:WWW daemon apache:/var/lib/wwwrun:/bin/false

將相關目錄(/var/nodes/easyrtc)更改擁有人為 wwwrun (調整權限)

# ls  -ld  /var/nodes/easyrtc/
drwxr-xr-x 2 root root 4096 Jan  3 11:06 /var/nodes/easyrtc/

# chown   wwwrun  /var/nodes/easyrtc/

# ls  -ld  /var/nodes/easyrtc/
drwxr-xr-x 2 wwwrun root 4096 Jan  3 11:06 /var/nodes/easyrtc/

下載 EasyRTC 套件
# cd   /root
# wget   https://github.com/priologic/easyrtc/archive/master.zip

解壓縮 EasyRTC 套件
# unzip   master.zip

將解壓縮的套件移到 相關目錄(/var/nodes/easyrtc)
# mv  /root/easyrtc-master/   /var/nodes/easyrtc/

切換到解壓縮的目錄
# cd   /var/nodes/easyrtc/easyrtc-master

執行安裝
#npm   install
還沒有啟動前, 觀察一下 netstat

# netstat   -tupln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2023/sshd
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      2731/cupsd
tcp        0      0 0.0.0.0:58265           0.0.0.0:*               LISTEN      2658/gnome-session
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2607/master
tcp        0      0 :::22                   :::*                    LISTEN      2023/sshd
tcp        0      0 :::631                  :::*                    LISTEN      1/init
tcp        0      0 ::1:25                  :::*                    LISTEN      2607/master
tcp        0      0 :::37755                :::*                    LISTEN      2658/gnome-session
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           452/avahi-daemon: r
udp        0      0 0.0.0.0:57592           0.0.0.0:*                           452/avahi-daemon: r
udp        0      0 0.0.0.0:631             0.0.0.0:*                           1/init
udp        0      0 :::59115                :::*                                452/avahi-daemon: r
udp        0      0 :::5353                 :::*                                452/avahi-daemon: r

啟動 EasyRTC
#node   server.js

啟動完之後觀察 netstat

# netstat   -tupln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      11035/node
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2023/sshd
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      2731/cupsd
tcp        0      0 0.0.0.0:58265           0.0.0.0:*               LISTEN      2658/gnome-session
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2607/master
tcp        0      0 :::22                   :::*                    LISTEN      2023/sshd
tcp        0      0 :::631                  :::*                    LISTEN      1/init
tcp        0      0 ::1:25                  :::*                    LISTEN      2607/master
tcp        0      0 :::37755                :::*                    LISTEN      2658/gnome-session
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           452/avahi-daemon: r
udp        0      0 0.0.0.0:57592           0.0.0.0:*                           452/avahi-daemon: r
udp        0      0 0.0.0.0:631             0.0.0.0:*                           1/init
udp        0      0 :::59115                :::*                                452/avahi-daemon: r
udp        0      0 :::5353                 :::*                                452/avahi-daemon: r


測試結果 Okay

=====================================================================

EsayRTC with Windows 安裝小記

EsayRTC 安裝流程 version 0.01 by Max


測試時間: 2012/12/22
建立環境: Windows 7


Reference: https://github.com/priologic/easyrtc/blob/master/docs/easyrtc_installing.md

1. 請連上 http://nodejs.org/
請點選 INSTALL 下載 nodejs 安裝檔案






2.請點選執行安裝 nodejs






3. 請點選 Next 開始安裝





4. 請勾選 “I accept the terms in the LIcense Agreement” → 請點選 Next






5. 請點選 Finish 完成 Node.js 安裝





6. 請連線到 http://www.easyrtc.com/
請點選 Download easyRTC beta, FREE!






7. 畫面會被重導向到 https://github.com/priologic/easyrtc
請點選 Clone in Windows 旁邊的 ZIP 圖示







8. 請將 .zip 檔案解壓縮到指定目錄
例如 C:\Users\使用者帳號\nodes\easyrtc
解壓縮的檔案會解壓縮到 C:\Users\max\nodes\easyrtc\easyrtc-master







9. 啟動 node.js command line
請點選 開始 → 所有程式 → Node.js  → Node.js command prompt







10. 請於node.js command line 切換到easyRTC 安裝目錄
請輸入 cd    C:\Users\max\nodes\easyrtc\easyrtc-master   (當初解壓縮目錄)







11. 請輸入 npm  install 開始安裝 EasyRTC






12. 啟動 EasyRTC
請輸入 node  server.js
預設會在 port 8080 LISTEN






13. 如果有 Windows 安全性警訊, 請點選 允許存取







14. 請於瀏覽器輸入http://localhost:8080 或是 http://自己的IP:8080
開始測試


星期三, 11月 14, 2012

Adobe Edge -- Create the Web in Taipei 小記



今天參加 Adobe 創新製作網頁之旅,深入探索現代化網頁工具及技術
講者為 
Ryan Stewart (https://twitter.com/ryanstewart)
以及
Paul Burnett (https://twitter.com/pburnett)

Adobe 參與了一些 open source 的專案, 也建立了一些很 cool 的工具

參加心得如下



Abstract:
  • Optimized different screen size (Responsive Web Design).
  • work with cloud service(Adobe Edge PhoneGap / Web Font).
  • Many free tools and open source tools and projects.

Support HTML 5 and CSS 3

Areas of Focus
  • Magazine-style Advance Layout
    • CSS Exclusions
    • CSS Regions
  • Cinematic Effects
    • CSS Custom Filters
  • Advanced Graphical Effects
    • CSS Blending
    • CSS Compositing

Focus on Webkit Browser
  • WebKit open source project
  • CSS FilterLab

Notes:
  • when execute the effect, above will show the code


Adobe Edge Tool and Service
  • Optimized for creating mobile-ready web content and apps
  • Focused on a specific task
  • Improve productivity without hiding the underlying web technologies

Adobe Edge Animate 1.0
  • Like Flash interface
  • Free (1.0 if free forever) via Adobe ID
  • Optimized the different screen size.
  • Can execute in application or browser, but it is HTML 5.
  • It can open with any normal html page, create some animate and output. (good point)

Adobe Edge Reflow
  • For optimized the different screen size (Responsive Web Design)

Adobe Typekit (Charge) (https://typekit.com/)
  • Use font on the web
  • 1253 font families, 53 foundries
  • Not support double byte font now.

Adobe Edge Web Font (Free)(http://html.adobe.com/edge/webfonts/)
  • Work with Google
  • Get started with Free Web Font
  • 500 + open source and free fonts
  • Open URLs fro each family
  • Not support double byte font now.

Source Sans Pro
  • A new font
  • Source Code Pro (for developer)
    • clear to identify ( l 1 0 O)

Brackets
  • open source tool ( MIT license)
  • Light weight editor
  • Not only text editor, and support CSS, HTML, JavaScript for developer
  • Quick edit (ctrl + e)
  • Live Preview (good point, show the result real time)
  • Brackets Extensions
    • InlineColorEditor


Adobe Edge Code
  • Code HTML, CSS, and JavaScript

Adobe Edge Inspect
  • Preview and Inspect on Mobile Devices
  • Install application on device and install a google chrome plugin to test.
  • Screen for every device look like.(And use text file to describe the device – screen resolution, and information)
  • Check remote device and modify real time.


PhoneGap
  • An SDK to build mobile apps with web technologies
  • PhoneGap provides acces to a number of core device APIs. (With a Java API)

Apache CORDOVA
  • PhoneGap is an Adobe distribution of the apache CORDOVA.

Adobe PhoneGap Build
  • Package Mobile Apps in the Cloud
  • And for different screen size and platform.(ios / Android / Windows … )
  • No need to test the device and download SDK.
  • Same code for different device. (one code to build 5 binary)
  • For update the program, you can only upload the html you wan to fix. Not all program.

Responsive Web Design
  • Fluid & Flexible Grid
  • Flexible Images
  • Media Queries (set min width, automatic move the content)

先記下來

^__^



星期一, 11月 05, 2012

OCPJP Day 14


Lab: Exception

假如 Exception 的架構如下
Exception ← AException ← BException ←CException

AException.java

package mod12;

public class AException extends Exception {

public AException() {
}

public AException(String msg) {
super(msg);
}
}

BException.java

package mod12;
// BException 繼承AException
public class BException extends AException {
}


CException.java

package mod12;
//
public class CException extends BException {
}


Parent.java

package mod12;

public class Parent {
public void work() throws BException{
boolean sucess = false;
if(!sucess){
//Can throw BException or child excpetion
throw new BException();
}
}
public void work2() throws BException{
//
(new Staffing()).doStaff();
}
}


Staffing.java

package mod12;

public class Staffing {
public void doStaff() throws BException{}
}


*方法Overriding Exception
Overriding 方法
  • 可以丟出
    • 一到多個從Overridden方法宣告會丟出的Exception與子孫類別
    • 任意的的Unchecked Exception (Error / Runtime Exception)
  • 不可以丟出
    • 未被Overridden方法宣告會丟出的Exception
    • Overridden方法宣告會丟出Exception的父類別

Child.java

package mod12;

public class Child extends Parent {
//public void work() throws SQLException{ } //這個不行, 不可宣告未被宣告的Excepton
//public void work() throws AException{ } //這個不行, 宣告Exception的父類別
public void work() throws BException{ } // OK, 宣告子類別BException
public void work2() throws CException{ } // OK, 宣告子類別CException
}


修改 Parent.java

package mod12;

import java.io.IOException;

public class Parent {
public void work() throws BException{
boolean sucess = false;
if(!sucess){
//Can throw BException or child excpetion
throw new BException();
}
}
public void work2() throws BException{
//
(new Staffing()).doStaff();
}
//父類別有丟兩個類別
public void work3() throws BException,IOException{
}
}

修改 Child.java

package mod12;

import java.io.FileNotFoundException;

public class Child extends Parent {
//public void work() throws SQLException{ } //這個不行, 不可宣告未被宣告的Excepton
//public void work() throws AException{ } //這個不行, 宣告Exception的父類別
public void work() throws BException{
//No need to announce RuntimeException
} // OK, 宣告子類別BException
public void work2() throws CException{ } // OK, 宣告子類別CException
public void work3() throws BException, FileNotFoundException{
//Can throws BException or IOException or IOException's child Exception
//Can throws one or more Exceptions
}
}






*Assertion 概論
  • 系統上線時期的除錯工具
  • 用來註明並測試程式執行時應符合的假設條件
  • 測試可以在執行時期完全移除, 對程式執行速度完全不受影響
  • Assertion檢查的機制預設是被關閉
    • 藉由下列的指令啟動
      • java -enableassertions MyApplication
      • java -ea MyApplication

*Assertion 機制的建議用法
  • 使用Assertion機制來紀錄並確認單一方法的假設及內部邏輯是否合理
    • 內部執行的不變性(internal invariants)
    • 流程控制的不變性(control flow invariants)
    • 後置狀況及類別不變性(Postcondition and class invariants)


int a = ( new Staffing()).doStaff();

if ( a > 0 ){


} else {
//內部執行的不變性(internal invariants)
assert( a == 0 );

}


switch ( XXX ) {
case SPRING:
case SUMMER:
case FAIL:
case WINTER:

default:
//流程控制的不變性(control flow invariants)
assert(false);
}


*不適當的Assertion使用時機
  • 不要在public方法中用Assertion機制來檢查參數
  • 不要在Assertion的檢測中造成任何副作用







Lab: assert

TestAssertions.java

package mod12;

public class TestAssertions {

public static void main(String[] args) {
int testFlag = 100;
//設定 assert ,但是預設是關閉的如果沒有在 VM option設定 -ea 就不會啟動
assert( testFlag > 100);
//也可以在後面加上訊息
//assert( testFlag > 100 ):"This is an error Message";
System.out.println("Done!");
}
}



*Chapter 15 Java I/O

*I/O基礎概論: I/O stream (輸出入串流)
  • byte stream
    • 一次只能讀取1byte
    • 透過 InputStream讀資料
    • 透過OutputStream寫資料
  • char stream
    • 解決雙位元語系國家字元傳送及接收問題
    • 一次可以傳送2bytes (相當於1char)
    • 透過Reader讀取資料
    • 透過Writer寫資料


InputStreamReader
轉換的API, InputStream 轉成 Reader

OutputStreamWriter
轉換的API, OutputStream 轉成 Writer


*輸出入串流(I/O stream)
  • Node: (在第一線處理的API)(一次處理一個byte)(FileReader)
    • Filter: (加工的串流)(BufferedReader 可以一次讀取一行)(節省處理)

Notes:
  • 串流都是單行道, 讀資料使用來源的串流(source stream), 盡頭串流(sink stream)開啟輸出資料流
Notes:
  • filter 也稱加工的串流(Processing String)
  • 可以在網路傳送java的物件只要實作 Serializable介面

*Console I/O
  • System.out變數可以將資料輸出到系統的標準輸出端(standard output), 他是一個PrintStream型別物件
  • System.in變數可以從系統的標準輸入端(standard input)輸入資料, 他是一個InputStream型別物件
  • System.err變數可以將錯誤資訊輸出到系統的標準錯誤輸出端(standard error), 他是一個PrintStream型別物件


Notes:
  • e.printStackTrace();

Scanner API 提供格式化輸入的功能, 可以套用於console 以及檔案或是網路的串流.

Notes:
  • useDelimiter 設定切割符號
  • 關閉串流的動作是釋放系統的資源

*格式化輸出
  • 可以使用格式化(formatting)的功能如下:
    • System.out.printf(%s %d%n, "Ken",100)
      • %s 輸出字串(任何的資料都可以用%s來輸出)
      • %d %o %x 輸出整數 (, 10進位, 8進位, 16進位)
      • %n 為換行
      • %f %g 輸出浮點數 ()
      • 可以在前面加上數字指定長度, 例如 %10s 長度為10
      • %% 輸出%符號
      • %b 輸出 boolean
        • If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(arg). Otherwise, the result is "true".
IllegalFormatconversionException 為指定的資料與型別不符(例如應該給整數卻給浮點數)

Mod15.java

package mod15;

import java.util.Date;

public class Mod15 {

public static void main(String[] args) {
int a = 100;
double b = 12.345;
String c = "Hello";
Date d = new Date();
//%30s --> output 30 characters
System.out.printf("%s%n", a);
System.out.printf("%s%n", b);
System.out.printf("%s%n", c);
System.out.printf("%s%n", d);
System.out.printf("%20.5f%n", b);
// 使用%b的時候, 如果值為null 輸出false, 如果是大小寫Boolean就看是true 或是 false來輸出, 如果是其他的型別但是值又不是null就會輸出true
String e = null;
Date f = null;
boolean g = true;
Boolean h = false;
int i = 100;
String j = "Hello";
Date k = new Date();
System.out.printf("%b%n", e);
System.out.printf("%b%n", f);
System.out.println();
System.out.printf("%b%n", g);
System.out.printf("%b%n", h);
System.out.println();
System.out.printf("%b%n", i);
System.out.printf("%b%n", j);
System.out.printf("%b%n", k);

}
}


*檔案和檔案I/O
  • 建立File物件
  • 操作File物件(對檔案本身進行操作, 例如重新命名或是刪除, 不對內容操作)
  • 讀取或是寫入檔案的串流(File streams)

何謂可序列化的資料(物件)?
  • 基本型別預設就是可序列化
  • 物件要可序列化必須符合
    • 其類別要實作java.io.Serializable interface
    • 類別屬性也一定要是可序列化的.