Skip to content

Commit 251e4c8

Browse files
committed
Perfectly implemented transport system
1 parent 9b12d04 commit 251e4c8

File tree

7 files changed

+37
-24
lines changed

7 files changed

+37
-24
lines changed

dist/browser.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(function factory(root) {
44

55
var dop = {
6-
version: '0.3.1',
6+
version: '0.3.2',
77
name: 'dop', // Useful for transport (websockets namespaces)
88
create: factory,
99

@@ -21,7 +21,8 @@ var dop = {
2121
// src
2222
util: {},
2323
core: {},
24-
protocol: {}
24+
protocol: {},
25+
transports: {listen:{}, connect:{}}
2526
};
2627

2728

@@ -46,7 +47,7 @@ dop.connect = function(options) {
4647
options = args[0] = {};
4748

4849
if (typeof options.transport != 'function')
49-
options.transport = connectWebsocket;
50+
options.transport = dop.transports.connect.websocket;
5051

5152
return dop.core.connector(args);
5253
};
@@ -142,8 +143,8 @@ emitter.emit(name, 4);
142143

143144

144145
////////// src/env/browser/websocket.js
145-
146-
var connectWebsocket = function websocket(dop, node, options) {
146+
(function(root){
147+
function websocket(dop, node, options) {
147148

148149
var url = 'ws://localhost:4444/'+dop.name;
149150

@@ -189,11 +190,16 @@ var connectWebsocket = function websocket(dop, node, options) {
189190
};
190191

191192
if (typeof dop=='undefined' && typeof module == 'object' && module.exports)
192-
module.exports = connectWebsocket;
193-
else if (typeof window != 'undefined')
194-
connectWebsocket.api = function() {
195-
return window.WebSocket;
196-
};
193+
module.exports = websocket;
194+
else {
195+
websocket.api = function() { return window.WebSocket };
196+
(typeof dop != 'undefined') ?
197+
dop.transports.connect.websocket = websocket
198+
:
199+
root.dopTransportsConnectWebsocket = websocket;
200+
}
201+
202+
})(this);
197203

198204

199205

dist/browser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/nodejs.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(function factory(root) {
44

55
var dop = {
6-
version: '0.3.1',
6+
version: '0.3.2',
77
name: 'dop', // Useful for transport (websockets namespaces)
88
create: factory,
99

@@ -21,7 +21,8 @@ var dop = {
2121
// src
2222
util: {},
2323
core: {},
24-
protocol: {}
24+
protocol: {},
25+
transports: {listen:{}, connect:{}}
2526
};
2627

2728

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dop",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"main": "./dist/nodejs.js",
55
"browser": "./dist/browser.js",
66
"license": "MIT",

src/dop.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function factory(root) {
22

33
var dop = {
4-
version: '0.3.1',
4+
version: '0.3.2',
55
name: 'dop', // Useful for transport (websockets namespaces)
66
create: factory,
77

@@ -19,7 +19,8 @@ var dop = {
1919
// src
2020
util: {},
2121
core: {},
22-
protocol: {}
22+
protocol: {},
23+
transports: {listen:{}, connect:{}}
2324
};
2425

2526

src/env/browser/connect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ dop.connect = function(options) {
77
options = args[0] = {};
88

99
if (typeof options.transport != 'function')
10-
options.transport = connectWebsocket;
10+
options.transport = dop.transports.connect.websocket;
1111

1212
return dop.core.connector(args);
1313
};

src/env/browser/websocket.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
2-
var connectWebsocket = function websocket(dop, node, options) {
1+
(function(root){
2+
function websocket(dop, node, options) {
33

44
var url = 'ws://localhost:4444/'+dop.name;
55

@@ -45,8 +45,13 @@ var connectWebsocket = function websocket(dop, node, options) {
4545
};
4646

4747
if (typeof dop=='undefined' && typeof module == 'object' && module.exports)
48-
module.exports = connectWebsocket;
49-
else if (typeof window != 'undefined')
50-
connectWebsocket.api = function() {
51-
return window.WebSocket;
52-
};
48+
module.exports = websocket;
49+
else {
50+
websocket.api = function() { return window.WebSocket };
51+
(typeof dop != 'undefined') ?
52+
dop.transports.connect.websocket = websocket
53+
:
54+
root.dopTransportsConnectWebsocket = websocket;
55+
}
56+
57+
})(this);

0 commit comments

Comments
 (0)