diff options
author | Pacien TRAN-GIRARD | 2014-05-12 23:40:30 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-05-12 23:40:30 +0200 |
commit | 1a219a4c2c5694168d81c239f9cc437c0e7fb15b (patch) | |
tree | 612eb7fe061710ac9379b1da6223f07d75c37ac5 /js/slide-controller.js | |
parent | 7296e05b83df9d92c138a4439bb1848213acf646 (diff) | |
download | io-slides-remote-1a219a4c2c5694168d81c239f9cc437c0e7fb15b.tar.gz |
Update require.js
Diffstat (limited to 'js/slide-controller.js')
-rw-r--r-- | js/slide-controller.js | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/js/slide-controller.js b/js/slide-controller.js index 2af62e9..13faa93 100644 --- a/js/slide-controller.js +++ b/js/slide-controller.js | |||
@@ -1,6 +1,6 @@ | |||
1 | /** | 1 | /** |
2 | * Remote control by: | 2 | * Remote control by: |
3 | * | 3 | * |
4 | * @authors Pacien TRAN-GIRARD | 4 | * @authors Pacien TRAN-GIRARD |
5 | */ | 5 | */ |
6 | (function(window) { | 6 | (function(window) { |
@@ -19,7 +19,8 @@ | |||
19 | this.setup(); | 19 | this.setup(); |
20 | } | 20 | } |
21 | 21 | ||
22 | SlideController.MODES = [ 'local', 'remote', 'controller' ]; | 22 | |
23 | SlideController.MODES = ['local', 'remote', 'controller']; | ||
23 | 24 | ||
24 | SlideController.prototype.setup = function() { | 25 | SlideController.prototype.setup = function() { |
25 | 26 | ||
@@ -62,17 +63,14 @@ | |||
62 | // Only open popup from main deck. Avoid recursive popupception. | 63 | // Only open popup from main deck. Avoid recursive popupception. |
63 | if (!this.isPresenter) { | 64 | if (!this.isPresenter) { |
64 | var opts = 'menubar=no,location=yes,resizable=yes,scrollbars=no,status=no'; | 65 | var opts = 'menubar=no,location=yes,resizable=yes,scrollbars=no,status=no'; |
65 | var localPresenter = window.open(location.href, 'mywindow', | 66 | var localPresenter = window.open(location.href, 'mywindow', opts); |
66 | opts); | ||
67 | 67 | ||
68 | // Loading in the popup? Turn the presenter mode on. | 68 | // Loading in the popup? Turn the presenter mode on. |
69 | localPresenter.addEventListener('load', function(e) { | 69 | localPresenter.addEventListener('load', function(e) { |
70 | localPresenter.document.body.classList | 70 | localPresenter.document.body.classList.add('with-notes'); |
71 | .add('with-notes'); | ||
72 | }.bind(this), false); | 71 | }.bind(this), false); |
73 | 72 | ||
74 | window.addEventListener('message', this.onMessage_ | 73 | window.addEventListener('message', this.onMessage_.bind(this), false); |
75 | .bind(this), false); | ||
76 | 74 | ||
77 | // Close popups if we reload the main window. | 75 | // Close popups if we reload the main window. |
78 | window.addEventListener('beforeunload', function(e) { | 76 | window.addEventListener('beforeunload', function(e) { |
@@ -92,29 +90,32 @@ | |||
92 | var addr = this.deck.config_.settings.remoteSocket; | 90 | var addr = this.deck.config_.settings.remoteSocket; |
93 | var channel = this.deck.config_.settings.remoteChannel; | 91 | var channel = this.deck.config_.settings.remoteChannel; |
94 | var password = (password != null) ? password : ''; | 92 | var password = (password != null) ? password : ''; |
95 | this.remoteSocket = io.connect(addr, { | ||
96 | 'query' : 'channel=' + channel + '&password=' + password, | ||
97 | 'force new connection' : true, | ||
98 | }); | ||
99 | 93 | ||
100 | this.remoteSocket.on('connect', function() { | 94 | require([addr + 'socket.io/socket.io.js'], function(io) { |
101 | var message = 'Connected to ' + channel + '@' + addr; | 95 | self.remoteSocket = io.connect(addr, { |
102 | console.log(message); | 96 | 'query' : 'channel=' + channel + '&password=' + password, |
103 | alert(message); | 97 | 'force new connection' : true, |
104 | }); | 98 | }); |
105 | 99 | ||
106 | this.remoteSocket.on('disconnect', function() { | 100 | self.remoteSocket.on('connect', function() { |
107 | var message = 'Diconnected from' + channel + '@' + addr; | 101 | var message = 'Connected to ' + channel + '@' + addr; |
108 | console.log(message); | 102 | console.log(message); |
109 | alert(message); | 103 | alert(message); |
110 | }); | 104 | }); |
105 | |||
106 | self.remoteSocket.on('disconnect', function() { | ||
107 | var message = 'Diconnected from' + channel + '@' + addr; | ||
108 | console.log(message); | ||
109 | alert(message); | ||
110 | }); | ||
111 | 111 | ||
112 | this.remoteSocket.on('message', function(message) { | 112 | self.remoteSocket.on('message', function(message) { |
113 | console.log('Received from remote: ' + message); | 113 | console.log('Received from remote: ' + message); |
114 | self.onMessage_({ | 114 | self.onMessage_({ |
115 | data : { | 115 | data : { |
116 | keyCode : parseInt(message[0]) | 116 | keyCode : parseInt(message[0]) |
117 | } | 117 | } |
118 | }); | ||
118 | }); | 119 | }); |
119 | }); | 120 | }); |
120 | 121 | ||
@@ -123,7 +124,7 @@ | |||
123 | } | 124 | } |
124 | 125 | ||
125 | return true; | 126 | return true; |
126 | } | 127 | }; |
127 | 128 | ||
128 | SlideController.prototype.onMessage_ = function(e) { | 129 | SlideController.prototype.onMessage_ = function(e) { |
129 | 130 | ||
@@ -134,8 +135,7 @@ | |||
134 | // Restrict messages to being from this origin. Allow local developmet | 135 | // Restrict messages to being from this origin. Allow local developmet |
135 | // from file:// though. | 136 | // from file:// though. |
136 | // TODO: It would be dope if FF implemented location.origin! | 137 | // TODO: It would be dope if FF implemented location.origin! |
137 | if (this.mode === 'local' && e.origin != ORIGIN_ | 138 | if (this.mode === 'local' && e.origin != ORIGIN_ && ORIGIN_.indexOf('file://') != 0) { |
138 | && ORIGIN_.indexOf('file://') != 0) { | ||
139 | alert('Someone tried to postMessage from an unknown origin'); | 139 | alert('Someone tried to postMessage from an unknown origin'); |
140 | return; | 140 | return; |
141 | } | 141 | } |