Grab the jquery signalr and open it with your text editor tools.
Copy and paste the following code at the beginning of file:
var jQuery = require("./jquery-3.3.1"); // Change the jquery version to your own version
window.jQuery = jQuery;
Paste above of this line:
(function ($, window, undefined)
Copy and paste the following code at the end of file:
module.exports = window.jQuery;
Remember everytime first launch of cocos creator, click âDeveloperâ > âCompile User Scriptsâ (F7).
You will get errors if you doesnât compile your scripts.
Usage: (Sample in Typescript)
let SignalR = require("../jquery.signalR-2.2.2");
let connection = SignalR.hubConnection("http://localhost");
let proxy = connection.createHubProxy('chatHub');
// receives broadcast messages from a hub function, called "broadcastMessage"
proxy.on('notify', this.notify.bind(this));
// atempt connection, and handle errors
connection.start({
transport: [
'webSockets',
//'foreverFrame',
//'serverSentEvents',
'longPolling'
],
jsonp: true,
})
.done(function(){
console.log('Now connected, connection ID=' + connection.id);
})
.fail(function(reason){
console.log('Could not connect: ' + reason);
});
I spent few weeks to figure out how to use signalr in cocos creator, hope this could help others.
It run on IOS, however it skip negotiation request. If keep negotiation request, have a error: JS: [ERROR]: Error: Failed to complete negotiation with the server: TypeError: undefined is not an object (evaluating âe.methodâ)signalR-ccc.zip (206.5 KB)