Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add common build which includes both worker and iframe runner context
- Loading branch information
Tobias von Klipstein
committed
Sep 28, 2012
1 parent
19b5228
commit 358a0c0
Showing
4 changed files
with
79 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Entry module for building bonsai for the iframe environment. | ||
*/ | ||
define([ | ||
'../player', | ||
'../../message_channel', | ||
'../context/iframe/bootstrap', | ||
'../context/iframe/context', | ||
'../context/worker/bootstrap', | ||
'../context/worker/context', | ||
'../../renderer/svg/svg', | ||
'../../tools', | ||
'../util' | ||
], function(player, MessageChannel, bootstrapIframe, IframeRunnerContext, bootstrapWorker, WorkerRunnerContext, SvgRenderer, tools, bootstrapUtil) { | ||
'use strict'; | ||
|
||
if(typeof window != 'undefined' && window.messageChannel) { | ||
|
||
// This needs to execute async (setTimeout:1) so that | ||
// IFrameContext.init finishes before this executes: | ||
setTimeout(function() { | ||
var messageChannel = window.messageChannel; | ||
delete window.messageChannel; | ||
bootstrapIframe(messageChannel, window); | ||
}, 1); | ||
|
||
} else if(typeof importScripts != 'undefined') { | ||
// init worker bootstrap | ||
var messageChannel; | ||
|
||
var notifyRenderer = function(message) {postMessage(message);}; | ||
var onMessage = function(message) {messageChannel.notify(message.data);}; | ||
var disconnect = function() { | ||
removeEventListener('message', onMessage); | ||
messageChannel = null; | ||
}; | ||
|
||
messageChannel = new MessageChannel(notifyRenderer, disconnect); | ||
addEventListener('message', onMessage); | ||
bootstrapWorker(messageChannel); | ||
} else { | ||
window['bonsai'] = player; | ||
|
||
var scripts = tools.map(document.getElementsByTagName('script'), function(script) { | ||
return script.src; | ||
}); | ||
|
||
var supportBlobUrls = (function() { | ||
var url = window.URL || window.webkitURL; | ||
return typeof url !== 'undefined'; | ||
})(); | ||
|
||
player.Renderer = SvgRenderer; | ||
|
||
var originalPlayerRun = player.run; | ||
player.run = tools.hitch(player, function(node, url, options) { | ||
player.setup({ | ||
baseUrl: player._baseUrl || tools.baseUri(document), | ||
runnerContext: player.RunnerContext || (supportBlobUrls ? WorkerRunnerContext : IframeRunnerContext), | ||
runnerUrl: player.runnerUrl || supportBlobUrls ? bootstrapUtil.getBlobUrl(__bonsaiRunnerCode__) : ('' + __bonsaiRunnerCode__) | ||
}); | ||
originalPlayerRun.apply(this, arguments); | ||
}); | ||
|
||
} | ||
}); |
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