Skip to content

Commit be75a5b

Browse files
committed
Update cordova-plugin-iosrtc to version 1.4.1.
1 parent 0ab3f3c commit be75a5b

File tree

5 files changed

+317
-9
lines changed

5 files changed

+317
-9
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/hooks/
21
/platforms/
32
/plugins/
4-
3+
/node_modules/

config.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
<platform name="ios">
2626
<allow-intent href="itms:*" />
2727
<allow-intent href="itms-apps:*" />
28+
<hook type="after_platform_add" src="hooks/iosrtc-swift-support.js" />
2829
</platform>
2930
<plugin name="cordova-plugin-whitelist" version="1" />
30-
<plugin name="com.eface2face.iosrtc" spec="^1.2.8" />
31+
<plugin name="cordova-plugin-device" version="^1.0.1" />
32+
<plugin name="cordova-plugin-iosrtc" version="^1.4.1" />
3133
</widget>

hooks/README.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
<!--
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
-->
21+
# Cordova Hooks
22+
23+
Cordova Hooks represent special scripts which could be added by application and plugin developers or even by your own build system to customize cordova commands. Hook scripts could be defined by adding them to the special predefined folder (`/hooks`) or via configuration files (`config.xml` and `plugin.xml`) and run serially in the following order:
24+
* Application hooks from `/hooks`;
25+
* Application hooks from `config.xml`;
26+
* Plugin hooks from `plugins/.../plugin.xml`.
27+
28+
__Remember__: Make your scripts executable.
29+
30+
__Note__: `.cordova/hooks` directory is also supported for backward compatibility, but we don't recommend using it as it is deprecated.
31+
32+
## Supported hook types
33+
The following hook types are supported:
34+
35+
after_build/
36+
after_compile/
37+
after_docs/
38+
after_emulate/
39+
after_platform_add/
40+
after_platform_rm/
41+
after_platform_ls/
42+
after_plugin_add/
43+
after_plugin_ls/
44+
after_plugin_rm/
45+
after_plugin_search/
46+
after_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed
47+
after_prepare/
48+
after_run/
49+
after_serve/
50+
before_build/
51+
before_compile/
52+
before_docs/
53+
before_emulate/
54+
before_platform_add/
55+
before_platform_rm/
56+
before_platform_ls/
57+
before_plugin_add/
58+
before_plugin_ls/
59+
before_plugin_rm/
60+
before_plugin_search/
61+
before_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed
62+
before_plugin_uninstall/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being uninstalled
63+
before_prepare/
64+
before_run/
65+
before_serve/
66+
pre_package/ <-- Windows 8 and Windows Phone only.
67+
68+
## Ways to define hooks
69+
### Via '/hooks' directory
70+
To execute custom action when corresponding hook type is fired, use hook type as a name for a subfolder inside 'hooks' directory and place you script file here, for example:
71+
72+
# script file will be automatically executed after each build
73+
hooks/after_build/after_build_custom_action.js
74+
75+
76+
### Config.xml
77+
78+
Hooks can be defined in project's `config.xml` using `<hook>` elements, for example:
79+
80+
<hook type="before_build" src="scripts/appBeforeBuild.bat" />
81+
<hook type="before_build" src="scripts/appBeforeBuild.js" />
82+
<hook type="before_plugin_install" src="scripts/appBeforePluginInstall.js" />
83+
84+
<platform name="wp8">
85+
<hook type="before_build" src="scripts/wp8/appWP8BeforeBuild.bat" />
86+
<hook type="before_build" src="scripts/wp8/appWP8BeforeBuild.js" />
87+
<hook type="before_plugin_install" src="scripts/wp8/appWP8BeforePluginInstall.js" />
88+
...
89+
</platform>
90+
91+
<platform name="windows8">
92+
<hook type="before_build" src="scripts/windows8/appWin8BeforeBuild.bat" />
93+
<hook type="before_build" src="scripts/windows8/appWin8BeforeBuild.js" />
94+
<hook type="before_plugin_install" src="scripts/windows8/appWin8BeforePluginInstall.js" />
95+
...
96+
</platform>
97+
98+
### Plugin hooks (plugin.xml)
99+
100+
As a plugin developer you can define hook scripts using `<hook>` elements in a `plugin.xml` like that:
101+
102+
<hook type="before_plugin_install" src="scripts/beforeInstall.js" />
103+
<hook type="after_build" src="scripts/afterBuild.js" />
104+
105+
<platform name="wp8">
106+
<hook type="before_plugin_install" src="scripts/wp8BeforeInstall.js" />
107+
<hook type="before_build" src="scripts/wp8BeforeBuild.js" />
108+
...
109+
</platform>
110+
111+
`before_plugin_install`, `after_plugin_install`, `before_plugin_uninstall` plugin hooks will be fired exclusively for the plugin being installed/uninstalled.
112+
113+
## Script Interface
114+
115+
### Javascript
116+
117+
If you are writing hooks in Javascript you should use the following module definition:
118+
```javascript
119+
module.exports = function(context) {
120+
...
121+
}
122+
```
123+
124+
You can make your scipts async using Q:
125+
```javascript
126+
module.exports = function(context) {
127+
var Q = context.requireCordovaModule('q');
128+
var deferral = new Q.defer();
129+
130+
setTimeout(function(){
131+
console.log('hook.js>> end');
132+
deferral.resolve();
133+
}, 1000);
134+
135+
return deferral.promise;
136+
}
137+
```
138+
139+
`context` object contains hook type, executed script full path, hook options, command-line arguments passed to Cordova and top-level "cordova" object:
140+
```json
141+
{
142+
"hook": "before_plugin_install",
143+
"scriptLocation": "c:\\script\\full\\path\\appBeforePluginInstall.js",
144+
"cmdLine": "The\\exact\\command\\cordova\\run\\with arguments",
145+
"opts": {
146+
"projectRoot":"C:\\path\\to\\the\\project",
147+
"cordova": {
148+
"platforms": ["wp8"],
149+
"plugins": ["com.plugin.withhooks"],
150+
"version": "0.21.7-dev"
151+
},
152+
"plugin": {
153+
"id": "com.plugin.withhooks",
154+
"pluginInfo": {
155+
...
156+
},
157+
"platform": "wp8",
158+
"dir": "C:\\path\\to\\the\\project\\plugins\\com.plugin.withhooks"
159+
}
160+
},
161+
"cordova": {...}
162+
}
163+
164+
```
165+
`context.opts.plugin` object will only be passed to plugin hooks scripts.
166+
167+
You can also require additional Cordova modules in your script using `context.requireCordovaModule` in the following way:
168+
```javascript
169+
var Q = context.requireCordovaModule('q');
170+
```
171+
172+
__Note__: new module loader script interface is used for the `.js` files defined via `config.xml` or `plugin.xml` only.
173+
For compatibility reasons hook files specified via `/hooks` folders are run via Node child_process spawn, see 'Non-javascript' section below.
174+
175+
### Non-javascript
176+
177+
Non-javascript scripts are run via Node child_process spawn from the project's root directory and have the root directory passes as the first argument. All other options are passed to the script using environment variables:
178+
179+
* CORDOVA_VERSION - The version of the Cordova-CLI.
180+
* CORDOVA_PLATFORMS - Comma separated list of platforms that the command applies to (e.g.: android, ios).
181+
* CORDOVA_PLUGINS - Comma separated list of plugin IDs that the command applies to (e.g.: org.apache.cordova.file, org.apache.cordova.file-transfer)
182+
* CORDOVA_HOOK - Path to the hook that is being executed.
183+
* CORDOVA_CMDLINE - The exact command-line arguments passed to cordova (e.g.: cordova run ios --emulate)
184+
185+
If a script returns a non-zero exit code, then the parent cordova command will be aborted.
186+
187+
## Writing hooks
188+
189+
We highly recommend writing your hooks using Node.js so that they are
190+
cross-platform. Some good examples are shown here:
191+
192+
[http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/)
193+
194+
Also, note that even if you are working on Windows, and in case your hook scripts aren't bat files (which is recommended, if you want your scripts to work in non-Windows operating systems) Cordova CLI will expect a shebang line as the first line for it to know the interpreter it needs to use to launch the script. The shebang line should match the following example:
195+
196+
#!/usr/bin/env [name_of_interpreter_executable]

