Red5 フリーソフトのFlashストリーミングサーバ ~開発クライアントの構築 その4~
(5)main.groovy、main.js、main.py、main.rbについて
「main.groovy」・「main.js」・「main.py」・「main.rb」については、特に変更するところがありません。
機能としては、red5アプリケーションを動作する際の基本的ファイルとなります。
ファイル構成については、groovy・javascript・Python・Rubyの4つの言語で構成されています。
- 「main.groovy」
import org.red5.server.adapter.ApplicationAdapter
import org.red5.server.api.IConnection
import org.red5.server.api.IScope
import org.red5.server.api.stream.IPlayItem
import org.red5.server.api.stream.IServerStream
import org.red5.server.api.stream.IStreamCapableConnection
import org.red5.server.api.stream.support.SimpleBandwidthConfigure
import org.red5.server.api.stream.support.SimplePlayItem
import org.red5.server.api.stream.support.StreamUtils
/**
* application.groovy - a translation into Groovy of the ofla demo application, a red5 example.
*
* @author Paul Gregoire
*/
public class Application extends ApplicationAdapter {
def appScope
def serverStream
public Application() {
println "Groovy ctor"
}
public void main(s) {
println "Groovy main"
appStart(null)
appConnect(null, null)
toString()
}
public boolean appStart(app) {
println "Groovy appStart"
appScope = app
return true
}
public boolean appConnect(conn, params) {
println "Groovy appConnect"
measureBandwidth(conn)
if (conn instanceof IStreamCapableConnection) {
def streamConn = conn
def sbc = new SimpleBandwidthConfigure()
sbc.setMaxBurst(8388608)
sbc.setBurst(8388608)
sbc.setOverallBandwidth(8388608)
streamConn.setBandwidthConfigure(sbc)
}
return super.appConnect(conn, params)
}
public void appDisconnect(conn) {
println "Groovy appDisconnect"
if (appScope == conn.scope && serverStream != null) {
serverStream.close
}
super.appDisconnect(conn)
}
public void toString() {
println "Groovy toString"
}
}
/*
* main.js - a translation into JavaScript of the ofla demo Application class, a Red5 example.
*
* @author Paul Gregoire
*/
importPackage(Packages.org.red5.server);
importPackage(Packages.org.red5.server.api);
importPackage(Packages.org.red5.server.api.stream);
importPackage(Packages.org.red5.server.api.stream.support);
importPackage(Packages.org.apache.commons.logging);
importClass(Packages.org.springframework.core.io.Resource);
importClass(Packages.org.red5.server.api.Red5);
importClass(Packages.org.red5.server.api.IScope);
importClass(Packages.org.red5.server.api.IScopeHandler);
var IStreamCapableConnection = Packages.org.red5.server.api.stream.IStreamCapableConnection;
function Application() {
this.appScope = undefined;
this.serverStream = undefined;
this.className = 'Application';
log.debug('Application init');
if (supa) {
Application.prototype = supa;
log.debug('Instance of '+supa);
}
appStart = function(app) {
if (log.isDebugEnabled) {
print('Javascript appStartn');
}
this.appScope = app;
return true;
};
appConnect = function(conn, params) {
log.error('Javascript appConnect');
if (log.isDebugEnabled) {
print('Javascript appConnectn');
}
measureBandwidth(conn);
if (conn == typeof(IStreamCapableConnection)) {
var streamConn = conn;
var sbc = new Packages.org.red5.server.api.stream.support.SimpleBandwidthConfigure();
sbc.setMaxBurst(8388608);
sbc.setBurst(8388608);
sbc.setOverallBandwidth(2097152);
streamConn.setBandwidthConfigure(sbc);
}
return this.__proto__.appConnect(conn, params);
};
appDisconnect = function(conn) {
if (log.isDebugEnabled) {
print('Javascript appDisconnectn');
}
if (this.appScope == conn.getScope() && this.serverStream) {
this.serverStream.close();
}
return this.__proto__.appDisconnect(conn);
};
toString = function(string) {
return 'Javascript:Applicationn';
};
start = function(app) {
print('Javascript startn');
return appStart(app);
};
connect = function(conn, scope, params) {
print('Javascript connectn');
return this.supa.connect(conn, scope, params);
};
join = function(client, scope) {
print('Javascript joinn');
return this.supa.join(client, scope);
};
disconnect = function(conn, scope) {
print('Javascript disconnectn');
return this.supa.disconnect(conn, scope);
};
leave = function(client, scope) {
print('Javascript leaven');
this.supa.leave(client, scope);
};
serviceCall = function(conn, call) {
print('Javascript serviceCalln');
return this.supa.serviceCall(conn, call);
};
doesNotUnderstand = function(name) {
print("Unknown method called: " + name + "n");
for (n in context) {
print('Context: '+n);
}
if (name in this.__proto__) {
if (arguments.length > 0) {
return this.__proto__[name](arguments);
} else {
return this.__proto__[name]();
}
}
};
}
Application.__has__ = function(name) {
println('Has: '+name);
return true;
};
Application.__get__ = function(name) {
println('Get: '+name);
if (name in this) {
return this[name];
} else if (typeof(this['doesNotUnderstand']) == 'function') {
return function() {
return this.doesNotUnderstand(name, arguments);
}
} else {
return undefined;
}
};
Application();
"""
main.py - a translation into Python of the ofla demo Application class, a Red5 example.
@author The Red5 Project (red5@osflash.org)
@author Joachim Bauch (jojo@struktur.de)
"""
from org.red5.server.adapter import ApplicationAdapter
from org.red5.server.api import IBandwidthConfigure
from org.red5.server.api.stream import IStreamCapableConnection
from org.red5.server.api.stream.support import SimpleConnectionBWConfig
class Application(ApplicationAdapter):
def appStart(self, app):
ApplicationAdapter.appStart(self, app)
print 'Python appStart', app
self.appScope = app
return 1
def appConnect(self, conn, params):
ApplicationAdapter.appConnect(self, conn, params)
print 'Python appConnect:', conn, params
self.measureBandwidth(conn)
if isinstance(conn, IStreamCapableConnection):
print 'Python setting bandwidth limits'
sbc = SimpleConnectionBWConfig()
sbc.getChannelBandwidth()[IBandwidthConfigure.OVERALL_CHANNEL] = 10240 * 1024
sbc.getChannelInitialBurst()[IBandwidthConfigure.OVERALL_CHANNEL] = 1024 * 1024
conn.setBandwidthConfigure(sbc)
return 1
def toString(self):
return 'Python:Application'
def getInstance(*args):
print 'Arguments:', args
return Application()
# JRuby - style
require 'java'
module RedFive
include_package "org.red5.server.api"
include_package "org.red5.server.api.stream"
include_package "org.red5.server.api.stream.support"
include_package "org.red5.server.adapter"
include_package "org.red5.server.stream"
end
#
# application.rb - a translation into Ruby of the ofla demo application, a red5 example.
#
# @author Paul Gregoire
#
class Application < RedFive::ApplicationAdapter
attr_reader :appScope, :serverStream
attr_writer :appScope, :serverStream
def initialize
#call super to init the superclass, in this case a Java class
super
puts "Initializing ruby application"
end
def appStart(app)
puts "Ruby appStart"
@appScope = app
return true
end
def appConnect(conn, params)
puts "Ruby appConnect"
measureBandwidth(conn)
puts "Ruby appConnect 2"
if conn.instance_of?(RedFive::IStreamCapableConnection)
puts "Got stream capable connection"
sbc = RedFive::SimpleBandwidthConfigure.new
sbc.setMaxBurst(8388608)
sbc.setBurst(8388608)
sbc.setOverallBandwidth(8388608)
conn.setBandwidthConfigure(sbc)
end
return super
end
def appDisconnect(conn)
puts "Ruby appDisconnect"
if appScope == conn.getScope && @serverStream != nil
@serverStream.close
end
super
end
def toString
return "Ruby toString"
end
def setScriptContext(scriptContext)
puts "Ruby application setScriptContext"
end
def method_missing(m, *args)
super unless @value.respond_to?(m)
return @value.send(m, *args)
end
end
ここまでが、③に関するファイルの変更箇所と簡単な説明となります。
次回は、①に関するファイルの変更箇所と簡単な説明となります。
次は、「Red5 フリーソフトのFlashストリーミングサーバ ~開発クライアントの構築 その5~」について紹介していきます。