|
1 | | -(function(){ |
2 | | - |
3 | | - if (APP) |
4 | | - { |
5 | | - var connect = require('connect'); |
6 | | - var serveStatic = require('serve-static'); |
7 | | - var path = require('path'); |
8 | | - } |
9 | | - |
| 1 | +(function() |
| 2 | +{ |
10 | 3 | // Import classes |
11 | 4 | var Module = springroll.Module, |
12 | | - PreviewContainer = springroll.PreviewContainer; |
13 | | - |
14 | | - // The local port to use for the preview server |
15 | | - var SERVER_PORT = 3030; |
| 5 | + PreviewContainer = springroll.PreviewContainer, |
| 6 | + Server = springroll.PreviewServer; |
16 | 7 |
|
17 | 8 | /** |
18 | 9 | * Preview the current project |
|
24 | 15 | Module.call(this); |
25 | 16 |
|
26 | 17 | /** |
27 | | - * The web server |
28 | | - * @property {Server} server |
| 18 | + * The web server for project view |
| 19 | + * @property {springroll.PreviewServer} server |
29 | 20 | */ |
30 | | - this.server = null; |
| 21 | + this.server = new Server(localStorage.getItem('project')); |
31 | 22 |
|
32 | 23 | /** |
33 | 24 | * The local location for the iframe |
34 | 25 | * @property {string} location |
35 | 26 | */ |
36 | | - this.location = "http://localhost:" + SERVER_PORT; |
| 27 | + this.location = "http://localhost:" + this.server.port + '/game'; |
37 | 28 |
|
38 | 29 | /** |
39 | 30 | * The current iframe |
40 | 31 | * @property {jquery} iframe |
41 | 32 | */ |
42 | 33 | this.container = new PreviewContainer(); |
43 | 34 |
|
44 | | - // Grab the opened project |
45 | | - this.project = localStorage.getItem('project'); |
46 | | - |
47 | 35 | $("#refreshButton").click(this.refresh.bind(this)); |
48 | 36 | $("#devToolsButton").click(this.toggleDevTools.bind(this)); |
49 | | - |
50 | | - // Disable the form submitting |
51 | | - $('form').submit(function(e) |
52 | | - { |
53 | | - return false; |
54 | | - }); |
55 | 37 |
|
56 | 38 | if (APP) |
57 | 39 | { |
58 | | - var app = connect(); |
59 | | - this.server = app.listen(SERVER_PORT); |
60 | | - app.use(serveStatic( |
61 | | - path.join(this.project, 'deploy'), |
62 | | - {'index': ['index.html']} |
63 | | - )); |
64 | | - |
65 | 40 | // Initialize the menu |
66 | 41 | this.initMenubar(false, true); |
67 | 42 | } |
68 | | - |
69 | | - // When the app closes re-open it |
70 | | - this.open(); |
| 43 | + |
| 44 | + this.open(); |
71 | 45 | }; |
72 | 46 |
|
73 | 47 | // Reference to the prototype |
|
91 | 65 | if (APP) |
92 | 66 | { |
93 | 67 | // Set the project title and |
94 | | - this.container.appTitle.text(path.basename(this.project)); |
95 | | - this.container.remoteChannel.val(path.basename(this.project)); |
| 68 | + this.container.appTitle.text(this.server.title); |
| 69 | + this.container.remoteChannel.val(this.server.title); |
96 | 70 | this.container.connectLoggingService(); |
97 | 71 | } |
98 | 72 |
|
| 73 | + console.log("Open location " + this.location); |
99 | 74 | this.container.open(this.location); |
100 | 75 | this.container.once('closed', this.open.bind(this)); |
101 | 76 | }; |
|
125 | 100 | p.shutdown = function() |
126 | 101 | { |
127 | 102 | this.container = null; |
128 | | - this.project = null; |
129 | 103 |
|
130 | 104 | if (this.server) |
131 | 105 | { |
132 | | - this.server.close(); |
133 | | - this.server = null; |
| 106 | + this.server.destroy(function() |
| 107 | + { |
| 108 | + this.server = null; |
| 109 | + this.close(true); |
| 110 | + } |
| 111 | + .bind(this)); |
| 112 | + } |
| 113 | + else |
| 114 | + { |
| 115 | + this.close(true); |
134 | 116 | } |
135 | | - this.close(true); |
136 | 117 | }; |
137 | 118 |
|
138 | 119 | // Create the module |
|
0 commit comments