Skip to content

FBP Protocol 0.8 compat #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"license": "MIT",
"dependencies": {
"debug": "^3.1.0",
"uuid": "^3.3.2",
"websocket": "~1.0.22"
},
"devDependencies": {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/base.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
platform = require '../helpers/platform'
uuid = require 'uuid'

class BaseRuntime extends platform.EventEmitter
constructor: (definition) ->
Expand Down Expand Up @@ -124,4 +125,13 @@ class BaseRuntime extends platform.EventEmitter

send: (protocol, command, payload) ->

_prepareMessage: (protocol, command, payload) ->
msg =
protocol: protocol
command: command
payload: payload
secret: @definition.secret
requestId: uuid()
return msg

module.exports = BaseRuntime
15 changes: 5 additions & 10 deletions src/lib/iframe.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,18 @@ class IframeRuntime extends Base
postMessage: (protocol, command, payload) ->
w = @iframe.contentWindow
return unless w

msg = @_prepareMessage protocol, command, payload

try
return if w.location.href is 'about:blank'
if w.location.href.indexOf('chrome-extension://') isnt -1
throw new Error 'Use * for IFRAME communications in a Chrome app'
catch e
# Chrome Apps
w.postMessage JSON.stringify(
protocol: protocol
command: command
payload: payload
), '*'
w.postMessage JSON.stringify(msg), '*'
return
w.postMessage JSON.stringify(
protocol: protocol
command: command
payload: payload
), w.location.href
w.postMessage JSON.stringify(msg), w.location.href

onMessage: (message) =>
if message.source and message.source isnt @iframe.contentWindow
Expand Down
7 changes: 2 additions & 5 deletions src/lib/opener.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@ class OpenerRuntime extends Base

postMessage: (protocol, command, payload) ->
return unless window.opener
window.opener.postMessage JSON.stringify(
protocol: protocol
command: command
payload: payload
), '*'
msg = @_prepareMessage protocol, command, payload
window.opener.postMessage JSON.stringify(msg), '*'

onMessage: (message) =>
if message.source and message.source isnt @iframe.contentWindow
Expand Down
5 changes: 1 addition & 4 deletions src/lib/webrtc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ class WebRTCRuntime extends Base
@emit 'disconnected'

send: (protocol, command, payload) ->
m =
protocol: protocol
command: command
payload: payload
m = @_prepareMessage protocol, command, payload
if @connecting
@buffer.push m
return
Expand Down
5 changes: 1 addition & 4 deletions src/lib/websocket.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ class WebSocketRuntime extends Base
return

return unless @connection
@connection.send JSON.stringify
protocol: protocol
command: command
payload: payload
@connection.send JSON.stringify @_prepareMessage protocol, command, payload

handleError: (error) =>
if @protocol is 'noflo'
Expand Down