hooks/iosrtc-swift-support.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#!/usr/bin/env node
2+
3+
'use strict';
4+
5+
// This hook automates this:
6+
// https://github.com/eface2face/cordova-plugin-iosrtc/blob/master/docs/Building.md
7+
8+
var fs = require("fs"),
9+
path = require("path"),
10+
xcode = require('xcode'),
11+
12+
BUILD_VERSION = '8.2',
13+
BUILD_VERSION_XCODE = '"' + BUILD_VERSION + '"',
14+
RUNPATH_SEARCH_PATHS = '@executable_path/Frameworks',
15+
RUNPATH_SEARCH_PATHS_XCODE = '"' + RUNPATH_SEARCH_PATHS + '"',
16+
17+
BRIDGING_HEADER_END = '/Plugins/cordova-plugin-iosrtc/cordova-plugin-iosrtc-Bridging-Header.h',
18+
COMMENT_KEY = /_comment$/;
19+
20+
21+
// Helpers
22+
23+
// Returns the project name
24+
function getProjectName(protoPath) {
25+
var cordovaConfigPath = path.join(protoPath, 'config.xml'),
26+
content = fs.readFileSync(cordovaConfigPath, 'utf-8');
27+
28+
return /<name>([\s\S]*)<\/name>/mi.exec(content)[1].trim();
29+
}
30+
31+
// Drops the comments
32+
function nonComments(obj) {
33+
var keys = Object.keys(obj),
34+
newObj = {},
35+
i = 0;
36+
37+
for (i; i < keys.length; i += 1) {
38+
if (!COMMENT_KEY.test(keys[i])) {
39+
newObj[keys[i]] = obj[keys[i]];
40+
}
41+
}
42+
43+
return newObj;
44+
}
45+
46+
47+
// Starting here
48+
49+
module.exports = function (context) {
50+
var projectRoot = context.opts.projectRoot,
51+
projectName = getProjectName(projectRoot),
52+
xcconfigPath = path.join(projectRoot, '/platforms/ios/cordova/build.xcconfig'),
53+
xcodeProjectName = projectName + '.xcodeproj',
54+
xcodeProjectPath = path.join(projectRoot, 'platforms', 'ios', xcodeProjectName, 'project.pbxproj'),
55+
swiftBridgingHead = projectName + BRIDGING_HEADER_END,
56+
swiftBridgingHeadXcode = '"' + swiftBridgingHead + '"',
57+
swiftOptions = [''], // <-- begin to file appending AFTER initial newline
58+
xcodeProject;
59+
60+
// Checking if the project files are in the right place
61+
if (!fs.existsSync(xcodeProjectPath)) {
62+
console.error('ERROR: An error occured searching the project file at: "' + xcodeProjectPath + '"');
63+
64+
return;
65+
}
66+
console.log('".pbxproj" project file found: ' + xcodeProjectPath);
67+
if (!fs.existsSync(xcconfigPath)) {
68+
console.error('ERROR: An error occured searching the project file at: "' + xcconfigPath + '"');
69+
70+
return;
71+
}
72+
console.log('".xcconfig" project file found: ' + xcconfigPath);
73+
xcodeProject = xcode.project(xcodeProjectPath);
74+
75+
// Showing info about the tasks to do
76+
console.log('Fixing issues in the generated project files:');
77+
console.log('- "iOS Deployment Target" and "Deployment Target" to: ' + BUILD_VERSION_XCODE);
78+
console.log('- "Runpath Search Paths" to: ' + RUNPATH_SEARCH_PATHS_XCODE);
79+
console.log('- "Objective-C Bridging Header" to: ' + swiftBridgingHeadXcode);
80+
81+
82+
// Massaging the files
83+
84+
// "build.xcconfig"
85+
swiftOptions.push('LD_RUNPATH_SEARCH_PATHS = ' + RUNPATH_SEARCH_PATHS);
86+
swiftOptions.push('SWIFT_OBJC_BRIDGING_HEADER = ' + swiftBridgingHead);
87+
swiftOptions.push('IPHONEOS_DEPLOYMENT_TARGET = ' + BUILD_VERSION);
88+
// NOTE: Not needed
89+
// swiftOptions.push('EMBEDDED_CONTENT_CONTAINS_SWIFT = YES');
90+
fs.appendFileSync(xcconfigPath, swiftOptions.join('\n'));
91+
console.log('File correctly fixed: ' + xcconfigPath);
92+
93+
// "project.pbxproj"
94+
// Parsing it
95+
xcodeProject.parse(function (error) {
96+
var configurations, buildSettings;
97+
98+
if (error) {
99+
console.error('ERROR: An error occured during the parse of the project file');
100+
} else {
101+
configurations = nonComments(xcodeProject.pbxXCBuildConfigurationSection());
102+
// Adding or changing the parameters we need
103+
Object.keys(configurations).forEach(function (config) {
104+
buildSettings = configurations[config].buildSettings;
105+
buildSettings.LD_RUNPATH_SEARCH_PATHS = RUNPATH_SEARCH_PATHS_XCODE;
106+
buildSettings.SWIFT_OBJC_BRIDGING_HEADER = swiftBridgingHeadXcode;
107+
buildSettings.IPHONEOS_DEPLOYMENT_TARGET = BUILD_VERSION_XCODE;
108+
});
109+
110+
// Writing the file again
111+
fs.writeFileSync(xcodeProjectPath, xcodeProject.writeSync(), 'utf-8');
112+
console.log('File correctly fixed: ' + xcodeProjectPath);
113+
}
114+
});
115+
116+
};

www/js/apprtc.debug.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,7 @@ AppController.prototype.waitForRemoteVideo_ = function() {
402402
trace("Remote video started; currentTime: " + this.remoteVideo_.currentTime);
403403
this.transitionToActive_();
404404
} else {
405-
// NOTE: video.readState not implemented in the iosrtc plugin.
406-
// this.remoteVideo_.oncanplay = this.waitForRemoteVideo_.bind(this);
407-
var self = this;
408-
this.remoteVideo_.oncanplay = function () {
409-
self.transitionToActive_();
410-
};
405+
this.remoteVideo_.oncanplay = this.waitForRemoteVideo_.bind(this);
411406
}
412407
};
413408
AppController.prototype.onRemoteStreamAdded_ = function(stream) {

0 commit comments

Comments
 (0)