Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Detect carrier and region from `mozMobileConnection`'s `MNC` and `MCC`

View 1-moz-mobile-connection-snippet.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
// Original https://github.com/mozilla/fireplace/blob/c50b5ca51643f13ae2e8b3a003d3aa0432358bf7/hearth/media/js/user.js#L41
 
// Retrieve MCC and MNC from mozMobileConnection (requires "privileged" app type and "mobileconnection" permission)
// and translates them to carrier and region via mobilenetwork.js
 
try {
// When Fireplace is served as a privileged packaged app (and not
// served via Yulelog) our JS will have direct access to this API.
var conn = navigator.mozMobileConnection;
if (conn) {
// `MCC`: Mobile Country Code
// `MNC`: Mobile Network Code
// `lastKnownHomeNetwork`: `{MCC}-{MNC}` (SIM's origin)
// `lastKnownNetwork`: `{MCC}-{MNC}` (could be different network if roaming)
var network = (conn.lastKnownHomeNetwork || conn.lastKnownNetwork || '-').split('-');
mcc = network[0];
mnc = network[1];
console.log('lastKnownNetwork', conn.lastKnownNetwork);
console.log('lastKnownHomeNetwork', conn.lastKnownHomeNetwork);
console.log('MCC = ' + mcc + ', MNC = ' + mnc);
} else {
console.warn('Error accessing navigator.mozMobileConnection');
}
} catch (e) {
// Fail gracefully if `navigator.mozMobileConnection` gives us problems.
console.warn('Error accessing navigator.mozMobileConnection:', e);
}
 
if (mcc || mnc) {
// Look up region and carrier from MCC (Mobile Country Code)
// and MNC (Mobile Network Code).
var network = mobilenetwork.getNetwork(mcc, mnc);
region = network.region;
carrier = network.carrier;
}
View 1-moz-mobile-connection-snippet.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
// Original: https://github.com/mozilla/fireplace/blob/7c68e04623978175a86d7d9bdb174a39cfc2330c/hearth/media/js/mobilenetwork.js
 
// Translates Mobile Network Codes (MNC) and Mobile Country Codes (MCC) to carrier and region
// Mobile country codes: http://en.wikipedia.org/wiki/Mobile_country_code
 
define('mobilenetwork', [], function() {
var regions = {
// United States
310: 'us',
 
// United Kingdom
235: 'uk',
 
// Brazil
724: 'br',
 
// Spain
214: 'es',
 
// Colombia
732: 'co',
 
// Venezuela
734: 've',
 
// Poland
260: 'pl',
 
// Mexico
334: 'mx',
 
// Hungary
216: 'hu',
 
// Germany
262: 'de'
};
 
var carriers = {
// United States
310: {
26: 'deutsche_telekom',
160: 'deutsche_telekom',
170: 'deutsche_telekom',
200: 'deutsche_telekom',
210: 'deutsche_telekom',
220: 'deutsche_telekom',
230: 'deutsche_telekom',
240: 'deutsche_telekom',
250: 'deutsche_telekom',
260: 'deutsche_telekom',
270: 'deutsche_telekom',
280: 'deutsche_telekom',
290: 'deutsche_telekom',
330: 'deutsche_telekom',
490: 'deutsche_telekom',
580: 'deutsche_telekom',
660: 'deutsche_telekom',
800: 'deutsche_telekom'
},
 
// United Kingdom
235: {
2: 'telefonica',
10: 'telefonica',
11: 'telefonica',
30: 'deutsche_telekom'
},
 
// Brazil
724: {
6: 'telefonica',
10: 'telefonica',
11: 'telefonica',
23: 'telefonica'
},
 
// Spain
214: {
5: 'telefonica',
7: 'telefonica'
},
 
// Colombia
732: {
123: 'telefonica'
},
 
// Venezuela
734: {
4: 'telefonica'
},
 
// Poland
260: {
2: 'deutsche_telekom'
},
 
// Mexico
334: {
2: 'america_movil',
20: 'america_movil',
300: 'telefonica'
},
 
// Hungary
216: {
30: 'deutsche_telekom'
},
 
// Germany
262: {
1: 'deutsche_telekom',
6: 'deutsche_telekom'
},
 
// Slovakia
231: {
2: 'deutsche_telekom',
4: 'deutsche_telekom',
6: 'telefonica'
},
 
// Czech Republic
232: {
2: 'telefonica'
},
 
// Austria
232: {
8: 'telefonica'
},
 
// Guatemala
704: {
3: 'telefonica'
},
 
// El Salvador
706: {
4: 'telefonica'
},
 
// Nicaragua
710: {
3: 'telefonica'
},
 
// Costa Rica
712: {
4: 'telefonica'
},
 
// Panama
714: {
2: 'telefonica',
3: 'america_movil'
},
 
// Chile
730: {
2: 'telefonica'
},
 
// Ecuador
740: {
1: 'america_movil'
},
 
// Paraguay
744: {
4: 'telefonica',
},
 
// Peru
716: {
6: 'telefonica',
10: 'america_movil'
},
 
// Argentina
722: {
10: 'telefonica',
70: 'telefonica'
},
 
// Uruguay
748: {
7: 'telefonica'
}
};
 
function getNetwork(mcc, mnc) {
// Look up region and carrier from MCC (Mobile Country Code)
// and MNC (Mobile Network Code).
mcc = +mcc || 0;
mnc = +mnc || 0;
return {
region: regions[mcc] || null,
carrier: carriers[mcc] && carriers[mcc][mnc] || null
};
}
 
return {
getNetwork: getNetwork
};
});

Although this still probably works, the code has changed considerably: https://github.com/mozilla/fireplace/blob/master/src/media/js/mobilenetwork.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.